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

The following examples show how to use javax.management.ObjectName#getDomain() . 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: BlockingNotificationMBeanServer.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean isInExposedModelControllerDomains(ObjectName name) {
    String domain = name.getDomain();

    if (!name.isDomainPattern()) {
        if (domain.equals(resolvedDomain) || domain.equals(expressionsDomain)) {
            return true;
        }
    }
    Pattern p = Pattern.compile(name.getDomain().replace("*", ".*"));
    if ((resolvedDomain != null && p.matcher(resolvedDomain).matches())
            || (expressionsDomain != null && p.matcher(expressionsDomain).matches())) {
        return true;
    }

    return false;
}
 
Example 2
Source File: MBeanLifecycleManager.java    From flex-blazeds with Apache License 2.0 6 votes vote down vote up
/**
 * Unregisters all runtime MBeans that are registered in the same domain as the 
 * MessageBrokerControl for the target MessageBroker. 
 *  
 * @param broker The MessageBroker component that has been stopped.
 */
public static void unregisterRuntimeMBeans(MessageBroker broker)
{        
    MBeanServer server = MBeanServerLocatorFactory.getMBeanServerLocator().getMBeanServer();
    ObjectName brokerMBean = broker.getControl().getObjectName();
    String domain = brokerMBean.getDomain();
    try
    {
        ObjectName pattern = new ObjectName(domain + ":*");
        Set names = server.queryNames(pattern, null);
        Iterator iter = names.iterator();
        while (iter.hasNext())
        {
            ObjectName on = (ObjectName)iter.next();
            server.unregisterMBean(on);
        }
    }
    catch (Exception e)
    {
        // We're generally unregistering these during shutdown (possibly JVM shutdown)
        // so there's nothing to really do here because we aren't guaranteed access to
        // resources like system log files, localized messaging, etc.
    }
}
 
Example 3
Source File: ConfiguredDomains.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
ObjectName getMirroredObjectName(ObjectName name) {
    String domain = name.getDomain();
    String mirroredDomain = null;
    if (domain.equals(legacyDomain)) {
        mirroredDomain = exprDomain;
    } else if (domain.equals(exprDomain)) {
        mirroredDomain = legacyDomain;
    }
    if (mirroredDomain == null) {
        return null;
    }
    try {
        return new ObjectName(mirroredDomain, name.getKeyPropertyList());
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: Server.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the domain data
 * @return The data iterator
 * @exception JMException Thrown if an error occurs
 */
public static Iterator getDomainData() throws JMException
{
   MBeanServer server = getMBeanServer();
   TreeMap<String, DomainData> domainData = new TreeMap<String, DomainData>();

   if (server != null)
   {
      Set objectNames = server.queryNames(null, null);
      Iterator objectNamesIter = objectNames.iterator();

      while (objectNamesIter.hasNext())
      {
         ObjectName name = (ObjectName)objectNamesIter.next();
         MBeanInfo info = server.getMBeanInfo(name);
         String domainName = name.getDomain();
         MBeanData mbeanData = new MBeanData(name, info);
         DomainData data = domainData.get(domainName);

         if (data == null)
         {
            data = new DomainData(domainName);
            domainData.put(domainName, data);
         }

         data.addData(mbeanData);
      }
   }

   return domainData.values().iterator();
}
 
Example 5
Source File: AbstractProtocol.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public ObjectName preRegister(MBeanServer server, ObjectName name)
        throws Exception {
    oname = name;
    mserver = server;
    domain = name.getDomain();
    return name;
}
 
Example 6
Source File: LifecycleMBeanBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Allows the object to be registered with an alternative
 * {@link MBeanServer} and/or {@link ObjectName}.
 */
@Override
public final ObjectName preRegister(MBeanServer server, ObjectName name)
        throws Exception {
    
    this.mserver = server;
    this.oname = name;
    this.domain = name.getDomain();

    return oname;
}
 
Example 7
Source File: DataSource.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the ObjectName for the ConnectionPoolMBean object to be registered
 * @param original the ObjectName for the DataSource
 * @return the ObjectName for the ConnectionPoolMBean
 * @throws MalformedObjectNameException
 */
public ObjectName createObjectName(ObjectName original) throws MalformedObjectNameException {
    String domain = ConnectionPool.POOL_JMX_DOMAIN;
    Hashtable<String,String> properties = original.getKeyPropertyList();
    String origDomain = original.getDomain();
    properties.put("type", "ConnectionPool");
    properties.put("class", this.getClass().getName());
    if (original.getKeyProperty("path")!=null || properties.get("context")!=null) {
        //this ensures that if the registration came from tomcat, we're not losing
        //the unique domain, but putting that into as an engine attribute
        properties.put("engine", origDomain);
    }
    ObjectName name = new ObjectName(domain,properties);
    return name;
}
 
Example 8
Source File: ModelControllerMBeanServerPlugin.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelControllerMBeanHelper getHelper(ObjectName name) {
    String domain = name.getDomain();
    if (domain.equals(configuredDomains.getLegacyDomain()) || name.isDomainPattern()) {
        return legacyHelper;
    }
    if (domain.equals(configuredDomains.getExprDomain())) {
        return exprHelper;
    }
    //This should not happen
    throw JmxLogger.ROOT_LOGGER.unknownDomain(domain);
}
 
Example 9
Source File: ObjectNameAddressUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Converts the ObjectName to a PathAddress.
 *
 * @param domainRoot the ObjectName used for mbean in the caller's JMX domain that represent the root management resource
 * @param rootResource the root resource for the management model
 * @param name the ObjectName to resolve
 *
 * @return the PathAddress if it exists in the model, {@code null} otherwise
 */
static PathAddress resolvePathAddress(final ObjectName domainRoot, final Resource rootResource, final ObjectName name) {
    String domain = domainRoot.getDomain();
    if (!name.getDomain().equals(domain)) {
        return null;
    }
    if (name.equals(domainRoot)) {
        return PathAddress.EMPTY_ADDRESS;
    }
    final Hashtable<String, String> properties = name.getKeyPropertyList();
    return searchPathAddress(PathAddress.EMPTY_ADDRESS, rootResource, properties);
}
 
Example 10
Source File: ServerNotifForwarder.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 11
Source File: ServerNotifForwarder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 12
Source File: ServerNotifForwarder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 13
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);
    
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
 
Example 14
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);
    
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
 
