Java Code Examples for javax.management.ObjectName#toString()

The following examples show how to use javax.management.ObjectName#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryUserDatabaseMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the MBean Name for the specified group name (if any);
 * otherwise return <code>null</code>.
 *
 * @param groupname Group name to look up
 */
public String findGroup(String groupname) {

    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.findGroup(groupname);
    if (group == null) {
        return (null);
    }
    try {
        ObjectName oname =
            MBeanUtils.createObjectName(managedGroup.getDomain(), group);
        return (oname.toString());
    } catch (MalformedObjectNameException e) {
        IllegalArgumentException iae = new IllegalArgumentException
            ("Cannot create object name for group [" + groupname + "]");
        iae.initCause(e);
        throw iae;
    }

}
 
Example 2
Source File: DefaultMBeanServerInterceptor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a specific MBean controlled by the DefaultMBeanServerInterceptor.
 * The name must have a non-default domain.
 */
private DynamicMBean getMBean(ObjectName name)
    throws InstanceNotFoundException {

    if (name == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Object name cannot be null"),
                           "Exception occurred trying to get an MBean");
    }
    DynamicMBean obj = repository.retrieve(name);
    if (obj == null) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
            MBEANSERVER_LOGGER.logp(Level.FINER,
                    DefaultMBeanServerInterceptor.class.getName(),
                    "getMBean", name + " : Found no object");
        }
        throw new InstanceNotFoundException(name.toString());
    }
    return obj;
}
 
Example 3
Source File: MemoryUserDatabaseMBean.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return the MBean Name for the specified group name (if any);
 * otherwise return <code>null</code>.
 *
 * @param groupname Group name to look up
 */
public String findGroup(String groupname) {

    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.findGroup(groupname);
    if (group == null) {
        return (null);
    }
    try {
        ObjectName oname =
            MBeanUtils.createObjectName(managedGroup.getDomain(), group);
        return (oname.toString());
    } catch (MalformedObjectNameException e) {
        IllegalArgumentException iae = new IllegalArgumentException
            ("Cannot create object name for group [" + groupname + "]");
        iae.initCause(e);
        throw iae;
    }

}
 
Example 4
Source File: DefaultMBeanServerInterceptor.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a specific MBean controlled by the DefaultMBeanServerInterceptor.
 * The name must have a non-default domain.
 */
private DynamicMBean getMBean(ObjectName name)
    throws InstanceNotFoundException {

    if (name == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Object name cannot be null"),
                           "Exception occurred trying to get an MBean");
    }
    DynamicMBean obj = repository.retrieve(name);
    if (obj == null) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
            MBEANSERVER_LOGGER.logp(Level.FINER,
                    DefaultMBeanServerInterceptor.class.getName(),
                    "getMBean", name + " : Found no object");
        }
        throw new InstanceNotFoundException(name.toString());
    }
    return obj;
}
 
