类javax.management.remote.JMXConnectionNotification源码实例Demo

下面列出了怎么用javax.management.remote.JMXConnectionNotification的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: gemfirexd-oss   文件: AgentImpl.java
/**
 * If the handback object passed is an AgentImpl, updates the JMX client count
 *
 * @param notification
 *          JMXConnectionNotification for change in client connection status
 * @param handback
 *          An opaque object which helps the listener to associate information
 *          regarding the MBean emitter. This object is passed to the MBean
 *          during the addListener call and resent, without modification, to
 *          the listener. The MBean object should not use or modify the
 *          object. (NOTE: copied from javax.management.NotificationListener)
 */
@SuppressFBWarnings(value="BC_UNCONFIRMED_CAST", justification="Only JMXConnectionNotification instances are used.") 
public void handleNotification(Notification notification, Object handback) {
  if (handback instanceof AgentImpl) {
    AgentImpl agent = (AgentImpl) handback;

    JMXConnectionNotification jmxNotifn =
      (JMXConnectionNotification) notification;

    LogWriterI18n logWriter = agent.getLogWriterI18n();
    logWriter.fine("Connection notification for connection id : '" +
                              jmxNotifn.getConnectionId() + "'");

    agent.updateRmiClientsCount();
  }
}
 
源代码2 项目: cassandra-exporter   文件: Application.java
private MBeanServerConnection establishMBeanServerConnection() throws IOException {
    if (jmxUser != null ^ jmxPassword != null) {
        throw new ParameterException(commandSpec.commandLine(), "Both --jmx-user and --jmx-password are required when either is used.");
    }

    Map<String, String[]> jmxEnvironment = new HashMap<>();
    if (jmxUser != null && jmxPassword != null) {
        jmxEnvironment.put(JMXConnector.CREDENTIALS, new String[]{jmxUser, jmxPassword});
    }

    final JMXConnector connector = JMXConnectorFactory.connect(jmxServiceURL, jmxEnvironment);
    final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();

    connector.addConnectionNotificationListener((notification, handback) -> {
        if (notification.getType().equals(JMXConnectionNotification.CLOSED)) {
            logger.error("JMX connection to {} closed.", jmxServiceURL);

            Runtime.getRuntime().exit(-1);
        }
    }, null, null);

    return mBeanServerConnection;
}
 
源代码3 项目: gemfirexd-oss   文件: AgentImpl.java
/**
 * If the handback object passed is an AgentImpl, updates the JMX client count
 *
 * @param notification
 *          JMXConnectionNotification for change in client connection status
 * @param handback
 *          An opaque object which helps the listener to associate information
 *          regarding the MBean emitter. This object is passed to the MBean
 *          during the addListener call and resent, without modification, to
 *          the listener. The MBean object should not use or modify the
 *          object. (NOTE: copied from javax.management.NotificationListener)
 */
@SuppressFBWarnings(value="BC_UNCONFIRMED_CAST", justification="Only JMXConnectionNotification instances are used.") 
public void handleNotification(Notification notification, Object handback) {
  if (handback instanceof AgentImpl) {
    AgentImpl agent = (AgentImpl) handback;

    JMXConnectionNotification jmxNotifn =
      (JMXConnectionNotification) notification;

    LogWriterI18n logWriter = agent.getLogWriterI18n();
    logWriter.fine("Connection notification for connection id : '" +
                              jmxNotifn.getConnectionId() + "'");

    agent.updateRmiClientsCount();
  }
}
 
源代码4 项目: jdk1.8-source-analysis   文件: RMIConnector.java
protected void lostNotifs(String message, long number) {
    final String notifType = JMXConnectionNotification.NOTIFS_LOST;

    final JMXConnectionNotification n =
        new JMXConnectionNotification(notifType,
                                      RMIConnector.this,
                                      connectionId,
                                      clientNotifCounter++,
                                      message,
                                      Long.valueOf(number));
    sendNotification(n);
}
 