Example 15
Source File: ServerNotifForwarder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 16
Source File: ServerNotifForwarder.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 17
Source File: ServerNotifForwarder.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 18
Source File: ExpressionLanguageEngineImpl.java    From jmxtrans-agent with MIT License 4 votes vote down vote up
@Override
public String evaluate(@Nullable ObjectName objectName, @Nullable String attribute, @Nullable String compositeDataKey, @Nullable Integer position) {
    return objectName == null ? null : objectName.getDomain();
}
 
Example 19
Source File: ServerNotifForwarder.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}
 
Example 20
Source File: ServerNotifForwarder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Integer addNotificationListener(final ObjectName name,
    final NotificationFilter filter)
    throws InstanceNotFoundException, IOException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
            "Add a listener at " + name);
    }

    checkState();

    // Explicitly check MBeanPermission for addNotificationListener
    //
    checkMBeanPermission(name, "addNotificationListener");
    if (notificationAccessController != null) {
        notificationAccessController.addNotificationListener(
            connectionId, name, getSubject());
    }
    try {
        boolean instanceOf =
        AccessController.doPrivileged(
                new PrivilegedExceptionAction<Boolean>() {
                    public Boolean run() throws InstanceNotFoundException {
                        return mbeanServer.isInstanceOf(name, broadcasterClass);
                    }
        });
        if (!instanceOf) {
            throw new IllegalArgumentException("The specified MBean [" +
                name + "] is not a " +
                "NotificationBroadcaster " +
                "object.");
        }
    } catch (PrivilegedActionException e) {
        throw (InstanceNotFoundException) extractException(e);
    }

    final Integer id = getListenerID();

    // 6238731: set the default domain if no domain is set.
    ObjectName nn = name;
    if (name.getDomain() == null || name.getDomain().equals("")) {
        try {
            nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
                                        name.getKeyPropertyList());
        } catch (MalformedObjectNameException mfoe) {
            // impossible, but...
            IOException ioe = new IOException(mfoe.getMessage());
            ioe.initCause(mfoe);
            throw ioe;
        }
    }

    synchronized (listenerMap) {
        IdAndFilter idaf = new IdAndFilter(id, filter);
        Set<IdAndFilter> set = listenerMap.get(nn);
        // Tread carefully because if set.size() == 1 it may be the
        // Collections.singleton we make here, which is unmodifiable.
        if (set == null)
            set = Collections.singleton(idaf);
        else {
            if (set.size() == 1)
                set = new HashSet<IdAndFilter>(set);
            set.add(idaf);
        }
        listenerMap.put(nn, set);
    }

    return id;
}