Example 5
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new Remote Host Filter Valve.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 *
 * @deprecated  Will be removed in Tomcat 8.0.x. Replaced by {@link
 *              #createValve(String, String)}.
 */
@Deprecated
public String createRemoteHostValve(String parent)
    throws Exception {

    // Create a new RemoteHostValve instance
    RemoteHostValve valve = new RemoteHostValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ContainerBase containerBase = getParentContainerFromParent(pname);
    containerBase.getPipeline().addValve(valve);
    ObjectName oname = valve.getObjectName();
    return (oname.toString());
    
}
 
Example 6
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Return the named {@link java.lang.ClassLoader}.
 * @param loaderName The ObjectName of the ClassLoader.
 * @return The named ClassLoader.
 * @exception InstanceNotFoundException if the named ClassLoader
 * is not found.
 */
public ClassLoader getClassLoader(ObjectName loaderName)
        throws InstanceNotFoundException {

    if (loaderName == null) {
        checkMBeanPermission((String) null, null, null, "getClassLoader");
        return server.getClass().getClassLoader();
    }

    DynamicMBean instance = getMBean(loaderName);
    checkMBeanPermission(instance, null, loaderName, "getClassLoader");

    Object resource = getResource(instance);

    /* Check if the given MBean is a ClassLoader */
    if (!(resource instanceof ClassLoader))
        throw new InstanceNotFoundException(loaderName.toString() +
                                            " is not a classloader");

    return (ClassLoader) resource;
}
 
Example 7
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Create a new Connector
 *
 * @param parent MBean Name of the associated parent component
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 * @param isAjp Create a AJP/1.3 Connector
 * @param isSSL Create a secure Connector
 *
 * @exception Exception if an MBean cannot be created or registered
 */
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL)
    throws Exception {
    // Set the protocol
    String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
    Connector retobj = new Connector(protocol);
    if ((address!=null) && (address.length()>0)) {
        retobj.setProperty("address", address);
    }
    // Set port number
    retobj.setPort(port);
    // Set SSL
    retobj.setSecure(isSSL);
    retobj.setScheme(isSSL ? "https" : "http");
    // Add the new instance to its parent component
    // FIX ME - addConnector will fail
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    service.addConnector(retobj);

    // Return the corresponding MBean name
    ObjectName coname = retobj.getObjectName();

    return coname.toString();
}
 
Example 8
Source File: DefaultMBeanServerInterceptor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Return the named {@link java.lang.ClassLoader}.
 * @param loaderName The ObjectName of the ClassLoader.
 * @return The named ClassLoader.
 * @exception InstanceNotFoundException if the named ClassLoader
 * is not found.
 */
public ClassLoader getClassLoader(ObjectName loaderName)
        throws InstanceNotFoundException {

    if (loaderName == null) {
        checkMBeanPermission((String) null, null, null, "getClassLoader");
        return server.getClass().getClassLoader();
    }

    DynamicMBean instance = getMBean(loaderName);
    checkMBeanPermission(instance, null, loaderName, "getClassLoader");

    Object resource = getResource(instance);

    /* Check if the given MBean is a ClassLoader */
    if (!(resource instanceof ClassLoader))
        throw new InstanceNotFoundException(loaderName.toString() +
                                            " is not a classloader");

    return (ClassLoader) resource;
}
 
Example 9
Source File: OldMBeanServerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private DynamicMBean getMBean(ObjectName name)
throws InstanceNotFoundException {
    DynamicMBean mbean = mbeans.get(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());
    return mbean;
}
 
Example 10
Source File: OldMBeanServerTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private DynamicMBean getMBean(ObjectName name)
throws InstanceNotFoundException {
    DynamicMBean mbean = mbeans.get(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());
    return mbean;
}
 
Example 11
Source File: GatewaySenderTestMBean.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private Object getWanSenderMemberId(ObjectName targetMbean) {
  String name = targetMbean.toString();
  Matcher match = memberPattern.matcher(name.toString());
  String memberName = null;
  if(match.find()){
    memberName = match.group(2);
  }
  HydraUtil.logFine("WanSenderMember Id = " + memberName + " for ON" + name);
  return memberName;
}
 
Example 12
Source File: JmxUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private static ObjectName getObjectName(ObjectName base, String keyprop)
        throws MalformedObjectNameException {
    if (base == null) return null;
    StringBuilder OnameStr = new StringBuilder(base.toString());
    if (keyprop != null) OnameStr.append(keyprop);
    ObjectName oname = new ObjectName(OnameStr.toString());
    return oname;
}
 
Example 13
Source File: OldMBeanServerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {

    forbidJMImpl(name);

    DynamicMBean mbean = getMBean(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());

    MBeanRegistration reg = mbeanRegistration(mbean);
    try {
        reg.preDeregister();
    } catch (Exception e) {
        throw new MBeanRegistrationException(e);
    }
    if (!mbeans.remove(name, mbean))
        throw new InstanceNotFoundException(name.toString());
        // This is incorrect because we've invoked preDeregister

    Object userMBean = getUserMBean(mbean);
    if (userMBean instanceof ClassLoader)
        clr.removeLoader((ClassLoader) userMBean);

    Notification n = new MBeanServerNotification(
            MBeanServerNotification.REGISTRATION_NOTIFICATION,
            MBeanServerDelegate.DELEGATE_NAME,
            0,
            name);
    delegate.sendNotification(n);

    reg.postDeregister();
}
 