源代码5 项目: jdk1.8-source-analysis   文件: RMIConnector.java
protected void doStart() throws IOException {
    // Get RMIServer stub from directory or URL encoding if needed.
    RMIServer stub;
    try {
        stub = (rmiServer!=null)?rmiServer:
            findRMIServer(jmxServiceURL, env);
    } catch (NamingException ne) {
        throw new IOException("Failed to get a RMI stub: "+ne);
    }

    // Connect IIOP Stub if needed.
    stub = connectStub(stub,env);

    // Calling newClient on the RMIServer stub.
    Object credentials = env.get(CREDENTIALS);
    connection = stub.newClient(credentials);

    // notif issues
    final ClientListenerInfo[] old = rmiNotifClient.preReconnection();

    reconnectNotificationListeners(old);

    connectionId = getConnectionId();

    Notification reconnectedNotif =
            new JMXConnectionNotification(JMXConnectionNotification.OPENED,
            this,
            connectionId,
            clientNotifSeqNo++,
            "Reconnected to server",
            null);
    sendNotification(reconnectedNotif);

}
 
源代码6 项目: jdk8u-dev-jdk   文件: MissingClassTest.java
private void handle(Notification n, Object h) {
    if (!(n instanceof JMXConnectionNotification)) {
        System.out.println("LostListener received strange notif: " +
                           notificationString(n));
        result.failed = true;
        result.notifyAll();
        return;
    }

    JMXConnectionNotification jn = (JMXConnectionNotification) n;
    if (!jn.getType().equals(jn.NOTIFS_LOST)) {
        System.out.println("Ignoring JMXConnectionNotification: " +
                           notificationString(jn));
        return;
    }
    final String msg = jn.getMessage();
    if ((!msg.startsWith("Dropped ")
         || !msg.endsWith("classes were missing locally"))
        && (!msg.startsWith("Not serializable: "))) {
        System.out.println("Surprising NOTIFS_LOST getMessage: " +
                           msg);
    }
    if (!(jn.getUserData() instanceof Long)) {
        System.out.println("JMXConnectionNotification userData " +
                           "not a Long: " + jn.getUserData());
        result.failed = true;
    } else {
        int lost = ((Long) jn.getUserData()).intValue();
        result.lostCount += lost;
        if (result.lostCount == NNOTIFS*2)
            result.notifyAll();
    }
}
 
源代码7 项目: jdk8u-dev-jdk   文件: MissingClassTest.java
public void handleNotification(Notification n, Object h) {
    /* Connectors can handle unserializable notifications in
       one of two ways.  Either they can arrange for the
       client to get a NotSerializableException from its
       fetchNotifications call (RMI connector), or they can
       replace the unserializable notification by a
       JMXConnectionNotification.NOTIFS_LOST (JMXMP
       connector).  The former case is handled by code within
       the connector client which will end up sending a
       NOTIFS_LOST to our LostListener.  The logic here
       handles the latter case by converting it into the
       former.
     */
    if (n instanceof JMXConnectionNotification
        && n.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
        lostListener.handleNotification(n, h);
        return;
    }

    synchronized (result) {
        if (!n.getType().equals("interesting")
            || !n.getUserData().equals("known")) {
            System.out.println("TestListener received strange notif: "
                               + notificationString(n));
            result.failed = true;
            result.notifyAll();
        } else {
            result.knownCount++;
            if (result.knownCount == NNOTIFS)
                result.notifyAll();
        }
    }
}
 
源代码8 项目: jdk8u_jdk   文件: MissingClassTest.java
public void handleNotification(Notification n, Object o) {
    if (n instanceof JMXConnectionNotification) {
        JMXConnectionNotification jn = (JMXConnectionNotification)n;
        if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
            failed = true;
        }
    }
}
 
源代码9 项目: visualvm   文件: ProxyClient.java
public void handleNotification(Notification n, Object hb) {
    if (n instanceof JMXConnectionNotification) {
        if (JMXConnectionNotification.FAILED.equals(n.getType()) || JMXConnectionNotification.CLOSED.equals(n.getType())) {
            markAsDead();
        }
    }
}
 
