org.exolab.core.messenger
Class ManagedPacketConnection

java.lang.Object
  extended by org.exolab.core.messenger.ManagedPacketConnection
All Implemented Interfaces:
ConnectionEventListener, ManagedConnection

public class ManagedPacketConnection
extends java.lang.Object
implements ManagedConnection, ConnectionEventListener

A ManagedPacketConnection implements an efficient packet based protocol over a low level transport protocol.

Version:
$Revision: 1.3 $ $Date: 2003/06/09 06:28:40 $
Author:
Tim Anderson
See Also:
PacketConnection, Messenger

Nested Class Summary
static class ManagedPacketConnection.ConnectRequest
           
static class ManagedPacketConnection.ConnectResponse
           
 
Constructor Summary
ManagedPacketConnection(Context context, MultiplexerFactory factory)
          Construct a new ManagedPacketConnection
 
Method Summary
 void accept(java.lang.String name, ConnectionHandler handler)
          Register a handler to accept new connections.
This method returns immediately.
 void close()
          Destroys the physical connection, prior to notifying any registered ManagedConnectionEventListener instance
 void close(java.lang.String name)
          Stop accepting connect requests for the specified connection
 void closed(Connection connection)
          Invoked when a connection is closed
protected  PacketConnection createConnection(java.lang.String name)
          Create a new connection to serve a client
protected  void doClose()
          Performs the actual connection closure, without notifying registered listeners
protected  void ensureOpen()
           
 void error(Connection connection, java.lang.Exception exception)
          Invoked when a fatal connection error occurs, just before an Exception is thrown to the application
protected  void errorOnStream(java.lang.Exception reason)
          Handle an error event, raised by the Multiplexer or Demultiplexer.
protected  Channel getChannel(int connectionId, int channelId)
          Helper to return a channel for a particular connection
protected  PacketQueue getOutputQueue()
          Returns the queue of packets to be streamed down the physical connection
protected  org.exolab.core.messenger.PacketPool getPool()
          Returns the pool of free packets
protected  ThreadPool getThreadPool()
          Returns the thread pool
protected  void initialise()
          Initialises the connection
 Connection open(java.lang.String name, ConnectionProperties properties)
          Creates a new connection handle for the underlying physical connection represented by the ManagedConnection instance
 void setManagedConnectionEventListener(ManagedConnectionEventListener listener)
          Set the listener for connection events
protected  void streamClosed()
          Handle a close event, raised by the Multiplexer or Demultiplexer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ManagedPacketConnection

public ManagedPacketConnection(Context context,
                               MultiplexerFactory factory)
Construct a new ManagedPacketConnection

Parameters:
context - the connection context
factory - the factory for multiplexers/demultiplexers
Throws:
java.lang.IllegalArgumentException - if any argument is null
Method Detail

open

public Connection open(java.lang.String name,
                       ConnectionProperties properties)
                throws java.rmi.RemoteException
Creates a new connection handle for the underlying physical connection represented by the ManagedConnection instance

Specified by:
open in interface ManagedConnection
Parameters:
name - the name of the connection
properties - connection properties (may be null)
Returns:
a new conneciton handle
Throws:
ConnectException - if no handler is registered for name
java.rmi.RemoteException - if a new connection handle cannot be created

accept

public void accept(java.lang.String name,
                   ConnectionHandler handler)
            throws java.rmi.RemoteException
Register a handler to accept new connections.
This method returns immediately.

Specified by:
accept in interface ManagedConnection
Parameters:
handler - the handler to pass new connections to
name - the connection name to listen on
Throws:
java.rmi.RemoteException - if an error occurs registering the handler
java.lang.IllegalArgumentException - if any argument is null

close

public void close(java.lang.String name)
Stop accepting connect requests for the specified connection

Specified by:
close in interface ManagedConnection
Parameters:
name - the connection name
Throws:
java.lang.IllegalArgumentException - if name is null

close

public void close()
           throws java.rmi.RemoteException
Destroys the physical connection, prior to notifying any registered ManagedConnectionEventListener instance

Specified by:
close in interface ManagedConnection
Throws:
java.rmi.RemoteException - if an error occurs closing the connection

setManagedConnectionEventListener

public void setManagedConnectionEventListener(ManagedConnectionEventListener listener)
Set the listener for connection events

Specified by:
setManagedConnectionEventListener in interface ManagedConnection
Parameters:
listener - the event listener. Setting it to null removes the listener

closed

public void closed(Connection connection)
Invoked when a connection is closed

Specified by:
closed in interface ConnectionEventListener
Parameters:
connection - the closed connection

error

public void error(Connection connection,
                  java.lang.Exception exception)
Invoked when a fatal connection error occurs, just before an Exception is thrown to the application

Specified by:
error in interface ConnectionEventListener
Parameters:
connection - the connection the error occurred on
exception - the error

getChannel

protected Channel getChannel(int connectionId,
                             int channelId)
Helper to return a channel for a particular connection

Parameters:
connectionId - the connection identifier
channelId - the channel identifier
Returns:
the channel for the supplied identifiers, or null, if no such channel exists

initialise

protected void initialise()
                   throws java.rmi.RemoteException
Initialises the connection

Throws:
java.rmi.RemoteException - if the connection can't be initialised

doClose

protected void doClose()
                throws java.rmi.RemoteException
Performs the actual connection closure, without notifying registered listeners

Throws:
java.rmi.RemoteException - if an error occurs closing the connection

getOutputQueue

protected PacketQueue getOutputQueue()
Returns the queue of packets to be streamed down the physical connection


getPool

protected org.exolab.core.messenger.PacketPool getPool()
Returns the pool of free packets


getThreadPool

protected ThreadPool getThreadPool()
Returns the thread pool


createConnection

protected PacketConnection createConnection(java.lang.String name)
                                     throws java.rmi.RemoteException
Create a new connection to serve a client

Parameters:
name - the connection name
Throws:
java.rmi.RemoteException - if the connection cannot be created
java.lang.IllegalArgumentException - if name is null

ensureOpen

protected void ensureOpen()
                   throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

streamClosed

protected void streamClosed()
Handle a close event, raised by the Multiplexer or Demultiplexer


errorOnStream

protected void errorOnStream(java.lang.Exception reason)
Handle an error event, raised by the Multiplexer or Demultiplexer. This closes the connection, prior to notifying any registered listeners of the error.

Parameters:
connection - this connection
reason - the exception describing the cause


Copyright © 1999-2012 The Exolab Group. All Rights Reserved.