Example 14
Source File: OldMBeanServerTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {

    forbidJMImpl(name);

    DynamicMBean mbean = getMBean(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());

    MBeanRegistration reg = mbeanRegistration(mbean);
    try {
        reg.preDeregister();
    } catch (Exception e) {
        throw new MBeanRegistrationException(e);
    }
    if (!mbeans.remove(name, mbean))
        throw new InstanceNotFoundException(name.toString());
        // This is incorrect because we've invoked preDeregister

    Object userMBean = getUserMBean(mbean);
    if (userMBean instanceof ClassLoader)
        clr.removeLoader((ClassLoader) userMBean);

    Notification n = new MBeanServerNotification(
            MBeanServerNotification.REGISTRATION_NOTIFICATION,
            MBeanServerDelegate.DELEGATE_NAME,
            0,
            name);
    delegate.sendNotification(n);

    reg.postDeregister();
}
 
Example 15
Source File: JvmJsonService.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@GET(path = "/backend/jvm/mbean-tree", permission = "agent:jvm:mbeanTree")
String getMBeanTree(@BindAgentId String agentId, @BindRequest MBeanTreeRequest request)
        throws Exception {
    checkNotNull(liveJvmService);
    MBeanDump mbeanDump;
    try {
        mbeanDump = liveJvmService.getMBeanDump(agentId,
                MBeanDumpKind.ALL_MBEANS_INCLUDE_ATTRIBUTES_FOR_SOME, request.expanded());
    } catch (AgentNotConnectedException e) {
        logger.debug(e.getMessage(), e);
        return "{\"agentNotConnected\":true}";
    }
    Map<String, MBeanTreeInnerNode> sortedRootNodes = Maps.newTreeMap();
    for (MBeanDump.MBeanInfo mbeanInfo : mbeanDump.getMbeanInfoList()) {
        ObjectName objectName = ObjectName.getInstance(mbeanInfo.getObjectName());
        String domain = objectName.getDomain();
        MBeanTreeInnerNode node = sortedRootNodes.get(domain);
        if (node == null) {
            node = new MBeanTreeInnerNode(domain);
            sortedRootNodes.put(domain, node);
        }
        List<String> propertyValues = ObjectNames.getPropertyValues(objectName);
        for (int i = 0; i < propertyValues.size() - 1; i++) {
            node = node.getOrCreateNode(propertyValues.get(i));
        }
        String name = objectName.toString();
        String value = Iterables.getLast(propertyValues);
        if (request.expanded().contains(name)) {
            node.addLeafNode(new MBeanTreeLeafNode(value, name, true,
                    getSortedAttributeMap(mbeanInfo.getAttributeList())));
        } else {
            node.addLeafNode(new MBeanTreeLeafNode(value, name, false, null));
        }
    }
    return mapper.writeValueAsString(sortedRootNodes);
}
 
Example 16
Source File: OldMBeanServerTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private DynamicMBean getMBean(ObjectName name)
throws InstanceNotFoundException {
    DynamicMBean mbean = mbeans.get(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());
    return mbean;
}
 
Example 17
Source File: Repository.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Removes an MBean from the repository.
 *
 * @param name name of the MBean to remove.
 * @param context A registration context. If non null, the repository
 *                will call {@link RegistrationContext#unregistered()
 *                context.unregistered()} from within the repository
 *                lock, just after the mbean associated with
 *                {@code name} is removed from the repository.
 *                If {@link RegistrationContext#unregistered()
 *                context.unregistered()} is not expected to throw any
 *                exception. If it does, the exception is logged
 *                and swallowed.
 *
 * @exception InstanceNotFoundException The MBean does not exist in
 *            the repository.
 */
