Java Code Examples for javax.management.MalformedObjectNameException#getMessage()

The following examples show how to use javax.management.MalformedObjectNameException#getMessage() . 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: InstrumentationManagerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private ObjectName getDelegateName() throws JMException {
    try {
        return (ObjectName)MBeanServerDelegate.class.getField("DELEGATE_NAME").get(null);
    } catch (Throwable t) {
        //ignore, likely on Java5
    }
    try {
        return new ObjectName("JMImplementation:type=MBeanServerDelegate");
    } catch (MalformedObjectNameException e) {
        JMException jme = new JMException(e.getMessage());
        jme.initCause(e);
        throw jme;
    }
}
 
Example 2
Source File: JmxEtlManager.java    From scriptella-etl with Apache License 2.0 5 votes vote down vote up
/**
 * Find ETL mbeans.
 *
 * @return set of object names.
 */
public static Set<ObjectName> findEtlMBeans() {
    try {
        return getMBeanServer().queryNames(new ObjectName(MBEAN_NAME_PREFIX + ",*"), null);
    } catch (MalformedObjectNameException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 3
Source File: JmxFixture.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public boolean objectExists( String objName ) {
    try
    {
        ObjectName objectName = new ObjectName( prefix + objName );
        return server.isRegistered( objectName );
    }
    catch( MalformedObjectNameException ex )
    {
        throw new IllegalArgumentException( ex.getMessage(), ex );
    }
}
 
Example 4
Source File: MBeanDumper.java    From tda with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs a ThreadMonitor object to get thread information
 * in a remote JVM.
 */
public MBeanDumper(MBeanServerConnection server) throws IOException {
   setMBeanServerConnection(server);
   try {
       objname = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
    } catch (MalformedObjectNameException e) {
        // should not reach here
        InternalError ie = new InternalError(e.getMessage());
        ie.initCause(e);
        throw ie;
   }
   parseMBeanInfo(); 
}
 
Example 5
Source File: ServerNotifForwarder.java    From hottub 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 6
Source File: ServerNotifForwarder.java    From jdk8u-dev-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 7
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 8
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 9
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 10
Source File: ServerNotifForwarder.java    From openjdk-8-source 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 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 12
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 13
Source File: ServerNotifForwarder.java    From openjdk-jdk9 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 14
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 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 JDKSourceCode1.8 with MIT License 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: ServerNotifForwarder.java    From TencentKona-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 19
Source File: ServerNotifForwarder.java    From dragonwell8_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;
}