源代码10 项目: hottub   文件: NotifReconnectDeadlockTest.java
public void handleNotification(Notification n, Object hb) {

                // treat the client notif to know the end
                if (n instanceof JMXConnectionNotification) {
                    if (!JMXConnectionNotification.NOTIFS_LOST.equals(n.getType())) {

                        clientState = n.getType();
                        System.out.println(
                           ">>> The client state has been changed to: "+clientState);

                        synchronized(lock) {
                            lock.notifyAll();
                        }
                    }

                    return;
                }

                System.out.println(">>> Do sleep to make reconnection.");
                synchronized(lock) {
                    try {
                        lock.wait(listenerSleep);
                    } catch (Exception e) {
                        // OK
                    }
                }
            }
 
源代码11 项目: openjdk-8-source   文件: RMIConnector.java
protected void lostNotifs(String message, long number) {
    final String notifType = JMXConnectionNotification.NOTIFS_LOST;

    final JMXConnectionNotification n =
        new JMXConnectionNotification(notifType,
                                      RMIConnector.this,
                                      connectionId,
                                      clientNotifCounter++,
                                      message,
                                      Long.valueOf(number));
    sendNotification(n);
}
 
源代码12 项目: dragonwell8_jdk   文件: MissingClassTest.java
public void handleNotification(Notification n, Object o) {
    if (n instanceof JMXConnectionNotification) {
        JMXConnectionNotification jn = (JMXConnectionNotification)n;
        if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
            failed = true;
        }
    }
}
 
源代码13 项目: openjdk-8-source   文件: MissingClassTest.java
public void handleNotification(Notification n, Object o) {
    if (n instanceof JMXConnectionNotification) {
        JMXConnectionNotification jn = (JMXConnectionNotification)n;
        if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
            failed = true;
        }
    }
}
 
源代码14 项目: gemfirexd-oss   文件: JmxOperationInvoker.java
@Override
public void handleNotification(Notification notification, Object handback) {
  if (JMXConnectionNotification.class.isInstance(notification)) {
    JMXConnectionNotification connNotif = (JMXConnectionNotification)notification;
    if (JMXConnectionNotification.CLOSED.equals(connNotif.getType()) ||
        JMXConnectionNotification.FAILED.equals(connNotif.getType())) {
      this.invoker.isConnected.set(false);
      this.invoker.resetClusterId();
      if (!this.invoker.isSelfDisconnect.get()) {
        Gfsh.getCurrentInstance().notifyDisconnect(this.invoker.toString());
      }
    }
  }
}
 
源代码15 项目: jdk8u-dev-jdk   文件: NotifReconnectDeadlockTest.java
public void handleNotification(Notification n, Object hb) {

                // treat the client notif to know the end
                if (n instanceof JMXConnectionNotification) {
                    if (!JMXConnectionNotification.NOTIFS_LOST.equals(n.getType())) {

                        clientState = n.getType();
                        System.out.println(
                           ">>> The client state has been changed to: "+clientState);

                        synchronized(lock) {
                            lock.notifyAll();
                        }
                    }

                    return;
                }

                System.out.println(">>> Do sleep to make reconnection.");
                synchronized(lock) {
                    try {
                        lock.wait(listenerSleep);
                    } catch (Exception e) {
                        // OK
                    }
                }
            }
 
源代码16 项目: TencentKona-8   文件: MissingClassTest.java
public void handleNotification(Notification n, Object h) {
    /* Connectors can handle unserializable notifications in
       one of two ways.  Either they can arrange for the
       client to get a NotSerializableException from its
       fetchNotifications call (RMI connector), or they can
       replace the unserializable notification by a
       JMXConnectionNotification.NOTIFS_LOST (JMXMP
       connector).  The former case is handled by code within
       the connector client which will end up sending a
       NOTIFS_LOST to our LostListener.  The logic here
       handles the latter case by converting it into the
       former.
     */
    if (n instanceof JMXConnectionNotification
        && n.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
        lostListener.handleNotification(n, h);
        return;
    }

    synchronized (result) {
        if (!n.getType().equals("interesting")
            || !n.getUserData().equals("known")) {
            System.out.println("TestListener received strange notif: "
                               + notificationString(n));
            result.failed = true;
            result.notifyAll();
        } else {
            result.knownCount++;
            if (result.knownCount == NNOTIFS)
                result.notifyAll();
        }
    }
}
 