public void remove(final ObjectName name,
        final RegistrationContext context)
    throws InstanceNotFoundException {

    // Debugging stuff
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, Repository.class.getName(),
                "remove", "name = " + name);
    }

    // Extract domain name.
    String dom= name.getDomain().intern();

    // Default domain case
    if (dom.length() == 0) dom = domain;

    lock.writeLock().lock();
    try {
        // Find the domain subtable
        final Map<String,NamedObject> moiTb = domainTb.get(dom);
        if (moiTb == null) {
            throw new InstanceNotFoundException(name.toString());
        }

        // Remove the corresponding element
        if (moiTb.remove(name.getCanonicalKeyPropertyListString())==null) {
            throw new InstanceNotFoundException(name.toString());
        }

        // We removed it !
        nbElements--;

        // No more object for this domain, we remove this domain hashtable
        if (moiTb.isEmpty()) {
            domainTb.remove(dom);

            // set a new default domain table (always present)
            // need to reinstantiate a hashtable because of possible
            // big buckets array size inside table, never cleared,
            // thus the new !
            if (dom == domain) // ES: OK dom and domain are interned.
                domainTb.put(domain, new HashMap<String,NamedObject>());
        }

        unregistering(context,name);

    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 18
Source File: ObjectInstance.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Allows an object instance to be created given an object name and
 * the full class name, including the package name.
 *
 * @param objectName  The object name.
 * @param className  The full class name, including the package
 * name, of the object instance.  If the MBean is a Dynamic MBean
 * the class name corresponds to its {@link
 * DynamicMBean#getMBeanInfo()
 * getMBeanInfo()}<code>.getClassName()</code>.
 * If the MBean is a Dynamic MBean the class name should be retrieved
 * from the <CODE>MBeanInfo</CODE> it provides.
 *
 */
public ObjectInstance(ObjectName objectName, String className) {
    if (objectName.isPattern()) {
        final IllegalArgumentException iae =
            new IllegalArgumentException("Invalid name->"+
                                         objectName.toString());
        throw new RuntimeOperationsException(iae);
    }
    this.name= objectName;
    this.className= className;
}
 
Example 19
Source File: ObjectInstance.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Allows an object instance to be created given an object name and
 * the full class name, including the package name.
 *
 * @param objectName  The object name.
 * @param className  The full class name, including the package
 * name, of the object instance.  If the MBean is a Dynamic MBean
 * the class name corresponds to its {@link
 * DynamicMBean#getMBeanInfo()
 * getMBeanInfo()}<code>.getClassName()</code>.
 * If the MBean is a Dynamic MBean the class name should be retrieved
 * from the <CODE>MBeanInfo</CODE> it provides.
 *
 */
public ObjectInstance(ObjectName objectName, String className) {
    if (objectName.isPattern()) {
        final IllegalArgumentException iae =
            new IllegalArgumentException("Invalid name->"+
                                         objectName.toString());
        throw new RuntimeOperationsException(iae);
    }
    this.name= objectName;
    this.className= className;
}
 
Example 20
Source File: ObjectInstance.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Allows an object instance to be created given an object name and
 * the full class name, including the package name.
 *
 * @param objectName  The object name.
 * @param className  The full class name, including the package
 * name, of the object instance.  If the MBean is a Dynamic MBean
 * the class name corresponds to its {@link
 * DynamicMBean#getMBeanInfo()
 * getMBeanInfo()}<code>.getClassName()</code>.
 * If the MBean is a Dynamic MBean the class name should be retrieved
 * from the <CODE>MBeanInfo</CODE> it provides.
 *
 */
public ObjectInstance(ObjectName objectName, String className) {
    if (objectName.isPattern()) {
        final IllegalArgumentException iae =
            new IllegalArgumentException("Invalid name->"+
                                         objectName.toString());
        throw new RuntimeOperationsException(iae);
    }
    this.name= objectName;
    this.className= className;
}