Merge
This commit is contained in:
commit
0a521a9457
@ -44,7 +44,6 @@ import javax.management.MBeanException;
|
|||||||
import javax.management.MBeanInfo;
|
import javax.management.MBeanInfo;
|
||||||
import javax.management.MBeanRegistrationException;
|
import javax.management.MBeanRegistrationException;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.NotCompliantMBeanException;
|
import javax.management.NotCompliantMBeanException;
|
||||||
import javax.management.NotificationFilter;
|
import javax.management.NotificationFilter;
|
||||||
import javax.management.NotificationListener;
|
import javax.management.NotificationListener;
|
||||||
@ -205,8 +204,7 @@ public abstract class DispatchInterceptor
|
|||||||
|
|
||||||
// Returns the ObjectName of the JMXNamespace (or JMXDomain) for that
|
// Returns the ObjectName of the JMXNamespace (or JMXDomain) for that
|
||||||
// key (a namespace or a domain name).
|
// key (a namespace or a domain name).
|
||||||
abstract ObjectName getHandlerNameFor(String key)
|
abstract ObjectName getHandlerNameFor(String key);
|
||||||
throws MalformedObjectNameException;
|
|
||||||
|
|
||||||
// Creates an interceptor for the given key, name, JMXNamespace (or
|
// Creates an interceptor for the given key, name, JMXNamespace (or
|
||||||
// JMXDomain). Note: this will be either a NamespaceInterceptor
|
// JMXDomain). Note: this will be either a NamespaceInterceptor
|
||||||
@ -263,14 +261,10 @@ public abstract class DispatchInterceptor
|
|||||||
void validateHandlerNameFor(String key, ObjectName name) {
|
void validateHandlerNameFor(String key, ObjectName name) {
|
||||||
if (key == null || key.equals(""))
|
if (key == null || key.equals(""))
|
||||||
throw new IllegalArgumentException("invalid key for "+name+": "+key);
|
throw new IllegalArgumentException("invalid key for "+name+": "+key);
|
||||||
try {
|
final ObjectName handlerName = getHandlerNameFor(key);
|
||||||
final ObjectName handlerName = getHandlerNameFor(key);
|
if (!name.equals(handlerName))
|
||||||
if (!name.equals(handlerName))
|
throw new IllegalArgumentException("bad handler name: "+name+
|
||||||
throw new IllegalArgumentException("bad handler name: "+name+
|
". Should be: "+handlerName);
|
||||||
". Should be: "+handlerName);
|
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
throw new IllegalArgumentException(name.toString(),x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by the DefaultMBeanServerInterceptor when an instance
|
// Called by the DefaultMBeanServerInterceptor when an instance
|
||||||
|
@ -38,7 +38,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerDelegate;
|
import javax.management.MBeanServerDelegate;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.QueryExp;
|
import javax.management.QueryExp;
|
||||||
import javax.management.namespace.JMXDomain;
|
import javax.management.namespace.JMXDomain;
|
||||||
@ -248,21 +247,17 @@ class DomainDispatchInterceptor
|
|||||||
if (pattern == null) return true;
|
if (pattern == null) return true;
|
||||||
if (pattern.isDomainPattern()) return true;
|
if (pattern.isDomainPattern()) return true;
|
||||||
|
|
||||||
try {
|
// case b) above.
|
||||||
// case b) above.
|
//
|
||||||
//
|
// This is a bit of a hack. If there's any chance that a JMXDomain
|
||||||
// This is a bit of a hack. If there's any chance that a JMXDomain
|
// MBean name is selected by the given pattern then we must include
|
||||||
// MBean name is selected by the given pattern then we must include
|
// the local namespace in our search.
|
||||||
// the local namespace in our search.
|
//
|
||||||
//
|
// Returning true will have this effect. see 2. above.
|
||||||
// Returning true will have this effect. see 2. above.
|
//
|
||||||
//
|
if (pattern.apply(ALL_DOMAINS.withDomain(pattern.getDomain())))
|
||||||
if (pattern.apply(ALL_DOMAINS.withDomain(pattern.getDomain())))
|
return true;
|
||||||
return true;
|
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
// should not happen
|
|
||||||
throw new IllegalArgumentException(String.valueOf(pattern), x);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,8 +286,7 @@ class DomainDispatchInterceptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final ObjectName getHandlerNameFor(String key)
|
final ObjectName getHandlerNameFor(String key) {
|
||||||
throws MalformedObjectNameException {
|
|
||||||
return JMXDomain.getDomainObjectName(key);
|
return JMXDomain.getDomainObjectName(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerDelegate;
|
import javax.management.MBeanServerDelegate;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
import javax.management.RuntimeOperationsException;
|
||||||
import javax.management.namespace.JMXDomain;
|
import javax.management.namespace.JMXDomain;
|
||||||
import javax.management.namespace.JMXNamespace;
|
import javax.management.namespace.JMXNamespace;
|
||||||
import static javax.management.namespace.JMXNamespaces.NAMESPACE_SEPARATOR;
|
import static javax.management.namespace.JMXNamespaces.NAMESPACE_SEPARATOR;
|
||||||
@ -60,6 +60,7 @@ public class NamespaceDispatchInterceptor
|
|||||||
|
|
||||||
private static final int NAMESPACE_SEPARATOR_LENGTH =
|
private static final int NAMESPACE_SEPARATOR_LENGTH =
|
||||||
NAMESPACE_SEPARATOR.length();
|
NAMESPACE_SEPARATOR.length();
|
||||||
|
private static final ObjectName X3 = ObjectName.valueOf("x:x=x");
|
||||||
|
|
||||||
private final DomainDispatchInterceptor nextInterceptor;
|
private final DomainDispatchInterceptor nextInterceptor;
|
||||||
private final String serverName;
|
private final String serverName;
|
||||||
@ -89,27 +90,38 @@ public class NamespaceDispatchInterceptor
|
|||||||
serverName = Util.getMBeanServerSecurityName(delegate);
|
serverName = Util.getMBeanServerSecurityName(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Should move that to JMXNamespace? or to ObjectName?
|
|
||||||
/**
|
/**
|
||||||
* Get first name space in ObjectName path. Ignore leading namespace
|
* Get first name space in ObjectName path. Ignore leading namespace
|
||||||
* separators.
|
* separators. Includes the trailing //.
|
||||||
|
*
|
||||||
|
* Examples:
|
||||||
|
* <pre>
|
||||||
|
* For ObjectName: Returns:
|
||||||
|
* foo//bar//baz:x=x -> "foo//"
|
||||||
|
* foo//:type=JMXNamespace -> "foo//"
|
||||||
|
* foo//:x=x -> "foo//"
|
||||||
|
* foo////:x=x -> "foo//"
|
||||||
|
* //foo//bar//baz:x=x -> "//"
|
||||||
|
* ////foo//bar//baz:x=x -> "//"
|
||||||
|
* //:x=x -> "//"
|
||||||
|
* foo:x=x -> ""
|
||||||
|
* (null) -> ""
|
||||||
|
* :x=x -> ""
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
**/
|
**/
|
||||||
static String getFirstNamespace(ObjectName name) {
|
static String getFirstNamespaceWithSlash(ObjectName name) {
|
||||||
if (name == null) return "";
|
if (name == null) return "";
|
||||||
final String domain = name.getDomain();
|
final String domain = name.getDomain();
|
||||||
if (domain.equals("")) return "";
|
if (domain.equals("")) return "";
|
||||||
|
|
||||||
// skip leading separators
|
|
||||||
int first = 0;
|
|
||||||
while (domain.startsWith(NAMESPACE_SEPARATOR,first))
|
|
||||||
first += NAMESPACE_SEPARATOR_LENGTH;
|
|
||||||
|
|
||||||
// go to next separator
|
// go to next separator
|
||||||
final int end = domain.indexOf(NAMESPACE_SEPARATOR,first);
|
final int end = domain.indexOf(NAMESPACE_SEPARATOR);
|
||||||
if (end == -1) return ""; // no namespace
|
if (end == -1) return ""; // no namespace
|
||||||
|
|
||||||
// This is the first element in the namespace path.
|
// This is the first element in the namespace path.
|
||||||
final String namespace = domain.substring(first,end);
|
final String namespace =
|
||||||
|
domain.substring(0,end+NAMESPACE_SEPARATOR_LENGTH);
|
||||||
|
|
||||||
return namespace;
|
return namespace;
|
||||||
}
|
}
|
||||||
@ -130,27 +142,49 @@ public class NamespaceDispatchInterceptor
|
|||||||
resource.getClass().getName());
|
resource.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isLocalHandlerNameFor(String namespace,
|
// Removes the trailing //. namespaceWithSlash should be either
|
||||||
ObjectName handlerName) {
|
// "" or a namespace path ending with //.
|
||||||
return handlerName.getDomain().equals(namespace+NAMESPACE_SEPARATOR) &&
|
//
|
||||||
JMXNamespace.TYPE_ASSIGNMENT.equals(
|
private final String getKeyFor(String namespaceWithSlash) {
|
||||||
handlerName.getKeyPropertyListString());
|
final int end = namespaceWithSlash.length() -
|
||||||
|
NAMESPACE_SEPARATOR_LENGTH;
|
||||||
|
if (end <= 0) return "";
|
||||||
|
final String key = namespaceWithSlash.substring(0,end);
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final MBeanServer getInterceptorOrNullFor(ObjectName name) {
|
final MBeanServer getInterceptorOrNullFor(ObjectName name) {
|
||||||
final String namespace = getFirstNamespace(name);
|
final String namespace = getFirstNamespaceWithSlash(name);
|
||||||
if (namespace.equals("") || isLocalHandlerNameFor(namespace,name) ||
|
|
||||||
name.getDomain().equals(namespace+NAMESPACE_SEPARATOR)) {
|
// Leading separators should trigger instance not found exception.
|
||||||
|
// returning null here has this effect.
|
||||||
|
//
|
||||||
|
if (namespace.equals(NAMESPACE_SEPARATOR)) {
|
||||||
|
LOG.finer("ObjectName starts with: "+namespace);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// namespace="" means that there was no namespace path in the
|
||||||
|
// ObjectName. => delegate to the next interceptor (local MBS)
|
||||||
|
// name.getDomain()=namespace means that we have an ObjectName of
|
||||||
|
// the form blah//:x=x. This is either a JMXNamespace or a non
|
||||||
|
// existent MBean. => delegate to the next interceptor (local MBS)
|
||||||
|
if (namespace.equals("") || name.getDomain().equals(namespace)) {
|
||||||
LOG.finer("dispatching to local name space");
|
LOG.finer("dispatching to local name space");
|
||||||
return nextInterceptor;
|
return nextInterceptor;
|
||||||
}
|
}
|
||||||
final NamespaceInterceptor ns = getInterceptor(namespace);
|
|
||||||
|
// There was a namespace path in the ObjectName. Returns the
|
||||||
|
// interceptor that handles it, or null if there is no such
|
||||||
|
// interceptor.
|
||||||
|
final String key = getKeyFor(namespace);
|
||||||
|
final NamespaceInterceptor ns = getInterceptor(key);
|
||||||
if (LOG.isLoggable(Level.FINER)) {
|
if (LOG.isLoggable(Level.FINER)) {
|
||||||
if (ns != null) {
|
if (ns != null) {
|
||||||
LOG.finer("dispatching to name space: " + namespace);
|
LOG.finer("dispatching to name space: " + key);
|
||||||
} else {
|
} else {
|
||||||
LOG.finer("no handler for: " + namespace);
|
LOG.finer("no handler for: " + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ns;
|
return ns;
|
||||||
@ -158,18 +192,44 @@ public class NamespaceDispatchInterceptor
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
final QueryInterceptor getInterceptorForQuery(ObjectName pattern) {
|
final QueryInterceptor getInterceptorForQuery(ObjectName pattern) {
|
||||||
final String namespace = getFirstNamespace(pattern);
|
final String namespace = getFirstNamespaceWithSlash(pattern);
|
||||||
if (namespace.equals("") || isLocalHandlerNameFor(namespace,pattern) ||
|
|
||||||
pattern.getDomain().equals(namespace+NAMESPACE_SEPARATOR)) {
|
// Leading separators should trigger instance not found exception.
|
||||||
|
// returning null here has this effect.
|
||||||
|
//
|
||||||
|
if (namespace.equals(NAMESPACE_SEPARATOR)) {
|
||||||
|
LOG.finer("ObjectName starts with: "+namespace);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// namespace="" means that there was no namespace path in the
|
||||||
|
// ObjectName. => delegate to the next interceptor (local MBS)
|
||||||
|
// name.getDomain()=namespace means that we have an ObjectName of
|
||||||
|
// the form blah//:x=x. This is either a JMXNamespace or a non
|
||||||
|
// existent MBean. => delegate to the next interceptor (local MBS)
|
||||||
|
if (namespace.equals("") || pattern.getDomain().equals(namespace)) {
|
||||||
LOG.finer("dispatching to local name space");
|
LOG.finer("dispatching to local name space");
|
||||||
return new QueryInterceptor(nextInterceptor);
|
return new QueryInterceptor(nextInterceptor);
|
||||||
}
|
}
|
||||||
final NamespaceInterceptor ns = getInterceptor(namespace);
|
|
||||||
|
// This is a 'hack' to check whether the first namespace is a pattern.
|
||||||
|
// We wan to throw RTOE wrapping IAE in that case
|
||||||
|
if (X3.withDomain(namespace).isDomainPattern()) {
|
||||||
|
throw new RuntimeOperationsException(
|
||||||
|
new IllegalArgumentException("Pattern not allowed in namespace path"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// There was a namespace path in the ObjectName. Returns the
|
||||||
|
// interceptor that handles it, or null if there is no such
|
||||||
|
// interceptor.
|
||||||
|
//
|
||||||
|
final String key = getKeyFor(namespace);
|
||||||
|
final NamespaceInterceptor ns = getInterceptor(key);
|
||||||
if (LOG.isLoggable(Level.FINER)) {
|
if (LOG.isLoggable(Level.FINER)) {
|
||||||
if (ns != null) {
|
if (ns != null) {
|
||||||
LOG.finer("dispatching to name space: " + namespace);
|
LOG.finer("dispatching to name space: " + key);
|
||||||
} else {
|
} else {
|
||||||
LOG.finer("no handler for: " + namespace);
|
LOG.finer("no handler for: " + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ns == null) return null;
|
if (ns == null) return null;
|
||||||
@ -177,15 +237,16 @@ public class NamespaceDispatchInterceptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final ObjectName getHandlerNameFor(String key)
|
final ObjectName getHandlerNameFor(String key) {
|
||||||
throws MalformedObjectNameException {
|
return ObjectName.valueOf(key+NAMESPACE_SEPARATOR,
|
||||||
return ObjectName.getInstance(key+NAMESPACE_SEPARATOR,
|
|
||||||
"type", JMXNamespace.TYPE);
|
"type", JMXNamespace.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final public String getHandlerKey(ObjectName name) {
|
final public String getHandlerKey(ObjectName name) {
|
||||||
return getFirstNamespace(name);
|
final String namespace = getFirstNamespaceWithSlash(name);
|
||||||
|
// namespace is either "" or a namespace ending with //
|
||||||
|
return getKeyFor(namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,7 +37,6 @@ import javax.management.InstanceAlreadyExistsException;
|
|||||||
import javax.management.JMX;
|
import javax.management.JMX;
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
import javax.management.MBeanServerInvocationHandler;
|
import javax.management.MBeanServerInvocationHandler;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.openmbean.OpenDataException;
|
import javax.management.openmbean.OpenDataException;
|
||||||
|
|
||||||
@ -225,7 +224,7 @@ public abstract class MXBeanLookup {
|
|||||||
String domain = prefix + name.getDomain();
|
String domain = prefix + name.getDomain();
|
||||||
try {
|
try {
|
||||||
name = name.withDomain(domain);
|
name = name.withDomain(domain);
|
||||||
} catch (MalformedObjectNameException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw EnvHelp.initCause(
|
throw EnvHelp.initCause(
|
||||||
new InvalidObjectException(e.getMessage()), e);
|
new InvalidObjectException(e.getMessage()), e);
|
||||||
}
|
}
|
||||||
@ -239,12 +238,14 @@ public abstract class MXBeanLookup {
|
|||||||
String domain = name.getDomain();
|
String domain = name.getDomain();
|
||||||
if (!domain.startsWith(prefix)) {
|
if (!domain.startsWith(prefix)) {
|
||||||
throw new OpenDataException(
|
throw new OpenDataException(
|
||||||
"Proxy's name does not start with " + prefix + ": " + name);
|
"Proxy's name does not start with " +
|
||||||
|
prefix + ": " + name);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
name = name.withDomain(domain.substring(prefix.length()));
|
name = name.withDomain(domain.substring(prefix.length()));
|
||||||
} catch (MalformedObjectNameException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw EnvHelp.initCause(new OpenDataException(e.getMessage()), e);
|
throw EnvHelp.initCause(
|
||||||
|
new OpenDataException(e.getMessage()), e);
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ import java.util.logging.Level;
|
|||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerDelegate;
|
import javax.management.MBeanServerDelegate;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectInstance;
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.loading.ClassLoaderRepository;
|
import javax.management.loading.ClassLoaderRepository;
|
||||||
|
@ -42,7 +42,6 @@ import javax.management.ListenerNotFoundException;
|
|||||||
import javax.management.MBeanPermission;
|
import javax.management.MBeanPermission;
|
||||||
import javax.management.MBeanServerDelegate;
|
import javax.management.MBeanServerDelegate;
|
||||||
import javax.management.MBeanServerNotification;
|
import javax.management.MBeanServerNotification;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.Notification;
|
import javax.management.Notification;
|
||||||
import javax.management.NotificationFilter;
|
import javax.management.NotificationFilter;
|
||||||
import javax.management.NotificationListener;
|
import javax.management.NotificationListener;
|
||||||
@ -268,13 +267,9 @@ public class DomainInterceptor extends HandlerInterceptor<JMXDomain> {
|
|||||||
// When we reach here, it has been verified that 'name' matches our domain
|
// When we reach here, it has been verified that 'name' matches our domain
|
||||||
// name (done by DomainDispatchInterceptor)
|
// name (done by DomainDispatchInterceptor)
|
||||||
private ObjectName getPatternFor(final ObjectName name) {
|
private ObjectName getPatternFor(final ObjectName name) {
|
||||||
try {
|
if (name == null) return ALL;
|
||||||
if (name == null) return ALL;
|
if (name.getDomain().equals(domainName)) return name;
|
||||||
if (name.getDomain().equals(domainName)) return name;
|
return name.withDomain(domainName);
|
||||||
return name.withDomain(domainName);
|
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
throw new IllegalArgumentException(String.valueOf(name),x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,15 +24,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.sun.jmx.namespace;
|
package com.sun.jmx.namespace;
|
||||||
|
|
||||||
import com.sun.jmx.defaults.JmxProperties;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.management.Attribute;
|
import javax.management.Attribute;
|
||||||
import javax.management.AttributeList;
|
import javax.management.AttributeList;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.namespace.JMXNamespace;
|
import javax.management.namespace.JMXNamespace;
|
||||||
import javax.management.namespace.JMXNamespacePermission;
|
import javax.management.namespace.JMXNamespacePermission;
|
||||||
@ -114,14 +111,12 @@ public class NamespaceInterceptor extends HandlerInterceptor<JMXNamespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ObjectName toSource(ObjectName targetName)
|
protected ObjectName toSource(ObjectName targetName) {
|
||||||
throws MalformedObjectNameException {
|
|
||||||
return proc.toSourceContext(targetName, true);
|
return proc.toSourceContext(targetName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ObjectName toTarget(ObjectName sourceName)
|
protected ObjectName toTarget(ObjectName sourceName) {
|
||||||
throws MalformedObjectNameException {
|
|
||||||
return proc.toTargetContext(sourceName, false);
|
return proc.toTargetContext(sourceName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ package com.sun.jmx.namespace;
|
|||||||
|
|
||||||
import static javax.management.namespace.JMXNamespaces.NAMESPACE_SEPARATOR;
|
import static javax.management.namespace.JMXNamespaces.NAMESPACE_SEPARATOR;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectInstance;
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
@ -83,11 +82,7 @@ public class ObjectNameRouter {
|
|||||||
}
|
}
|
||||||
final String targetDomain =
|
final String targetDomain =
|
||||||
(tlen>0?targetPrefix+NAMESPACE_SEPARATOR+srcDomain:srcDomain);
|
(tlen>0?targetPrefix+NAMESPACE_SEPARATOR+srcDomain:srcDomain);
|
||||||
try {
|
return sourceName.withDomain(targetDomain);
|
||||||
return sourceName.withDomain(targetDomain);
|
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
throw new IllegalArgumentException(String.valueOf(sourceName),x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ObjectName toSourceContext(ObjectName targetName,
|
public final ObjectName toSourceContext(ObjectName targetName,
|
||||||
@ -113,11 +108,7 @@ public class ObjectNameRouter {
|
|||||||
final String sourceDomain =
|
final String sourceDomain =
|
||||||
(slen>0?sourcePrefix+NAMESPACE_SEPARATOR+targetDomain:
|
(slen>0?sourcePrefix+NAMESPACE_SEPARATOR+targetDomain:
|
||||||
targetDomain);
|
targetDomain);
|
||||||
try {
|
return targetName.withDomain(sourceDomain);
|
||||||
return targetName.withDomain(sourceDomain);
|
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
throw new IllegalArgumentException(String.valueOf(targetName),x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ObjectInstance toTargetContext(ObjectInstance sourceMoi,
|
public final ObjectInstance toTargetContext(ObjectInstance sourceMoi,
|
||||||
|
@ -46,7 +46,6 @@ import javax.management.MBeanException;
|
|||||||
import javax.management.MBeanInfo;
|
import javax.management.MBeanInfo;
|
||||||
import javax.management.MBeanRegistrationException;
|
import javax.management.MBeanRegistrationException;
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.NotCompliantMBeanException;
|
import javax.management.NotCompliantMBeanException;
|
||||||
import javax.management.NotificationFilter;
|
import javax.management.NotificationFilter;
|
||||||
import javax.management.NotificationListener;
|
import javax.management.NotificationListener;
|
||||||
@ -100,18 +99,17 @@ public abstract class RoutingMBeanServerConnection<T extends MBeanServerConnecti
|
|||||||
* the target name is "foo//X".
|
* the target name is "foo//X".
|
||||||
* In the case of cascading - such as in NamespaceInterceptor, this method
|
* In the case of cascading - such as in NamespaceInterceptor, this method
|
||||||
* will convert "foo//X" (the targetName) into "X", the source name.
|
* will convert "foo//X" (the targetName) into "X", the source name.
|
||||||
|
* @throws IllegalArgumentException if the name cannot be converted.
|
||||||
**/
|
**/
|
||||||
protected abstract ObjectName toSource(ObjectName targetName)
|
protected abstract ObjectName toSource(ObjectName targetName);
|
||||||
throws MalformedObjectNameException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a source ObjectName to a target ObjectName.
|
* Converts a source ObjectName to a target ObjectName.
|
||||||
* (see description of toSource above for explanations)
|
* (see description of toSource above for explanations)
|
||||||
* In the case of cascading - such as in NamespaceInterceptor, this method
|
* In the case of cascading - such as in NamespaceInterceptor, this method
|
||||||
* will convert "X" (the sourceName) into "foo//X", the target name.
|
* will convert "X" (the sourceName) into "foo//X", the target name.
|
||||||
|
* @throws IllegalArgumentException if the name cannot be converted.
|
||||||
**/
|
**/
|
||||||
protected abstract ObjectName toTarget(ObjectName sourceName)
|
protected abstract ObjectName toTarget(ObjectName sourceName);
|
||||||
throws MalformedObjectNameException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be overridden by subclasses to check the validity of a new
|
* Can be overridden by subclasses to check the validity of a new
|
||||||
@ -128,17 +126,12 @@ public abstract class RoutingMBeanServerConnection<T extends MBeanServerConnecti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls toSource(), Wraps MalformedObjectNameException.
|
// Calls toSource(), Wraps IllegalArgumentException.
|
||||||
ObjectName toSourceOrRuntime(ObjectName targetName)
|
ObjectName toSourceOrRuntime(ObjectName targetName) {
|
||||||
throws RuntimeOperationsException {
|
|
||||||
try {
|
try {
|
||||||
return toSource(targetName);
|
return toSource(targetName);
|
||||||
} catch (MalformedObjectNameException x) {
|
} catch (RuntimeException x) {
|
||||||
final IllegalArgumentException x2 =
|
throw makeCompliantRuntimeException(x);
|
||||||
new IllegalArgumentException(String.valueOf(targetName),x);
|
|
||||||
final RuntimeOperationsException x3 =
|
|
||||||
new RuntimeOperationsException(x2);
|
|
||||||
throw x3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,12 +369,8 @@ public abstract class RoutingMBeanServerConnection<T extends MBeanServerConnecti
|
|||||||
try {
|
try {
|
||||||
final ObjectName targetName = toTarget(sourceName);
|
final ObjectName targetName = toTarget(sourceName);
|
||||||
return new ObjectInstance(targetName,source.getClassName());
|
return new ObjectInstance(targetName,source.getClassName());
|
||||||
} catch (MalformedObjectNameException x) {
|
} catch (RuntimeException x) {
|
||||||
final IllegalArgumentException x2 =
|
throw makeCompliantRuntimeException(x);
|
||||||
new IllegalArgumentException(String.valueOf(sourceName),x);
|
|
||||||
final RuntimeOperationsException x3 =
|
|
||||||
new RuntimeOperationsException(x2);
|
|
||||||
throw x3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,8 +199,7 @@ public abstract class RoutingProxy<T extends MBeanServerConnection>
|
|||||||
public T source() { return source; }
|
public T source() { return source; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectName toSource(ObjectName targetName)
|
public ObjectName toSource(ObjectName targetName) {
|
||||||
throws MalformedObjectNameException {
|
|
||||||
if (targetName == null) return null;
|
if (targetName == null) return null;
|
||||||
if (targetName.getDomain().equals("") && targetNs.equals("")) {
|
if (targetName.getDomain().equals("") && targetNs.equals("")) {
|
||||||
try {
|
try {
|
||||||
@ -229,8 +228,7 @@ public abstract class RoutingProxy<T extends MBeanServerConnection>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectName toTarget(ObjectName sourceName)
|
public ObjectName toTarget(ObjectName sourceName) {
|
||||||
throws MalformedObjectNameException {
|
|
||||||
if (sourceName == null) return null;
|
if (sourceName == null) return null;
|
||||||
return router.toTargetContext(sourceName,false);
|
return router.toTargetContext(sourceName,false);
|
||||||
}
|
}
|
||||||
|
@ -424,10 +424,16 @@ public interface MBeanServer extends MBeanServerConnection {
|
|||||||
public ObjectInstance getObjectInstance(ObjectName name)
|
public ObjectInstance getObjectInstance(ObjectName name)
|
||||||
throws InstanceNotFoundException;
|
throws InstanceNotFoundException;
|
||||||
|
|
||||||
// doc comment inherited from MBeanServerConnection
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* @throws RuntimeOperationsException {@inheritDoc}
|
||||||
|
*/
|
||||||
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query);
|
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query);
|
||||||
|
|
||||||
// doc comment inherited from MBeanServerConnection
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* @throws RuntimeOperationsException {@inheritDoc}
|
||||||
|
*/
|
||||||
public Set<ObjectName> queryNames(ObjectName name, QueryExp query);
|
public Set<ObjectName> queryNames(ObjectName name, QueryExp query);
|
||||||
|
|
||||||
// doc comment inherited from MBeanServerConnection
|
// doc comment inherited from MBeanServerConnection
|
||||||
|
@ -436,7 +436,17 @@ public interface MBeanServerConnection extends NotificationManager {
|
|||||||
* specified, all the MBeans registered will be retrieved.
|
* specified, all the MBeans registered will be retrieved.
|
||||||
* @param query The query expression to be applied for selecting
|
* @param query The query expression to be applied for selecting
|
||||||
* MBeans. If null no query expression will be applied for
|
* MBeans. If null no query expression will be applied for
|
||||||
* selecting MBeans.
|
* selecting MBeans. ObjectName patterns that may be contained in the
|
||||||
|
* query expression will be
|
||||||
|
* <a href="namespace/package-summary.html#NamespaceAndQueries"><!--
|
||||||
|
* -->evaluated</a> in the context of the
|
||||||
|
* {@link javax.management.namespace namespace}
|
||||||
|
* in which the MBeans selected by {@code name} are registered.
|
||||||
|
* Thus, in the {@code query} parameter, no ObjectName pattern containing a
|
||||||
|
* namespace path can match any of the MBean names selected by {@code name}.
|
||||||
|
* See the
|
||||||
|
* <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!--
|
||||||
|
* -->namespaces documentation</a> for more details.
|
||||||
*
|
*
|
||||||
* @return A set containing the <CODE>ObjectInstance</CODE>
|
* @return A set containing the <CODE>ObjectInstance</CODE>
|
||||||
* objects for the selected MBeans. If no MBean satisfies the
|
* objects for the selected MBeans. If no MBean satisfies the
|
||||||
@ -444,6 +454,11 @@ public interface MBeanServerConnection extends NotificationManager {
|
|||||||
*
|
*
|
||||||
* @exception IOException A communication problem occurred when
|
* @exception IOException A communication problem occurred when
|
||||||
* talking to the MBean server.
|
* talking to the MBean server.
|
||||||
|
* @exception RuntimeOperationsException Wraps a
|
||||||
|
* <CODE>java.lang.IllegalArgumentException</CODE>: The <em>name</em>
|
||||||
|
* parameter contains an invalid pattern. See the
|
||||||
|
* <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!--
|
||||||
|
* -->namespaces documentation</a> for more details.
|
||||||
*/
|
*/
|
||||||
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query)
|
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
@ -464,7 +479,17 @@ public interface MBeanServerConnection extends NotificationManager {
|
|||||||
* specified, the name of all registered MBeans will be retrieved.
|
* specified, the name of all registered MBeans will be retrieved.
|
||||||
* @param query The query expression to be applied for selecting
|
* @param query The query expression to be applied for selecting
|
||||||
* MBeans. If null no query expression will be applied for
|
* MBeans. If null no query expression will be applied for
|
||||||
* selecting MBeans.
|
* selecting MBeans. ObjectName patterns that may be contained in the
|
||||||
|
* query expression will be
|
||||||
|
* <a href="namespace/package-summary.html#NamespaceAndQueries"><!--
|
||||||
|
* -->evaluated</a> in the context of the
|
||||||
|
* {@link javax.management.namespace namespace}
|
||||||
|
* in which the MBeans slected by {@code name} are registered.
|
||||||
|
* Thus, in the {@code query} parameter, no ObjectName pattern containing a
|
||||||
|
* namespace path can match any of the MBean names selected by {@code name}.
|
||||||
|
* See the
|
||||||
|
* <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!--
|
||||||
|
* -->namespaces documentation</a> for more details.
|
||||||
*
|
*
|
||||||
* @return A set containing the ObjectNames for the MBeans
|
* @return A set containing the ObjectNames for the MBeans
|
||||||
* selected. If no MBean satisfies the query, an empty list is
|
* selected. If no MBean satisfies the query, an empty list is
|
||||||
@ -472,6 +497,11 @@ public interface MBeanServerConnection extends NotificationManager {
|
|||||||
*
|
*
|
||||||
* @exception IOException A communication problem occurred when
|
* @exception IOException A communication problem occurred when
|
||||||
* talking to the MBean server.
|
* talking to the MBean server.
|
||||||
|
* @exception RuntimeOperationsException Wraps a
|
||||||
|
* <CODE>java.lang.IllegalArgumentException</CODE>: The <em>name</em>
|
||||||
|
* parameter contains an invalid pattern. See the
|
||||||
|
* <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!--
|
||||||
|
* -->namespaces documentation</a> for more details.
|
||||||
*/
|
*/
|
||||||
public Set<ObjectName> queryNames(ObjectName name, QueryExp query)
|
public Set<ObjectName> queryNames(ObjectName name, QueryExp query)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
@ -56,14 +56,38 @@ import java.util.Map;
|
|||||||
* properties.</p>
|
* properties.</p>
|
||||||
*
|
*
|
||||||
* <p>The <em>domain</em> is a string of characters not including
|
* <p>The <em>domain</em> is a string of characters not including
|
||||||
* the character colon (<code>:</code>). It is recommended that the domain
|
* the character colon (<code>:</code>).</p>
|
||||||
* should not contain the string "{@code //}", which is reserved for future use.
|
* <p>Starting with the version 2.0 of the JMX specification, the
|
||||||
|
* <em>domain</em> can also start with a {@linkplain
|
||||||
|
* javax.management.namespace#NamespacePrefix namespace prefix} identifying
|
||||||
|
* the {@linkplain javax.management.namespace namespace} in which the
|
||||||
|
* MBean is registered. A namespace prefix is a path string where
|
||||||
|
* elements are separated by a double slash (<code>//</code>).
|
||||||
|
* It identifies the {@linkplain javax.management.namespace namespace} in
|
||||||
|
* which the MBean so named is registered.</p>
|
||||||
|
*
|
||||||
|
* <p>For instance the ObjectName <em>bar//baz:k=v</em> identifiies an MBean
|
||||||
|
* named <em>baz:k=v</em> in the namespace <em>bar</em>. Similarly the
|
||||||
|
* ObjectName <em>foo//bar//baz:k=v</em> identifiies an MBean named
|
||||||
|
* <em>baz:k=v</em> in the namespace <em>foo//bar</em>. See the {@linkplain
|
||||||
|
* javax.management.namespace namespace} documentation for more details.</p>
|
||||||
*
|
*
|
||||||
* <p>If the domain includes at least one occurrence of the wildcard
|
* <p>If the domain includes at least one occurrence of the wildcard
|
||||||
* characters asterisk (<code>*</code>) or question mark
|
* characters asterisk (<code>*</code>) or question mark
|
||||||
* (<code>?</code>), then the object name is a pattern. The asterisk
|
* (<code>?</code>), then the object name is a pattern. The asterisk
|
||||||
* matches any sequence of zero or more characters, while the question
|
* matches any sequence of zero or more characters, while the question
|
||||||
* mark matches any single character.</p>
|
* mark matches any single character. <br>
|
||||||
|
* A namespace separator <code>//</code> does not match wildcard
|
||||||
|
* characters unless it is at the very end of the domain string.
|
||||||
|
* So <em>foo*bar*:*</em> does not match <em>foo//bar:k=v</em> but it
|
||||||
|
* does match <em>fooxbar//:k=v</em>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>When included in a namespace path the special path element
|
||||||
|
* <code>**</code> matches any number of sub namespaces
|
||||||
|
* recursively, but only if used as a complete namespace path element,
|
||||||
|
* as in <code>**//b//c//D:k=v</code> or <code>a//**//c//D:k=v</code>
|
||||||
|
* - see <a href="#metawildcard">below</a>.
|
||||||
*
|
*
|
||||||
* <p>If the domain is empty, it will be replaced in certain contexts
|
* <p>If the domain is empty, it will be replaced in certain contexts
|
||||||
* by the <em>default domain</em> of the MBean server in which the
|
* by the <em>default domain</em> of the MBean server in which the
|
||||||
@ -171,6 +195,51 @@ import java.util.Map;
|
|||||||
* with {@code \}.</li>
|
* with {@code \}.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
* <p id="metawildcard"><b>Pattern and namespaces:</b></p>
|
||||||
|
* <p>In an object name pattern, a path element
|
||||||
|
* of exactly <code>**</code> corresponds to a meta
|
||||||
|
* wildcard that will match any number of sub namespaces.<br>Hence:</p>
|
||||||
|
* <table border="0" cellpadding="5">
|
||||||
|
* <thead><th>pattern</th><th>matches</th><th>doesn't match</th></thead>
|
||||||
|
* <tbody>
|
||||||
|
* <tr><td><ul><li><code>**//D:k=v</code></li></ul></td>
|
||||||
|
* <td><code>a//D:k=v</code><br>
|
||||||
|
* <code>a//b//D:k=v</code><br>
|
||||||
|
* <code>a//b//c//D:k=v</code></td>
|
||||||
|
* <td><code>D:k=v</code></td></tr>
|
||||||
|
* <tr><td><ul><li><code>a//**//D:k=v</code></li></ul></td>
|
||||||
|
* <td><code>a//b//D:k=v</code><br>
|
||||||
|
* <code>a//b//c//D:k=v</code></td>
|
||||||
|
* <td><code>b//b//c//D:k=v</code><br>
|
||||||
|
* <code>a//D:k=v</code><br>
|
||||||
|
* <code>D:k=v</code></td></tr>
|
||||||
|
* <tr><td><ul><li><code>a//**//e//D:k=v</code></li></ul></td>
|
||||||
|
* <td><code>a//b//e//D:k=v</code><br>
|
||||||
|
* <code>a//b//c//e//D:k=v</code></td>
|
||||||
|
* <td><code>a//b//c//c//D:k=v</code><br>
|
||||||
|
* <code>b//b//c//e//D:k=v</code><br>
|
||||||
|
* <code>a//e//D:k=v</code><br>
|
||||||
|
* <code>e//D:k=v</code></td></tr>
|
||||||
|
* <tr><td><ul><li><code>a//b**//e//D:k=v</code></li></ul></td>
|
||||||
|
* <td><code>a//b//e//D:k=v</code></td>
|
||||||
|
* <td><code>a//b//c//e//D:k=v</code><br>
|
||||||
|
* because in that case <code>b**</code><br>
|
||||||
|
* is not a meta-wildcard - and <code>b**</code><br>
|
||||||
|
* is thus equivalent to <code>b*</code>.</td></tr>
|
||||||
|
* </tbody>
|
||||||
|
* </table>
|
||||||
|
*</ul>
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* <b>Note:</b> Although ObjectName patterns where the characters
|
||||||
|
* <code>*</code> and <code>?</code> appear in the namespace path are legal,
|
||||||
|
* they are not valid in the {@code name} parameter of the MBean Server's
|
||||||
|
* {@link MBeanServer#queryNames queryNames} and {@link MBeanServer#queryMBeans
|
||||||
|
* queryMBeans} methods. See the
|
||||||
|
* <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!--
|
||||||
|
* -->namespaces documentation</a> for more details.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
* <p>An ObjectName can be written as a String with the following
|
* <p>An ObjectName can be written as a String with the following
|
||||||
* elements in order:</p>
|
* elements in order:</p>
|
||||||
*
|
*
|
||||||
@ -439,11 +508,6 @@ public class ObjectName implements Comparable<ObjectName>, QueryExp {
|
|||||||
_propertyList = aname._propertyList;
|
_propertyList = aname._propertyList;
|
||||||
_property_list_pattern = aname._property_list_pattern;
|
_property_list_pattern = aname._property_list_pattern;
|
||||||
_property_value_pattern = aname._property_value_pattern;
|
_property_value_pattern = aname._property_value_pattern;
|
||||||
// TODO remove this hack
|
|
||||||
// if (toString().endsWith("//javax.management.service:type1=event_client_delegeate_mbean,type2=default")) {
|
|
||||||
// Thread.currentThread().dumpStack();
|
|
||||||
// throw new Error("************************ Gotcha!");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instance private fields <=======================================
|
// Instance private fields <=======================================
|
||||||
@ -1096,11 +1160,10 @@ public class ObjectName implements Comparable<ObjectName>, QueryExp {
|
|||||||
*/
|
*/
|
||||||
private boolean isDomain(String domain) {
|
private boolean isDomain(String domain) {
|
||||||
if (domain == null) return true;
|
if (domain == null) return true;
|
||||||
final char[] d=domain.toCharArray();
|
final int len = domain.length();
|
||||||
final int len = d.length;
|
|
||||||
int next = 0;
|
int next = 0;
|
||||||
while (next < len) {
|
while (next < len) {
|
||||||
final char c = d[next++];
|
final char c = domain.charAt(next++);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ':' :
|
case ':' :
|
||||||
case '\n' :
|
case '\n' :
|
||||||
@ -1234,12 +1297,6 @@ public class ObjectName implements Comparable<ObjectName>, QueryExp {
|
|||||||
if (!nw.equals("")) {
|
if (!nw.equals("")) {
|
||||||
nameString = nw + NAMESPACE_SEPARATOR + nameString;
|
nameString = nw + NAMESPACE_SEPARATOR + nameString;
|
||||||
}
|
}
|
||||||
// TODO remove this hack
|
|
||||||
// if (nameString.endsWith("//javax.management.service:type1=event_client_delegeate_mbean,type2=default")) {
|
|
||||||
// System.err.println("old="+old+", nw="+nw);
|
|
||||||
// Thread.currentThread().dumpStack();
|
|
||||||
// throw new Error("************************ Gotcha!");
|
|
||||||
// }
|
|
||||||
return nameString;
|
return nameString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1584,13 +1641,18 @@ public class ObjectName implements Comparable<ObjectName>, QueryExp {
|
|||||||
* @return A new {@code ObjectName} that is the same as {@code this}
|
* @return A new {@code ObjectName} that is the same as {@code this}
|
||||||
* except the domain is {@code newDomain}.
|
* except the domain is {@code newDomain}.
|
||||||
* @throws NullPointerException if {@code newDomain} is null.
|
* @throws NullPointerException if {@code newDomain} is null.
|
||||||
* @throws MalformedObjectNameException if the new domain is syntactically
|
* @exception IllegalArgumentException The {@code newDomain} passed as a
|
||||||
* illegal.
|
* parameter does not have the right format. The {@linkplain
|
||||||
|
* Throwable#getCause() cause} of this exception will be a
|
||||||
|
* {@link MalformedObjectNameException}.
|
||||||
* @since 1.7
|
* @since 1.7
|
||||||
**/
|
**/
|
||||||
public final ObjectName withDomain(String newDomain)
|
public final ObjectName withDomain(String newDomain) {
|
||||||
throws MalformedObjectNameException {
|
try {
|
||||||
return new ObjectName(newDomain, this);
|
return new ObjectName(newDomain, this);
|
||||||
|
} catch (MalformedObjectNameException x) {
|
||||||
|
throw new IllegalArgumentException(x.getMessage(),x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,6 @@ import static javax.management.namespace.JMXNamespaces.NAMESPACE_SEPARATOR;
|
|||||||
import javax.management.InstanceNotFoundException;
|
import javax.management.InstanceNotFoundException;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerDelegate;
|
import javax.management.MBeanServerDelegate;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -291,12 +290,9 @@ public class JMXDomain extends JMXNamespace {
|
|||||||
public static ObjectName getDomainObjectName(String domain) {
|
public static ObjectName getDomainObjectName(String domain) {
|
||||||
if (domain == null) return null;
|
if (domain == null) return null;
|
||||||
if (domain.contains(NAMESPACE_SEPARATOR))
|
if (domain.contains(NAMESPACE_SEPARATOR))
|
||||||
throw new IllegalArgumentException(domain);
|
throw new IllegalArgumentException("domain contains " +
|
||||||
try {
|
NAMESPACE_SEPARATOR+": "+domain);
|
||||||
return ObjectName.getInstance(domain, "type", TYPE);
|
return ObjectName.valueOf(domain, "type", TYPE);
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
throw new IllegalArgumentException(domain,x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,7 +136,8 @@ import java.security.Permission;
|
|||||||
* <code>**</code> matches any number of sub namespaces
|
* <code>**</code> matches any number of sub namespaces
|
||||||
* recursively, but only if used as a complete namespace path element,
|
* recursively, but only if used as a complete namespace path element,
|
||||||
* as in <code>**//b//c//D:k=v</code> or <code>a//**//c//D:k=v</code>
|
* as in <code>**//b//c//D:k=v</code> or <code>a//**//c//D:k=v</code>
|
||||||
* - see <a href="#metawildcard">below</a>.
|
* - see ObjectName <a href="../ObjectName.html#metawildcard">documentation</a>
|
||||||
|
* for more details.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -270,38 +271,9 @@ import java.security.Permission;
|
|||||||
* </pre>
|
* </pre>
|
||||||
* <p><b>Note on wildcards:</b> In an object name pattern, a path element
|
* <p><b>Note on wildcards:</b> In an object name pattern, a path element
|
||||||
* of exactly <code>**</code> corresponds to a meta
|
* of exactly <code>**</code> corresponds to a meta
|
||||||
* wildcard that will match any number of sub namespaces. Hence:</p>
|
* wildcard that will match any number of sub namespaces.
|
||||||
* <ul>
|
* See ObjectName <a href="../ObjectName.html#metawildcard">documentation</a>
|
||||||
* <table border="1">
|
* for more details.</p>
|
||||||
* <thead><th>pattern</th><th>matches</th><th>doesn't match</th></thead>
|
|
||||||
* <tbody>
|
|
||||||
* <tr><td><code>**//D:k=v</code></td>
|
|
||||||
* <td><code>a//D:k=v</code><br>
|
|
||||||
* <code>a//b//D:k=v</code><br>
|
|
||||||
* <code>a//b//c//D:k=v</code></td>
|
|
||||||
* <td><code>D:k=v</code></td></tr>
|
|
||||||
* <tr><td><code>a//**//D:k=v</code></td>
|
|
||||||
* <td><code>a//b//D:k=v</code><br>
|
|
||||||
* <code>a//b//c//D:k=v</code></td>
|
|
||||||
* <td><code>b//b//c//D:k=v</code><br>
|
|
||||||
* <code>a//D:k=v</code><br>
|
|
||||||
* <code>D:k=v</code></td></tr>
|
|
||||||
* <tr><td><code>a//**//e//D:k=v</code></td>
|
|
||||||
* <td><code>a//b//e//D:k=v</code><br>
|
|
||||||
* <code>a//b//c//e//D:k=v</code></td>
|
|
||||||
* <td><code>a//b//c//c//D:k=v</code><br>
|
|
||||||
* <code>b//b//c//e//D:k=v</code><br>
|
|
||||||
* <code>a//e//D:k=v</code><br>
|
|
||||||
* <code>e//D:k=v</code></td></tr>
|
|
||||||
* <tr><td><code>a//b**//e//D:k=v</code></td>
|
|
||||||
* <td><code>a//b//e//D:k=v</code></td>
|
|
||||||
* <td><code>a//b//c//e//D:k=v</code><br>
|
|
||||||
* because in that case <code>b**</code><br>
|
|
||||||
* is not a meta-wildcard - and <code>b**</code><br>
|
|
||||||
* is thus equivalent to <code>b*</code>.</td></tr>
|
|
||||||
* </tbody>
|
|
||||||
* </table>
|
|
||||||
*</ul>
|
|
||||||
*
|
*
|
||||||
* <p>If {@code <mbean server name>::} is omitted, then one of
|
* <p>If {@code <mbean server name>::} is omitted, then one of
|
||||||
* <code>member</code> or <code>object name</code> may be omitted.
|
* <code>member</code> or <code>object name</code> may be omitted.
|
||||||
|
@ -292,17 +292,13 @@ public class JMXNamespaces {
|
|||||||
if (path == null || to == null)
|
if (path == null || to == null)
|
||||||
throw new IllegalArgumentException("Null argument");
|
throw new IllegalArgumentException("Null argument");
|
||||||
checkTrailingSlashes(path);
|
checkTrailingSlashes(path);
|
||||||
try {
|
String prefix = path;
|
||||||
String prefix = path;
|
if (!prefix.equals(""))
|
||||||
if (!prefix.equals("")) prefix =
|
prefix = ObjectNameRouter.normalizeNamespacePath(
|
||||||
ObjectNameRouter.normalizeNamespacePath(
|
|
||||||
prefix + NAMESPACE_SEPARATOR,false,false,false);
|
prefix + NAMESPACE_SEPARATOR,false,false,false);
|
||||||
return to.withDomain(
|
return to.withDomain(
|
||||||
ObjectNameRouter.normalizeDomain(
|
ObjectNameRouter.normalizeDomain(
|
||||||
prefix+to.getDomain(),false));
|
prefix+to.getDomain(),false));
|
||||||
} catch (MalformedObjectNameException x) {
|
|
||||||
throw new IllegalArgumentException(path+": "+x,x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,7 +204,38 @@
|
|||||||
* </pre>
|
* </pre>
|
||||||
* An easier way to access MBeans contained in a name space is to
|
* An easier way to access MBeans contained in a name space is to
|
||||||
* <i>cd</i> inside the name space, as shown in the following paragraph.
|
* <i>cd</i> inside the name space, as shown in the following paragraph.
|
||||||
* </p>
|
* </p><p id="RejectedNamespacePatterns">
|
||||||
|
* Although ObjectName patterns where the characters
|
||||||
|
* <code>*</code> and <code>?</code> appear in the namespace path are
|
||||||
|
* legal, they are not valid in the {@code name} parameter of the
|
||||||
|
* MBean Server {@link
|
||||||
|
* javax.management.MBeanServer#queryNames queryNames} and {@link
|
||||||
|
* javax.management.MBeanServer#queryMBeans queryMBeans} methods.<br>
|
||||||
|
* When invoking <code>queryNames</code> or <code>queryMBeans</code>,
|
||||||
|
* only ObjectNames of the form:<br>
|
||||||
|
* [<em>namespace-without-pattern</em>//]*[<em>pattern-without-namespace</em>]:<em>key-properties-with-or-without-pattern</em>
|
||||||
|
* are valid.<br>
|
||||||
|
* In other words: in the case of {@link
|
||||||
|
* javax.management.MBeanServer#queryNames queryNames} and {@link
|
||||||
|
* javax.management.MBeanServer#queryMBeans queryMBeans}, if a
|
||||||
|
* namespace path is present, it must not contain any pattern.
|
||||||
|
* </p><p id="NamespaceAndQueries">
|
||||||
|
* There is no such restriction for the {@code query} parameter of these
|
||||||
|
* methods. However, it must be noted that the {@code query} parameter
|
||||||
|
* will be evaluated in the context of the namespace where the MBeans
|
||||||
|
* selected by the pattern specified in {@code name} are located.
|
||||||
|
* This means that if {@code query} parameter is an ObjectName pattern that
|
||||||
|
* contains a namespace path, no MBean name will match and the result of
|
||||||
|
* the query will be empty.<br>
|
||||||
|
* In other words:</p>
|
||||||
|
* <ul><li>{@code queryNames("foo//bar//?a?:*","b?z:type=Monitor,*")} will select
|
||||||
|
* all MBeans in namespace <em>foo//bar</em> whose names match both
|
||||||
|
* <em>?a?:*</em> and <em>b?z:type=Monitor,*</em>, but</li>
|
||||||
|
* <li>{@code queryNames("foo//bar//?a?:*","foo//bar//b?z:type=Monitor,*")}
|
||||||
|
* will select nothing because no name matching <em>?a?:*</em> will
|
||||||
|
* also match <em>foo//bar//b?z:type=Monitor,*</em>.
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* <h3 id="ChangeTo">Narrowing Down Into a Name Spaces</h3>
|
* <h3 id="ChangeTo">Narrowing Down Into a Name Spaces</h3>
|
||||||
* <p>
|
* <p>
|
||||||
@ -228,7 +259,8 @@
|
|||||||
* to name space {@code "foo"} behaves just like a regular MBean server.
|
* to name space {@code "foo"} behaves just like a regular MBean server.
|
||||||
* However, it may sometimes throw an {@link
|
* However, it may sometimes throw an {@link
|
||||||
* java.lang.UnsupportedOperationException UnsupportedOperationException}
|
* java.lang.UnsupportedOperationException UnsupportedOperationException}
|
||||||
* wrapped in a JMX exception if you try to call an operation which is not
|
* wrapped in a {@link javax.management.RuntimeOperationsException
|
||||||
|
* RuntimeOperationsException} if you try to call an operation which is not
|
||||||
* supported by the underlying name space handler.
|
* supported by the underlying name space handler.
|
||||||
* <br>For instance, {@link javax.management.MBeanServer#registerMBean
|
* <br>For instance, {@link javax.management.MBeanServer#registerMBean
|
||||||
* registerMBean} is not supported for name spaces mounted from remote
|
* registerMBean} is not supported for name spaces mounted from remote
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
* @test LeadingSeparatorsTest.java
|
* @test LeadingSeparatorsTest.java
|
||||||
* @summary Test that the semantics of a leading // in ObjectName is respected.
|
* @summary Test that the semantics of a leading // in ObjectName is respected.
|
||||||
* @author Daniel Fuchs
|
* @author Daniel Fuchs
|
||||||
* @bug 5072476
|
* @bug 5072476 6768935
|
||||||
* @run clean LeadingSeparatorsTest Wombat WombatMBean
|
* @run clean LeadingSeparatorsTest Wombat WombatMBean
|
||||||
* @compile -XDignore.symbol.file=true LeadingSeparatorsTest.java
|
* @compile -XDignore.symbol.file=true LeadingSeparatorsTest.java
|
||||||
* @run build LeadingSeparatorsTest Wombat WombatMBean
|
* @run build LeadingSeparatorsTest Wombat WombatMBean
|
||||||
@ -36,6 +36,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.management.InstanceNotFoundException;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
import javax.management.NotCompliantMBeanException;
|
import javax.management.NotCompliantMBeanException;
|
||||||
@ -121,19 +122,29 @@ public class LeadingSeparatorsTest {
|
|||||||
// register wombat using an object name with a leading //
|
// register wombat using an object name with a leading //
|
||||||
final Object obj = new MyWombat();
|
final Object obj = new MyWombat();
|
||||||
// check that returned object name doesn't have the leading //
|
// check that returned object name doesn't have the leading //
|
||||||
assertEquals(n2,top.registerMBean(obj, n1).getObjectName());
|
assertEquals(n2,top.registerMBean(obj, n2).getObjectName());
|
||||||
System.out.println(n1+" registered");
|
System.out.println(n1+" registered");
|
||||||
|
|
||||||
// check that the registered Wombat can be accessed with all its
|
// check that the registered Wombat can be accessed with all its
|
||||||
// names.
|
// names.
|
||||||
System.out.println(n2+" mood is: "+top.getAttribute(n2, "Mood"));
|
System.out.println(n2+" mood is: "+top.getAttribute(n2, "Mood"));
|
||||||
System.out.println(n1+" mood is: "+top.getAttribute(n1, "Mood"));
|
try {
|
||||||
|
System.out.println(n1+" mood is: "+top.getAttribute(n1, "Mood"));
|
||||||
|
throw new Exception("Excepected exception not thrown for "+n1);
|
||||||
|
} catch (InstanceNotFoundException x) {
|
||||||
|
System.out.println("OK: "+x);
|
||||||
|
}
|
||||||
System.out.println(n4+" mood is: "+top.getAttribute(n4, "Mood"));
|
System.out.println(n4+" mood is: "+top.getAttribute(n4, "Mood"));
|
||||||
System.out.println(n3+" mood is: "+top.getAttribute(n3, "Mood"));
|
try {
|
||||||
|
System.out.println(n3+" mood is: "+top.getAttribute(n3, "Mood"));
|
||||||
|
throw new Exception("Excepected exception not thrown for "+n3);
|
||||||
|
} catch (InstanceNotFoundException x) {
|
||||||
|
System.out.println("OK: "+x);
|
||||||
|
}
|
||||||
|
|
||||||
// call listMatching. The result should not contain any prefix.
|
// call listMatching. The result should not contain any prefix.
|
||||||
final Set<ObjectName> res = (Set<ObjectName>)
|
final Set<ObjectName> res = (Set<ObjectName>)
|
||||||
top.invoke(n3, "listMatching",
|
top.invoke(n4, "listMatching",
|
||||||
// remove rmi// from rmi//*:*
|
// remove rmi// from rmi//*:*
|
||||||
JMXNamespaces.deepReplaceHeadNamespace(
|
JMXNamespaces.deepReplaceHeadNamespace(
|
||||||
new Object[] {ObjectName.WILDCARD.withDomain("rmi//*")},
|
new Object[] {ObjectName.WILDCARD.withDomain("rmi//*")},
|
||||||
@ -158,7 +169,7 @@ public class LeadingSeparatorsTest {
|
|||||||
// //niark//niark//
|
// //niark//niark//
|
||||||
//
|
//
|
||||||
final Set<ObjectName> res4 = (Set<ObjectName>)
|
final Set<ObjectName> res4 = (Set<ObjectName>)
|
||||||
top.invoke(n3, "untrue",
|
top.invoke(n4, "untrue",
|
||||||
// remove niark//niark : should remove nothing since
|
// remove niark//niark : should remove nothing since
|
||||||
// our ObjectName begins with a leading //
|
// our ObjectName begins with a leading //
|
||||||
JMXNamespaces.deepReplaceHeadNamespace(
|
JMXNamespaces.deepReplaceHeadNamespace(
|
||||||
|
@ -40,6 +40,7 @@ import javax.management.MBeanServerFactory;
|
|||||||
import javax.management.NotCompliantMBeanException;
|
import javax.management.NotCompliantMBeanException;
|
||||||
import javax.management.ObjectInstance;
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
import javax.management.RuntimeOperationsException;
|
||||||
import javax.management.namespace.JMXNamespaces;
|
import javax.management.namespace.JMXNamespaces;
|
||||||
import javax.management.namespace.JMXRemoteNamespace;
|
import javax.management.namespace.JMXRemoteNamespace;
|
||||||
import javax.management.namespace.JMXNamespace;
|
import javax.management.namespace.JMXNamespace;
|
||||||
@ -215,9 +216,20 @@ public class NullDomainObjectNameTest {
|
|||||||
assertEquals(proxy.queryNames(
|
assertEquals(proxy.queryNames(
|
||||||
new ObjectName(":*"),null).
|
new ObjectName(":*"),null).
|
||||||
contains(moi3.getObjectName()),true);
|
contains(moi3.getObjectName()),true);
|
||||||
failed("queryNames(null,null) should have failed for faked//");
|
failed("queryNames(new ObjectName(\":*\"),null) " +
|
||||||
} catch (IllegalArgumentException x) {
|
"should have failed for faked//");
|
||||||
System.out.println("Received expected exception for faked//: "+x);
|
} catch (RuntimeOperationsException x) {
|
||||||
|
if (x.getCause() instanceof IllegalArgumentException)
|
||||||
|
System.out.println(
|
||||||
|
"Received expected exception for faked//: "+x);
|
||||||
|
else {
|
||||||
|
System.err.println(
|
||||||
|
"Expected exception has unexpected cause " +
|
||||||
|
"for faked//: "+x.getCause());
|
||||||
|
x.printStackTrace();
|
||||||
|
failed("queryNames(new ObjectName(\":*\"),null)" +
|
||||||
|
" failed with unexpected cause for faked//");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// These should fail because the ObjectName doesn't start
|
// These should fail because the ObjectName doesn't start
|
||||||
// with "faked//"
|
// with "faked//"
|
||||||
@ -226,9 +238,20 @@ public class NullDomainObjectNameTest {
|
|||||||
"new ObjectName(\":*\"),null) with faked//");
|
"new ObjectName(\":*\"),null) with faked//");
|
||||||
assertEquals(proxy.queryMBeans(
|
assertEquals(proxy.queryMBeans(
|
||||||
new ObjectName(":*"),null).contains(moi3),true);
|
new ObjectName(":*"),null).contains(moi3),true);
|
||||||
failed("queryMBeans(null,null) should have failed for faked//");
|
failed("queryMBeans(new ObjectName(\":*\"),null)" +
|
||||||
} catch (IllegalArgumentException x) {
|
" should have failed for faked//");
|
||||||
System.out.println("Received expected exception for faked//: "+x);
|
} catch (RuntimeOperationsException x) {
|
||||||
|
if (x.getCause() instanceof IllegalArgumentException)
|
||||||
|
System.out.println(
|
||||||
|
"Received expected exception for faked//: "+x);
|
||||||
|
else {
|
||||||
|
System.err.println(
|
||||||
|
"Expected exception has unexpected cause " +
|
||||||
|
"for faked//: "+x.getCause());
|
||||||
|
x.printStackTrace();
|
||||||
|
failed("queryMBeans(new ObjectName(\":*\"),null) " +
|
||||||
|
"failed with unexpected cause for faked//");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Checking queryNames(faked//*:*,null)");
|
System.out.println("Checking queryNames(faked//*:*,null)");
|
||||||
|
@ -41,6 +41,7 @@ import javax.management.MBeanServerFactory;
|
|||||||
import javax.management.NotCompliantMBeanException;
|
import javax.management.NotCompliantMBeanException;
|
||||||
import javax.management.ObjectInstance;
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
import javax.management.RuntimeOperationsException;
|
||||||
import javax.management.namespace.JMXNamespaces;
|
import javax.management.namespace.JMXNamespaces;
|
||||||
import javax.management.namespace.JMXRemoteNamespace;
|
import javax.management.namespace.JMXRemoteNamespace;
|
||||||
import javax.management.namespace.JMXNamespace;
|
import javax.management.namespace.JMXNamespace;
|
||||||
@ -189,15 +190,35 @@ public class NullObjectNameTest {
|
|||||||
assertEquals(proxy.queryNames(null,null).
|
assertEquals(proxy.queryNames(null,null).
|
||||||
contains(moi3.getObjectName()),true);
|
contains(moi3.getObjectName()),true);
|
||||||
failed("queryNames(null,null) should have failed for faked//");
|
failed("queryNames(null,null) should have failed for faked//");
|
||||||
} catch (IllegalArgumentException x) {
|
} catch (RuntimeOperationsException x) {
|
||||||
System.out.println("Received expected exception for faked//: "+x);
|
if (x.getCause() instanceof IllegalArgumentException)
|
||||||
|
System.out.println(
|
||||||
|
"Received expected exception for faked//: "+x);
|
||||||
|
else {
|
||||||
|
System.err.println(
|
||||||
|
"Expected exception has unexpected cause " +
|
||||||
|
"for faked//: "+x.getCause());
|
||||||
|
x.printStackTrace();
|
||||||
|
failed("queryNames(null,null) failed with unexpected " +
|
||||||
|
"cause for faked//");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
System.out.println("Checking queryMBeans(null,null) with faked//");
|
System.out.println("Checking queryMBeans(null,null) with faked//");
|
||||||
assertEquals(proxy.queryMBeans(null,null).contains(moi3),true);
|
assertEquals(proxy.queryMBeans(null,null).contains(moi3),true);
|
||||||
failed("queryMBeans(null,null) should have failed for faked//");
|
failed("queryMBeans(null,null) should have failed for faked//");
|
||||||
} catch (IllegalArgumentException x) {
|
} catch (RuntimeOperationsException x) {
|
||||||
System.out.println("Received expected exception for faked//: "+x);
|
if (x.getCause() instanceof IllegalArgumentException)
|
||||||
|
System.out.println(
|
||||||
|
"Received expected exception for faked//: "+x);
|
||||||
|
else {
|
||||||
|
System.err.println(
|
||||||
|
"Expected exception has unexpected cause " +
|
||||||
|
"for faked//: "+x.getCause());
|
||||||
|
x.printStackTrace();
|
||||||
|
failed("queryMBeans(null,null) failed with unexpected " +
|
||||||
|
"cause for faked//");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
System.out.println("Checking queryNames(faked//*:*,null)");
|
System.out.println("Checking queryNames(faked//*:*,null)");
|
||||||
assertEquals(proxy.queryNames(new ObjectName("faked//*:*"),null).
|
assertEquals(proxy.queryNames(new ObjectName("faked//*:*"),null).
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
* @test QueryNamesTest.java 1.4
|
* @test QueryNamesTest.java 1.4
|
||||||
* @summary Test how queryNames works with Namespaces.
|
* @summary Test how queryNames works with Namespaces.
|
||||||
* @author Daniel Fuchs
|
* @author Daniel Fuchs
|
||||||
* @bug 5072476
|
* @bug 5072476 6768935
|
||||||
* @run clean QueryNamesTest Wombat WombatMBean
|
* @run clean QueryNamesTest Wombat WombatMBean
|
||||||
* @run build QueryNamesTest Wombat WombatMBean
|
* @run build QueryNamesTest Wombat WombatMBean
|
||||||
* @run main QueryNamesTest
|
* @run main QueryNamesTest
|
||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -52,7 +53,9 @@ import javax.management.MBeanServer;
|
|||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
import javax.management.MalformedObjectNameException;
|
import javax.management.MalformedObjectNameException;
|
||||||
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
import javax.management.RuntimeOperationsException;
|
||||||
import javax.management.namespace.JMXNamespace;
|
import javax.management.namespace.JMXNamespace;
|
||||||
import javax.management.namespace.JMXNamespaces;
|
import javax.management.namespace.JMXNamespaces;
|
||||||
|
|
||||||
@ -366,6 +369,66 @@ public class QueryNamesTest {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void checkNsPattern(MBeanServer server) throws Exception {
|
||||||
|
final List<String> list = new ArrayList<String>();
|
||||||
|
for (String s : namespaces) {
|
||||||
|
final String[] cmpnt = s.split("//");
|
||||||
|
for (int i=0;i<cmpnt.length;i++) {
|
||||||
|
final String[] clone = cmpnt.clone();
|
||||||
|
if (clone[i].length() < 3) {
|
||||||
|
clone[i] = "*";
|
||||||
|
} else {
|
||||||
|
clone[i] = "?"+cmpnt[i].substring(1, cmpnt[i].length()-2)+"*";
|
||||||
|
}
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
for (int j=0;j<cmpnt.length;j++) {
|
||||||
|
sb.append(clone[j]).append("//");
|
||||||
|
}
|
||||||
|
list.add(sb.toString()+"*:*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : list) {
|
||||||
|
final Set<ObjectName> res = new HashSet<ObjectName>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
res.addAll(server.queryNames(ObjectName.valueOf(s),null));
|
||||||
|
} catch (RuntimeOperationsException x) {
|
||||||
|
if (x.getCause() instanceof IllegalArgumentException) {
|
||||||
|
System.out.println("queryNames("+s+"): OK - received "+x.getCause());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.err.println("queryNames("+s+"): Bad cause: "+x.getCause());
|
||||||
|
throw x;
|
||||||
|
} catch (Exception x) {
|
||||||
|
System.err.println("queryNames("+s+"): Bad exception: "+x);
|
||||||
|
throw x;
|
||||||
|
}
|
||||||
|
System.err.println("queryNames("+s+"): Bad result: "+res);
|
||||||
|
System.err.println("queryNames("+s+"): Excpected exception not thrown.");
|
||||||
|
throw new Exception("queryNames("+s+"): Excpected exception not thrown.");
|
||||||
|
}
|
||||||
|
for (String s : list) {
|
||||||
|
final Set<ObjectInstance> res = new HashSet<ObjectInstance>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
res.addAll(server.queryMBeans(ObjectName.valueOf(s),null));
|
||||||
|
} catch (RuntimeOperationsException x) {
|
||||||
|
if (x.getCause() instanceof IllegalArgumentException) {
|
||||||
|
System.out.println("queryMBeans("+s+"): OK - received "+x.getCause());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.err.println("queryMBeans("+s+"): Bad cause: "+x.getCause());
|
||||||
|
throw x;
|
||||||
|
} catch (Exception x) {
|
||||||
|
System.err.println("queryMBeans("+s+"): Bad exception: "+x);
|
||||||
|
throw x;
|
||||||
|
}
|
||||||
|
System.err.println("queryMBeans("+s+"): Bad result: "+res);
|
||||||
|
System.err.println("queryMBeans("+s+"): Excpected exception not thrown.");
|
||||||
|
throw new Exception("queryMBeans("+s+"): Excpected exception not thrown.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
||||||
@ -378,6 +441,7 @@ public class QueryNamesTest {
|
|||||||
System.out.println("Domains: " +Arrays.asList(server.getDomains()));
|
System.out.println("Domains: " +Arrays.asList(server.getDomains()));
|
||||||
checkRegistration(server);
|
checkRegistration(server);
|
||||||
checkNsQuery(server);
|
checkNsQuery(server);
|
||||||
|
checkNsPattern(server);
|
||||||
} finally {
|
} finally {
|
||||||
boolean res = true;
|
boolean res = true;
|
||||||
res = res && removeWombats(server, wombats);
|
res = res && removeWombats(server, wombats);
|
||||||
|
Loading…
Reference in New Issue
Block a user