org.exolab.jms.net.multiplexer
Class MultiplexedManagedConnection

java.lang.Object
  |
  +--org.exolab.jms.net.connector.AbstractManagedConnection
        |
        +--org.exolab.jms.net.multiplexer.MultiplexedManagedConnection
All Implemented Interfaces:
ManagedConnection, MultiplexerListener
Direct Known Subclasses:
SocketManagedConnection

public abstract class MultiplexedManagedConnection
extends AbstractManagedConnection
implements MultiplexerListener

A ManagedConnection that uses a Multiplexer to multiplex data over an Endpoint

Version:
$Revision: 1.10 $ $Date: 2006/12/16 12:37:17 $
Author:
Tim Anderson

Constructor Summary
MultiplexedManagedConnection(Authenticator authenticator)
          Construct a new server MultiplexedManagedConnection.
MultiplexedManagedConnection(java.security.Principal principal)
          Construct a new client MultiplexedManagedConnection.
 
Method Summary
 void closed()
          Invoked when the connection is closed by the peer.
protected abstract  Endpoint createEndpoint()
          Creates the endpoint to multiplex data over.
protected  Multiplexer createMultiplexer(Endpoint endpoint, Authenticator authenticator)
          Create a new server-side multiplexer.
protected  Multiplexer createMultiplexer(Endpoint endpoint, java.security.Principal principal)
          Create a new client-side multiplexer.
 void destroy()
          Destroys the physical connection.
 void error(java.lang.Throwable error)
          Invoked when an error occurs on the multiplexer.
protected  Caller getCaller()
          Helper to return an Caller instance, denoting the client performing a method invocation.
 Connection getConnection()
          Creates a new connection handle for the underlying physical connection.
protected  java.lang.String getDisplayName()
          Helper to generate a descriptive name, for display purposes.
 java.security.Principal getPrincipal()
          Returns the principal associated with this connection.
protected  java.lang.ThreadGroup getThreadGroup()
          Returns the thread group to associate with allocated threads.
 boolean hasPrincipal(java.security.Principal principal)
          Determines if the security principal that owns this connection is the same as that supplied.
protected  Response invoke(Connection connection, Request request)
          Invoke a method on a remote object.
protected  boolean isClient()
          Helper to determine if this is a client-side or server side instance.
 void ping()
          Ping the connection.
 void pinged(int token)
          Notifies of a successful ping.
 void request(org.exolab.jms.net.multiplexer.Channel channel)
          Invoked for an invocation request.
 void setInvocationHandler(InvocationHandler handler)
          Registers a handler for handling invocations on objects exported via this connection.
 
Methods inherited from class org.exolab.jms.net.connector.AbstractManagedConnection
getConnectionEventListener, notifyClosed, notifyError, setConnectionEventListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.exolab.jms.net.connector.ManagedConnection
getLocalURI, getRemoteURI
 

Constructor Detail

MultiplexedManagedConnection

public MultiplexedManagedConnection(java.security.Principal principal)
Construct a new client MultiplexedManagedConnection.
Parameters:
principal - the security principal. May be null

MultiplexedManagedConnection

public MultiplexedManagedConnection(Authenticator authenticator)
Construct a new server MultiplexedManagedConnection.
Parameters:
authenticator - the connection authenticator
Method Detail

setInvocationHandler

public void setInvocationHandler(InvocationHandler handler)
                          throws ResourceException
Registers a handler for handling invocations on objects exported via this connection. Once a handler is registered, it cannot be de-registered.
Parameters:
handler - the invocation handler
Throws:
IllegalStateException - if a handler is already registered
ResourceException - for any error

getConnection

public Connection getConnection()
                         throws IllegalStateException
Creates a new connection handle for the underlying physical connection.
Returns:
a new connection handle
Throws:
IllegalStateException - if an invocation handler hasn't been registered

ping

public void ping()
          throws ResourceException
Ping the connection. The connection event listener will be notified if the ping succeeds.
Throws:
IllegalStateException - if a connection is not established
ResourceException - for any error

destroy

public void destroy()
             throws ResourceException
Destroys the physical connection.
Throws:
ResourceException - for any error

getPrincipal

public java.security.Principal getPrincipal()
Returns the principal associated with this connection.
Returns:
the principal associated with this connection, or null if none is set

hasPrincipal

public boolean hasPrincipal(java.security.Principal principal)
Determines if the security principal that owns this connection is the same as that supplied.

NOTE: If this is a server-side instance, the principal is only available once the connection has been established, by setInvocationHandler(org.exolab.jms.net.connector.InvocationHandler)

Parameters:
principal - the principal to compare. May be null.
Returns:
true if the principal that owns this connection is the same as principal

request

public void request(org.exolab.jms.net.multiplexer.Channel channel)
Invoked for an invocation request.
Specified by:
request in interface MultiplexerListener
Parameters:
channel - the channel the invocation is on

closed

public void closed()
Invoked when the connection is closed by the peer.
Specified by:
closed in interface MultiplexerListener

error

public void error(java.lang.Throwable error)
Invoked when an error occurs on the multiplexer.
Specified by:
error in interface MultiplexerListener
Parameters:
error - the error

pinged

public void pinged(int token)
Notifies of a successful ping.
Specified by:
pinged in interface MultiplexerListener
Parameters:
token - the token sent in the ping

invoke

protected Response invoke(Connection connection,
                          Request request)
Invoke a method on a remote object.
Parameters:
connection - the connection invoking the request
request - the request
Returns:
the response

createEndpoint

protected abstract Endpoint createEndpoint()
                                    throws java.io.IOException
Creates the endpoint to multiplex data over.
Returns:
the endpoint to multiplex data over
Throws:
java.io.IOException - for any I/O error

createMultiplexer

protected Multiplexer createMultiplexer(Endpoint endpoint,
                                        java.security.Principal principal)
                                 throws java.io.IOException,
                                        SecurityException
Create a new client-side multiplexer.
Parameters:
endpoint - the endpoint to multiplex messages over
principal - the security principal
Returns:
a new client-side multiplexer
Throws:
java.io.IOException - if an I/O error occurs
SecurityException - if connection is refused by the server

createMultiplexer

protected Multiplexer createMultiplexer(Endpoint endpoint,
                                        Authenticator authenticator)
                                 throws java.io.IOException,
                                        ResourceException
Create a new server-side multiplexer.
Parameters:
endpoint - the endpoint to multiplex messages over
authenticator - the connection authetnicator
Returns:
a new server-side multiplexer
Throws:
java.io.IOException - if an I/O error occurs
ResourceException - if the authenticator cannot authenticate

isClient

protected boolean isClient()
Helper to determine if this is a client-side or server side instance.
Returns:
true if this is a client-side instance, otherwise false

getCaller

protected Caller getCaller()
Helper to return an Caller instance, denoting the client performing a method invocation. Only applicable for server-side, and only after the multiplexer has been created.
Returns:
the caller instance, or null if it hasn't been initialised

getThreadGroup

protected java.lang.ThreadGroup getThreadGroup()
Returns the thread group to associate with allocated threads.
Returns:
the thread group to associate with allocated threads, or null to use the default thread group.

getDisplayName

protected java.lang.String getDisplayName()
Helper to generate a descriptive name, for display purposes.

This implementation returns the remote URI, concatenated with "[client]" if this is a client connection, or "[server]" if it is a server connection.

Returns:
the display name


Copyright © 1999-2007 The OpenJMS Group. All Rights Reserved.