源代码17 项目: TencentKona-8   文件: MissingClassTest.java
private void handle(Notification n, Object h) {
    if (!(n instanceof JMXConnectionNotification)) {
        System.out.println("LostListener received strange notif: " +
                           notificationString(n));
        result.failed = true;
        result.notifyAll();
        return;
    }

    JMXConnectionNotification jn = (JMXConnectionNotification) n;
    if (!jn.getType().equals(jn.NOTIFS_LOST)) {
        System.out.println("Ignoring JMXConnectionNotification: " +
                           notificationString(jn));
        return;
    }
    final String msg = jn.getMessage();
    if ((!msg.startsWith("Dropped ")
         || !msg.endsWith("classes were missing locally"))
        && (!msg.startsWith("Not serializable: "))) {
        System.out.println("Surprising NOTIFS_LOST getMessage: " +
                           msg);
    }
    if (!(jn.getUserData() instanceof Long)) {
        System.out.println("JMXConnectionNotification userData " +
                           "not a Long: " + jn.getUserData());
        result.failed = true;
    } else {
        int lost = ((Long) jn.getUserData()).intValue();
        result.lostCount += lost;
        if (result.lostCount == NNOTIFS*2)
            result.notifyAll();
    }
}
 
源代码18 项目: TencentKona-8   文件: MissingClassTest.java
public void handleNotification(Notification n, Object o) {
    if (n instanceof JMXConnectionNotification) {
        JMXConnectionNotification jn = (JMXConnectionNotification)n;
        if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
            failed = true;
        }
    }
}
 
源代码19 项目: TencentKona-8   文件: ConnectionTest.java
private static boolean
    mustBeConnectionNotification(Notification notif,
                                 String requiredConnId,
                                 String requiredType) {

    if (!(notif instanceof JMXConnectionNotification)) {
        System.out.println("Should have been a " +
                           "JMXConnectionNotification: " +
                           notif.getClass());
        return false;
    }

    JMXConnectionNotification cnotif = (JMXConnectionNotification) notif;
    if (!cnotif.getType().equals(requiredType)) {
        System.out.println("Wrong type notif: is \"" + cnotif.getType() +
                           "\", should be \"" + requiredType + "\"");
        return false;
    }

    if (!cnotif.getConnectionId().equals(requiredConnId)) {
        System.out.println("Wrong connection id: is \"" +
                           cnotif.getConnectionId() + "\", should be \"" +
                           requiredConnId);
        return false;
    }

    return true;
}
 
源代码20 项目: openjdk-8-source   文件: MissingClassTest.java
public void handleNotification(Notification n, Object h) {
    /* Connectors can handle unserializable notifications in
       one of two ways.  Either they can arrange for the
       client to get a NotSerializableException from its
       fetchNotifications call (RMI connector), or they can
       replace the unserializable notification by a
       JMXConnectionNotification.NOTIFS_LOST (JMXMP
       connector).  The former case is handled by code within
       the connector client which will end up sending a
       NOTIFS_LOST to our LostListener.  The logic here
       handles the latter case by converting it into the
       former.
     */
    if (n instanceof JMXConnectionNotification
        && n.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
        lostListener.handleNotification(n, h);
        return;
    }

    synchronized (result) {
        if (!n.getType().equals("interesting")
            || !n.getUserData().equals("known")) {
            System.out.println("TestListener received strange notif: "
                               + notificationString(n));
            result.failed = true;
            result.notifyAll();
        } else {
            result.knownCount++;
            if (result.knownCount == NNOTIFS)
                result.notifyAll();
        }
    }
}
 
源代码21 项目: gemfirexd-oss   文件: AgentImpl.java
/**
 * Invoked before sending the specified notification to the listener.
 * Returns whether the given notification is to be sent to the listener.
 *
 * @param notification
 *          The notification to be sent.
 * @return true if the notification has to be sent to the listener, false
 *         otherwise.
 */
