org.exolab.core.messenger
Class PacketConnection

java.lang.Object
  extended by org.exolab.core.messenger.PacketConnection
All Implemented Interfaces:
Connection

public class PacketConnection
extends java.lang.Object
implements Connection

A PacketConnection is a Connection that minimises resource usage.

This is achieved by:

Version:
$Revision: 1.5 $ $Date: 2003/06/09 06:28:40 $
Author:
Tim Anderson
See Also:
ConnectionEventListener, PacketChannel, PacketQueue, PacketPool, Multiplexer, Demultiplexer

Constructor Summary
PacketConnection(ManagedPacketConnection owner, int connectionId)
          Construct a new PacketConnection
 
Method Summary
 void accept(java.lang.String name, ChannelHandler handler)
          Register a handler to accept channel connections for the specified name.
 void accept(java.lang.String name, ChannelListener listener)
          Register a handler to accept a single channel connection for the specified name, and bind the listener to it
This method returns immediately.
 void addConnectionEventListener(ConnectionEventListener listener)
          Add a listener for connection events
 void close()
          Close the connection.
 void close(java.lang.String name)
          Stop accepting requests on the specified channel
protected  void closed(PacketChannel channel)
           
protected  PacketChannel createChannel(int channelId, int destinationId)
           
protected  void doClose()
          Performs the actual connection closure, without notifying registered listeners
protected  void ensureOpen()
           
protected  Channel getChannel(int channelId)
          Returns the channel for the give channel identifier
 int getConnectionId()
          Return the unique identifier for this connection
protected  int getNextChannelId()
           
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
 Channel open(java.lang.String name)
          Open a channel
 void removeConnectionEventListener(ConnectionEventListener listener)
          Remove a listener of connection events
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketConnection

public PacketConnection(ManagedPacketConnection owner,
                        int connectionId)
                 throws java.rmi.RemoteException
Construct a new PacketConnection

Parameters:
owner - the managed connection that owns this
connectionId - the connection identifier
Throws:
java.lang.IllegalArgumentException - if owner is null
java.rmi.RemoteException - if the connection can't be initialised
Method Detail

getConnectionId

public int getConnectionId()
Return the unique identifier for this connection

Returns:
the identifier for this connection

open

public Channel open(java.lang.String name)
             throws java.rmi.RemoteException
Open a channel

Specified by:
open in interface Connection
Parameters:
name - the name of the channel
Returns:
the open channel
Throws:
java.rmi.RemoteException - if the channel can't be opened
ConnectionClosedException - if the connection is closed
InvalidChannelException - if the channel doesn't exist

accept

public void accept(java.lang.String name,
                   ChannelHandler handler)
            throws java.rmi.RemoteException
Register a handler to accept channel connections for the specified name.
This method returns immediately.

Specified by:
accept in interface Connection
Parameters:
name - the channel name to listen on
handler - the handler to pass new channels to
Throws:
java.rmi.RemoteException - if an error occurs accepting channels
ConnectionClosedException - if the connection is closed
java.lang.IllegalArgumentException - if any argument is null

accept

public void accept(java.lang.String name,
                   ChannelListener listener)
            throws java.rmi.RemoteException
Register a handler to accept a single channel connection for the specified name, and bind the listener to it
This method returns immediately.

Specified by:
accept in interface Connection
Parameters:
name - the channel name to listen on
listener - the listener to handle requests on the channel
Throws:
java.rmi.RemoteException - if an error occurs accepting channels
ConnectionClosedException - if the connection is closed
java.lang.IllegalArgumentException - if any argument is null

close

public void close(java.lang.String name)
Stop accepting requests on the specified channel

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

addConnectionEventListener

public void addConnectionEventListener(ConnectionEventListener listener)
Add a listener for connection events

Specified by:
addConnectionEventListener in interface Connection
Parameters:
listener - the listener to add

removeConnectionEventListener

public void removeConnectionEventListener(ConnectionEventListener listener)
Remove a listener of connection events

Specified by:
removeConnectionEventListener in interface Connection
Parameters:
listener - the listener to remove

close

public void close()
           throws java.rmi.RemoteException
Close the connection.

This closes all channels open on the connection, and then closes the underlying physical connection, prior to notifying registered ConnectionEventListener instances

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

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

getChannel

protected Channel getChannel(int channelId)
Returns the channel for the give channel identifier

Parameters:
channelId - the channel identifier
Returns:
the channel corresponding to channelId, or null, if no channel exists

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


createChannel

protected PacketChannel createChannel(int channelId,
                                      int destinationId)
                               throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

closed

protected void closed(PacketChannel channel)
               throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

getNextChannelId

protected int getNextChannelId()

ensureOpen

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


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