public void close() throws IOException {
    synchronized (this) {
      if (closed) return;
      connected = false;
      closed = true;

      if (notificationHandler != null) notificationHandler.stop();
      if (heartbeat != null) heartbeat.stop();
      if (connection != null) connection.close();

      connection = null;
      rmiServer = null;
    }

    emitter.sendConnectionNotificationClosed();
  }
  public void connect(Map environment) throws IOException, SecurityException {
    synchronized (this) {
      if (connected) return;
      if (closed) throw new IOException("This RMIConnector has already been closed");

      // Spec says, about default ClassLoader, to look here:
      // 1. Environment at connect(); if null,
      // 2. Environment at creation; if null,
      // 3. Context classloader at connect().
      ClassLoader loader = findDefaultClassLoader(environment);
      if (loader != null) defaultClassLoader = loader;
      else if (defaultClassLoader == null)
        defaultClassLoader = Thread.currentThread().getContextClassLoader();

      Map env = environment == null ? new HashMap() : environment;

      String protocol = jmxServiceURL.getProtocol();
      ConnectionResolver resolver = ConnectionResolver.newConnectionResolver(protocol, env);
      if (resolver == null) throw new IOException("Unsupported protocol: " + protocol);
      if (rmiServer == null) rmiServer = (RMIServer) resolver.lookupClient(jmxServiceURL, env);
      rmiServer = (RMIServer) resolver.bindClient(rmiServer, env);

      Object credentials = env.get(CREDENTIALS);
      this.connection = rmiServer.newClient(credentials);

      connected = true;
      this.connectionId = connection.getConnectionId();

      this.heartbeat = new RMIHeartBeat(connection, emitter, env);
      this.notificationHandler =
          new RMIRemoteNotificationClientHandler(
              connection, defaultClassLoader, emitter, heartbeat, env);

      this.heartbeat.start();
      this.notificationHandler.start();
    }

    emitter.sendConnectionNotificationOpened();
  }
 public void removeConnectionNotificationListener(
     NotificationListener listener, NotificationFilter filter, Object handback)
     throws ListenerNotFoundException {
   emitter.removeNotificationListener(listener, filter, handback);
 }
 public void removeConnectionNotificationListener(NotificationListener listener)
     throws ListenerNotFoundException {
   emitter.removeNotificationListener(listener);
 }
 public void addConnectionNotificationListener(
     NotificationListener listener, NotificationFilter filter, Object handback) {
   emitter.addNotificationListener(listener, filter, handback);
 }