public boolean isNotificationEnabled(Notification notification) {
  boolean isThisNotificationEnabled = false;
  if (notification.getType().equals(JMXConnectionNotification.OPENED) ||
      notification.getType().equals(JMXConnectionNotification.CLOSED) ||
      notification.getType().equals(JMXConnectionNotification.FAILED) ) {
    isThisNotificationEnabled = true;
  }
  return isThisNotificationEnabled;
}
 
源代码22 项目: Java8CN   文件: RMIConnector.java
protected void doStart() throws IOException {
    // Get RMIServer stub from directory or URL encoding if needed.
    RMIServer stub;
    try {
        stub = (rmiServer!=null)?rmiServer:
            findRMIServer(jmxServiceURL, env);
    } catch (NamingException ne) {
        throw new IOException("Failed to get a RMI stub: "+ne);
    }

    // Connect IIOP Stub if needed.
    stub = connectStub(stub,env);

    // Calling newClient on the RMIServer stub.
    Object credentials = env.get(CREDENTIALS);
    connection = stub.newClient(credentials);

    // notif issues
    final ClientListenerInfo[] old = rmiNotifClient.preReconnection();

    reconnectNotificationListeners(old);

    connectionId = getConnectionId();

    Notification reconnectedNotif =
            new JMXConnectionNotification(JMXConnectionNotification.OPENED,
            this,
            connectionId,
            clientNotifSeqNo++,
            "Reconnected to server",
            null);
    sendNotification(reconnectedNotif);

}
 
源代码23 项目: jdk8u60   文件: RMIConnector.java
protected void doStart() throws IOException {
    // Get RMIServer stub from directory or URL encoding if needed.
    RMIServer stub;
    try {
        stub = (rmiServer!=null)?rmiServer:
            findRMIServer(jmxServiceURL, env);
    } catch (NamingException ne) {
        throw new IOException("Failed to get a RMI stub: "+ne);
    }

    // Connect IIOP Stub if needed.
    stub = connectStub(stub,env);

    // Calling newClient on the RMIServer stub.
    Object credentials = env.get(CREDENTIALS);
    connection = stub.newClient(credentials);

    // notif issues
    final ClientListenerInfo[] old = rmiNotifClient.preReconnection();

    reconnectNotificationListeners(old);

    connectionId = getConnectionId();

    Notification reconnectedNotif =
            new JMXConnectionNotification(JMXConnectionNotification.OPENED,
            this,
            connectionId,
            clientNotifSeqNo++,
            "Reconnected to server",
            null);
    sendNotification(reconnectedNotif);

}
 
源代码24 项目: jdk8u60   文件: MissingClassTest.java
public void handleNotification(Notification n, Object h) {
    /* Connectors can handle unserializable notifications in
       one of two ways.  Either they can arrange for the
       client to get a NotSerializableException from its
       fetchNotifications call (RMI connector), or they can
       replace the unserializable notification by a
       JMXConnectionNotification.NOTIFS_LOST (JMXMP
       connector).  The former case is handled by code within
       the connector client which will end up sending a
       NOTIFS_LOST to our LostListener.  The logic here
       handles the latter case by converting it into the
       former.
     */
    if (n instanceof JMXConnectionNotification
        && n.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
        lostListener.handleNotification(n, h);
        return;
    }

    synchronized (result) {
        if (!n.getType().equals("interesting")
            || !n.getUserData().equals("known")) {
            System.out.println("TestListener received strange notif: "
                               + notificationString(n));
            result.failed = true;
            result.notifyAll();
        } else {
            result.knownCount++;
            if (result.knownCount == NNOTIFS)
                result.notifyAll();
        }
    }
}
 
