## mx4j.tools.remote
Class AbstractConnectionManager

    java.lang.Object
      mx4j.tools.remote.AbstractConnectionManager

All Implemented Interfaces:
  ConnectionManager

Direct Known Subclasses:
  HTTPConnectionManager

public abstract class AbstractConnectionManager
extends java.lang.Object
implements ConnectionManager

Implementation of the ConnectionManager interface that implements emission of connection notifications, authentication, and proper closing of connections.

Version:
  $Revision: 1.8 $

Constructor Summary
`protected` `AbstractConnectionManager(AbstractJMXConnectorServer server, java.util.Map environment)` Called by subclasses.

Method Summary
`protected javax.security.auth.Subject` `authenticate(java.lang.Object credentials)` Authenticates a Subject with the given credentials, by looking up a JMXAuthenticator in the environment returned by `getEnvironment()`.
`void` `close()` Implemented using the template method pattern
`void` `closeConnection(Connection connection)` Implemented using the template method pattern, handles the emission of the connection notification of type "closed".
`Connection` `connect(java.lang.Object credentials)` Implemented using the template method pattern, it handles authentication, creation of the connection ID, emission of connection notification of type "opened".
`protected java.lang.String` `createConnectionID(javax.security.auth.Subject subject)` Returns a connection ID as specified by JSR 160.
`protected abstract void` `doClose()` Closes this ConnectionManager but not the connections it manages
`protected abstract void` `doCloseConnection(Connection connection)` Closes the given Connection.
`protected abstract Connection` `doConnect(java.lang.String connectionId, javax.security.auth.Subject subject)` Template method to be implemented by subclasses; must return the server-side part of a connection.
`protected java.util.Map` `getEnvironment()` Returns the environment passed when creating the JMXConnectorServer
`protected java.security.AccessControlContext` `getSecurityContext()` Returns a security context at the moment of creation of this ConnectionManager.
`protected boolean` `isClosed()` Returns whether the `close()` method has been called.
`protected void` `setJMXConnectorServer(AbstractJMXConnectorServer server)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface mx4j.tools.remote.ConnectionManager
`getProtocol`

Constructor Detail

### AbstractConnectionManager

    protected AbstractConnectionManager(AbstractJMXConnectorServer server,
                                        java.util.Map environment)

  Called by subclasses.

Parameters:
  `server` - The JMXConnectorServer that will emit connection notifications
  `environment` - The environment passed when the JMXConnectorServer is created.

Method Detail

### setJMXConnectorServer

    protected void setJMXConnectorServer(AbstractJMXConnectorServer server)

### connect

    public Connection connect(java.lang.Object credentials)
                       throws java.io.IOException,
                              java.lang.SecurityException

  Implemented using the template method pattern, it handles authentication, creation of the connection ID, emission of connection notification of type "opened".

  Specified by:
    `connect` in interface `ConnectionManager`
  Parameters:
    `credentials` - The credentials sent by the client to authenticate a subject.
  Returns:
    A new client-specific connection.
  Throws:
    `java.lang.SecurityException` - If the authentication fails.
    `java.io.IOException` - If the connection cannot be created.
  See Also:
    `doConnect(java.lang.String, javax.security.auth.Subject)`, `authenticate(java.lang.Object)`, `createConnectionID(javax.security.auth.Subject)`

### createConnectionID

    protected java.lang.String createConnectionID(javax.security.auth.Subject subject)

  Returns a connection ID as specified by JSR 160.

  Parameters:
    `subject` - The authenticated Subject

### doConnect

    protected abstract Connection doConnect(java.lang.String connectionId,
                                            javax.security.auth.Subject subject)
                                     throws java.io.IOException

  Template method to be implemented by subclasses; must return the server-side part of a connection. When an remote invocation arrives, it will lookup the corrispondent server-side part of the connection and delegate the call to it. The server-side part of the connection must then (eventually) call the MBeanServer to satisfy the request.

  Parameters:
    `connectionId` - The connection ID for connection that is returned
    `subject` - The authenticated Subject
  Returns:
    The server-side part of a connection (with the given connection ID)
  Throws:
    `java.io.IOException` - If the connection cannot be created

### close

    public void close()
               throws java.io.IOException

  Implemented using the template method pattern

  Specified by:
    `close` in interface `ConnectionManager`
  Throws:
    `java.io.IOException`
  See Also:
    `doClose()`, `closeConnection(mx4j.tools.remote.Connection)`

### doClose

    protected abstract void doClose()
                             throws java.io.IOException

  Closes this ConnectionManager but not the connections it manages

  Throws:
    `java.io.IOException` - If this ConnectionManager cannot be closed

### closeConnection

    public void closeConnection(Connection connection)
                         throws java.io.IOException

  Implemented using the template method pattern, handles the emission of the connection notification of type "closed". This method is called both when closing the connector server and when closing a connector.

  Specified by:
    `closeConnection` in interface `ConnectionManager`
  Throws:
    `java.io.IOException`
  See Also:
    `doCloseConnection(mx4j.tools.remote.Connection)`

### doCloseConnection

    protected abstract void doCloseConnection(Connection connection)
                                       throws java.io.IOException

  Closes the given Connection.

  Throws:
    `java.io.IOException`

### isClosed

    protected boolean isClosed()

  Returns whether the `close()` method has been called.

### getEnvironment

    protected java.util.Map getEnvironment()

  Returns the environment passed when creating the JMXConnectorServer

### getSecurityContext

    protected java.security.AccessControlContext getSecurityContext()

  Returns a security context at the moment of creation of this ConnectionManager. This security context is the restricting context that should be used when a call from a remote client is invoked in a doPrivileged() block.

### authenticate

    protected javax.security.auth.Subject authenticate(java.lang.Object credentials)
                                                throws java.io.IOException,
                                                       java.lang.SecurityException

  Authenticates a Subject with the given credentials, by looking up a JMXAuthenticator in the environment returned by `getEnvironment()`.

  Throws:
    `java.io.IOException`
    `java.lang.SecurityException`

Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.