Search in sources :

Example 61 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class RMIConnector method connect.

/**
     * @throws IOException if the connection could not be made because of a
     *   communication problem, or in the case of the {@code iiop} protocol,
     *   that RMI/IIOP is not supported
     */
public synchronized void connect(Map<String, ?> environment) throws IOException {
    final boolean tracing = logger.traceOn();
    String idstr = (tracing ? "[" + this.toString() + "]" : null);
    if (terminated) {
        logger.trace("connect", idstr + " already closed.");
        throw new IOException("Connector closed");
    }
    if (connected) {
        logger.trace("connect", idstr + " already connected.");
        return;
    }
    try {
        if (tracing)
            logger.trace("connect", idstr + " connecting...");
        final Map<String, Object> usemap = new HashMap<String, Object>((this.env == null) ? Collections.<String, Object>emptyMap() : this.env);
        if (environment != null) {
            EnvHelp.checkAttributes(environment);
            usemap.putAll(environment);
        }
        // Get RMIServer stub from directory or URL encoding if needed.
        if (tracing)
            logger.trace("connect", idstr + " finding stub...");
        RMIServer stub = (rmiServer != null) ? rmiServer : findRMIServer(jmxServiceURL, usemap);
        // Check for secure RMIServer stub if the corresponding
        // client-side environment property is set to "true".
        //
        String stringBoolean = (String) usemap.get("jmx.remote.x.check.stub");
        boolean checkStub = EnvHelp.computeBooleanFromString(stringBoolean);
        if (checkStub)
            checkStub(stub, rmiServerImplStubClass);
        // Connect IIOP Stub if needed.
        if (tracing)
            logger.trace("connect", idstr + " connecting stub...");
        stub = connectStub(stub, usemap);
        idstr = (tracing ? "[" + this.toString() + "]" : null);
        // Calling newClient on the RMIServer stub.
        if (tracing)
            logger.trace("connect", idstr + " getting connection...");
        Object credentials = usemap.get(CREDENTIALS);
        try {
            connection = getConnection(stub, credentials, checkStub);
        } catch (java.rmi.RemoteException re) {
            if (jmxServiceURL != null) {
                final String pro = jmxServiceURL.getProtocol();
                final String path = jmxServiceURL.getURLPath();
                if ("rmi".equals(pro) && path.startsWith("/jndi/iiop:")) {
                    MalformedURLException mfe = new MalformedURLException("Protocol is rmi but JNDI scheme is iiop: " + jmxServiceURL);
                    mfe.initCause(re);
                    throw mfe;
                }
            }
            throw re;
        }
        //   or contextClassLoader at connect time.
        if (tracing)
            logger.trace("connect", idstr + " getting class loader...");
        defaultClassLoader = EnvHelp.resolveClientClassLoader(usemap);
        usemap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, defaultClassLoader);
        rmiNotifClient = new RMINotifClient(defaultClassLoader, usemap);
        env = usemap;
        final long checkPeriod = EnvHelp.getConnectionCheckPeriod(usemap);
        communicatorAdmin = new RMIClientCommunicatorAdmin(checkPeriod);
        connected = true;
        // The connectionId variable is used in doStart(), when
        // reconnecting, to identify the "old" connection.
        //
        connectionId = getConnectionId();
        Notification connectedNotif = new JMXConnectionNotification(JMXConnectionNotification.OPENED, this, connectionId, clientNotifSeqNo++, "Successful connection", null);
        sendNotification(connectedNotif);
        if (tracing)
            logger.trace("connect", idstr + " done...");
    } catch (IOException e) {
        if (tracing)
            logger.trace("connect", idstr + " failed to connect: " + e);
        throw e;
    } catch (RuntimeException e) {
        if (tracing)
            logger.trace("connect", idstr + " failed to connect: " + e);
        throw e;
    } catch (NamingException e) {
        final String msg = "Failed to retrieve RMIServer stub: " + e;
        if (tracing)
            logger.trace("connect", idstr + " " + msg);
        throw EnvHelp.initCause(new IOException(msg), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) IOException(java.io.IOException) JMXConnectionNotification(javax.management.remote.JMXConnectionNotification) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) MarshalledObject(java.rmi.MarshalledObject) RemoteObject(java.rmi.server.RemoteObject) NamingException(javax.naming.NamingException) JMXConnectionNotification(javax.management.remote.JMXConnectionNotification)

