javax.management.remote.JMXConnectionNotification Java Examples

The following examples show how to use javax.management.remote.JMXConnectionNotification. 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: AgentImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  }
}
 
Example #2
Source File: AgentImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  }
}
 
Example #3
Source File: Application.java    From cassandra-exporter with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: NotifReconnectDeadlockTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
                    }
                }
            }
 
Example #5
Source File: RMIConnector.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #6
Source File: DiagEventSubscriptionService.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
@Override
public void handleNotification(Notification notification, Object handback) {
  // pass off the work immediately to a separate thread
  taskExecutor.submit(() -> {
    String threadName = Thread.currentThread().getName();
    try {
      Thread.currentThread().setName(node.getHostname());

      switch (notification.getType()) {
        case JMXConnectionNotification.CLOSED:
        case JMXConnectionNotification.FAILED:
          LOG.debug("JMX connection closed");
          if (onConnectionClosed != null) {
            onConnectionClosed.accept(notification);
          }
          break;

        case JMXConnectionNotification.NOTIFS_LOST:
          LOG.warn("Lost JMX notifications");
          break;

        case "event_last_id_summary":
          LOG.debug("Received event summary: {}", notification);
          if (onSummary != null) {
            onSummary.accept((Map<String, Comparable>) notification.getUserData());
          }
          break;

        default:
          break;
      }
    } catch (RuntimeException e) {
      LOG.error("Error while handling JMX notification", e);
    } finally {
      Thread.currentThread().setName(threadName);
    }
  });
}
 
Example #7
Source File: ConnectionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: MissingClassTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void handleNotification(Notification n, Object o) {
    if (n instanceof JMXConnectionNotification) {
        JMXConnectionNotification jn = (JMXConnectionNotification)n;
        if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
            failed = true;
        }
    }
}
 
Example #9
Source File: MissingClassTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example #10
Source File: MissingClassTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example #11
Source File: MissingClassTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example #12
Source File: RMIConnector.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);

}
 
Example #13
Source File: RMIConnector.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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);

}
 
Example #14
Source File: JMConnManager.java    From jmonitor with GNU General Public License v2.0 5 votes vote down vote up
@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));
    }
}
 
Example #15
Source File: JmxOperationInvoker.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@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());
      }
    }
  }
}
 
Example #16
Source File: RMIConnector.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);

}
 
Example #17
Source File: ConnectionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: MissingClassTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example #19
Source File: RMIConnector.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #20
Source File: NotifReconnectDeadlockTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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
                    }
                }
            }
 
Example #21
Source File: ConnectionTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #22
Source File: RMIConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #23
Source File: RMIConnector.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: MissingClassTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example #25
Source File: ConnectionTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #26
Source File: MissingClassTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example #27
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);

}
 
Example #28
Source File: RMIConnector.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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);

}
 
Example #29
Source File: RMIConnector.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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);
}
 
Example #30
Source File: NotifReconnectDeadlockTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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
                    }
                }
            }