源代码25 项目: jdk8u60   文件: MissingClassTest.java
private void handle(Notification n, Object h) {
    if (!(n instanceof JMXConnectionNotification)) {
        System.out.println("LostListener received strange notif: " +
                           notificationString(n));
        result.failed = true;
        result.notifyAll();
        return;
    }

    JMXConnectionNotification jn = (JMXConnectionNotification) n;
    if (!jn.getType().equals(jn.NOTIFS_LOST)) {
        System.out.println("Ignoring JMXConnectionNotification: " +
                           notificationString(jn));
        return;
    }
    final String msg = jn.getMessage();
    if ((!msg.startsWith("Dropped ")
         || !msg.endsWith("classes were missing locally"))
        && (!msg.startsWith("Not serializable: "))) {
        System.out.println("Surprising NOTIFS_LOST getMessage: " +
                           msg);
    }
    if (!(jn.getUserData() instanceof Long)) {
        System.out.println("JMXConnectionNotification userData " +
                           "not a Long: " + jn.getUserData());
        result.failed = true;
    } else {
        int lost = ((Long) jn.getUserData()).intValue();
        result.lostCount += lost;
        if (result.lostCount == NNOTIFS*2)
            result.notifyAll();
    }
}
 
源代码26 项目: jdk8u60   文件: MissingClassTest.java
public void handleNotification(Notification n, Object o) {
    if (n instanceof JMXConnectionNotification) {
        JMXConnectionNotification jn = (JMXConnectionNotification)n;
        if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
            failed = true;
        }
    }
}
 
public void handleNotification(Notification n, Object hb) {

                // treat the client notif to know the end
                if (n instanceof JMXConnectionNotification) {
                    if (!JMXConnectionNotification.NOTIFS_LOST.equals(n.getType())) {

                        clientState = n.getType();
                        System.out.println(
                           ">>> The client state has been changed to: "+clientState);

                        synchronized(lock) {
                            lock.notifyAll();
                        }
                    }

                    return;
                }

                System.out.println(">>> Do sleep to make reconnection.");
                synchronized(lock) {
                    try {
                        lock.wait(listenerSleep);
                    } catch (Exception e) {
                        // OK
                    }
                }
            }
 
源代码28 项目: JDKSourceCode1.8   文件: RMIConnector.java
protected void lostNotifs(String message, long number) {
    final String notifType = JMXConnectionNotification.NOTIFS_LOST;

    final JMXConnectionNotification n =
        new JMXConnectionNotification(notifType,
                                      RMIConnector.this,
                                      connectionId,
                                      clientNotifCounter++,
                                      message,
                                      Long.valueOf(number));
    sendNotification(n);
}
 
源代码29 项目: JDKSourceCode1.8   文件: RMIConnector.java
protected void doStart() throws IOException {
    // Get RMIServer stub from directory or URL encoding if needed.
    RMIServer stub;
    try {
        stub = (rmiServer!=null)?rmiServer:
            findRMIServer(jmxServiceURL, env);
    } catch (NamingException ne) {
        throw new IOException("Failed to get a RMI stub: "+ne);
    }

    // Connect IIOP Stub if needed.
    stub = connectStub(stub,env);

    // Calling newClient on the RMIServer stub.
    Object credentials = env.get(CREDENTIALS);
    connection = stub.newClient(credentials);

    // notif issues
    final ClientListenerInfo[] old = rmiNotifClient.preReconnection();

    reconnectNotificationListeners(old);

    connectionId = getConnectionId();

    Notification reconnectedNotif =
            new JMXConnectionNotification(JMXConnectionNotification.OPENED,
            this,
            connectionId,
            clientNotifSeqNo++,
            "Reconnected to server",
            null);
    sendNotification(reconnectedNotif);

}
 
源代码30 项目: jmonitor   文件: JMConnManager.java
@Override
public void handleNotification(Notification notification, Object handback) {
    JMXConnectionNotification noti = (JMXConnectionNotification) notification;
    if (noti.getType().equals(JMXConnectionNotification.CLOSED)) {
        disconnect(String.valueOf(handback));
    } else if (noti.getType().equals(JMXConnectionNotification.FAILED)) {
        disconnect(String.valueOf(handback));
    } else if (noti.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
        disconnect(String.valueOf(handback));
    }
}
 
 类所在包
 同包方法