Example 62 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class ServerNotifForwarder method snoopOnUnregister.

// The standard RMI connector client will register a listener on the MBeanServerDelegate
// in order to be told when MBeans are unregistered.  We snoop on fetched notifications
// so that we can know too, and remove the corresponding entry from the listenerMap.
// See 6957378.
private void snoopOnUnregister(NotificationResult nr) {
    List<IdAndFilter> copy = null;
    synchronized (listenerMap) {
        Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
        if (delegateSet == null || delegateSet.isEmpty()) {
            return;
        }
        copy = new ArrayList<>(delegateSet);
    }
    for (TargetedNotification tn : nr.getTargetedNotifications()) {
        Integer id = tn.getListenerID();
        for (IdAndFilter idaf : copy) {
            if (idaf.id == id) {
                // This is a notification from the MBeanServerDelegate.
                Notification n = tn.getNotification();
                if (n instanceof MBeanServerNotification && n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
                    MBeanServerNotification mbsn = (MBeanServerNotification) n;
                    ObjectName gone = mbsn.getMBeanName();
                    synchronized (listenerMap) {
                        listenerMap.remove(gone);
                    }
                }
            }
        }
    }
}
Also used : MBeanServerNotification(javax.management.MBeanServerNotification) TargetedNotification(javax.management.remote.TargetedNotification) TargetedNotification(javax.management.remote.TargetedNotification) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) ObjectName(javax.management.ObjectName)

Example 63 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class GarbageCollectorImpl method createGCNotification.

void createGCNotification(long timestamp, String gcName, String gcAction, String gcCause, GcInfo gcInfo) {
    if (!hasListeners()) {
        return;
    }
    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION, getObjectName(), getNextSeqNumber(), timestamp, gcName);
    GarbageCollectionNotificationInfo info = new GarbageCollectionNotificationInfo(gcName, gcAction, gcCause, gcInfo);
    CompositeData cd = GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
Also used : GarbageCollectionNotificationInfo(com.sun.management.GarbageCollectionNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) Notification(javax.management.Notification)

Example 64 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class MemoryImpl method createNotification.

static void createNotification(String notifType, String poolName, MemoryUsage usage, long count) {
    MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
    if (!mbean.hasListeners()) {
        // if no listener is registered.
        return;
    }
    long timestamp = System.currentTimeMillis();
    String msg = getNotifMsg(notifType);
    Notification notif = new Notification(notifType, mbean.getObjectName(), getNextSeqNumber(), timestamp, msg);
    MemoryNotificationInfo info = new MemoryNotificationInfo(poolName, usage, count);
    CompositeData cd = MemoryNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    mbean.sendNotification(notif);
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) Notification(javax.management.Notification)

Example 65 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class ResultLogManager method clearMemoryLog.

// Clear the memory log, sends a notification indicating that
// the memory log was cleared.
//
private void clearMemoryLog() throws IOException {
    synchronized (this) {
        memoryLog.clear();
        memCapacityReached = false;
    }
    sendNotification(new Notification(MEMORY_LOG_CLEARED, objectName, getNextSeqNumber(), "memory log cleared"));
}
Also used : Notification(javax.management.Notification)

Aggregations

Notification (javax.management.Notification)134 ObjectName (javax.management.ObjectName)47 NotificationListener (javax.management.NotificationListener)30 AttributeChangeNotification (javax.management.AttributeChangeNotification)22 HashMap (java.util.HashMap)16 MBeanServer (javax.management.MBeanServer)15 JMXConnector (javax.management.remote.JMXConnector)14 JMXServiceURL (javax.management.remote.JMXServiceURL)14 NotificationFilter (javax.management.NotificationFilter)13 MBeanServerConnection (javax.management.MBeanServerConnection)12 JMXConnectorServer (javax.management.remote.JMXConnectorServer)11 Test (org.junit.Test)11 IOException (java.io.IOException)10 MBeanServerNotification (javax.management.MBeanServerNotification)9 ArrayList (java.util.ArrayList)8 Attribute (javax.management.Attribute)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)7 CompositeData (javax.management.openmbean.CompositeData)7 JMXConnectionNotification (javax.management.remote.JMXConnectionNotification)7 MalformedURLException (java.net.MalformedURLException)6