org.caleigo.toolkit.tunnel
Class AbstractTunnelServer

java.lang.Object
  extended byorg.caleigo.toolkit.tunnel.AbstractTunnelServer
All Implemented Interfaces:
ITunnelListener, ITunnelServer
Direct Known Subclasses:
HTTPTunnelServer, SocketTunnelServer

public class AbstractTunnelServer
extends java.lang.Object
implements ITunnelServer, ITunnelListener

Version:
1.00
Author:
Mattias Hagstrand

Field Summary
protected  boolean mIsInitialized
           
protected  java.util.List mMessageConsumers
           
protected  java.util.Map mRegisteredCodecs
           
protected  java.util.Map mRegisteredPackers
           
protected  java.util.List mTunnels
           
protected  java.util.List mTunnelServerListeners
           
 
Constructor Summary
AbstractTunnelServer()
           
 
Method Summary
 void addMessageConsumer(IMessageConsumer consumer)
          Adds the IMessageConsumer that receives messages from all connections that this ITunnelServer has set up.
protected  void addTunnel(ITunnel tunnel)
           
 void addTunnelServerListener(ITunnelServerListener listener)
           
 void connectionLost(TunnelEvent event)
          Invoked on an ITunnel on the client side when the connection to the server has been lost.
 void finalize()
          Performs cleanup for this ITunnelServer.
protected  void fireTunnelAddedEvent(ITunnel tunnel)
           
protected  void fireTunnelRemovedEvent(ITunnel tunnel)
           
protected  ITunnelCodec getCodec(java.lang.String codecClassName)
           
protected  ITunnelPacker getPacker(java.lang.String packerClassName)
           
 ITunnel getTunnel(int index)
          Returns the ITunnel with the provided index.
 int getTunnelCount()
          Returns the number of ITunnels that this ITunnelServer has created.
 java.util.Iterator getTunnels()
          Returns an Iterator for all ITunnels that this ITunnelServer has created.
 void initialize()
          Initializes the ITunnelServer.
 void registerCodec(java.lang.Class codec)
          Registers an ITunnelCodec that can be used when setting up a connection.
 void registerPacker(java.lang.Class packer)
          Registers an ITunnelPacker that can be used when setting up a connection.
 void removeMessageConsumer(IMessageConsumer consumer)
          Removes the IMessageConsumer all connections that this ITunnelServer has set up.
protected  void removeTunnel(ITunnel tunnel)
           
 void removeTunnelServerListener(ITunnelServerListener listener)
           
protected  void setUpTunnel(java.lang.Object connectionMessage, ITunnel tunnel)
          Try to set up the provided ITunnel based on the information contined in the connection message.
 void tunnelClosed(TunnelEvent event)
          Invoked when the ITunnel has been closed.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mTunnels

protected java.util.List mTunnels

mMessageConsumers

protected java.util.List mMessageConsumers

mRegisteredCodecs

protected java.util.Map mRegisteredCodecs

mRegisteredPackers

protected java.util.Map mRegisteredPackers

mIsInitialized

protected boolean mIsInitialized

mTunnelServerListeners

protected java.util.List mTunnelServerListeners
Constructor Detail

AbstractTunnelServer

public AbstractTunnelServer()
Method Detail

initialize

public void initialize()
                throws java.lang.IllegalStateException,
                       TunnelException
Initializes the ITunnelServer. This method must be called before connections can be accepted.

Specified by:
initialize in interface ITunnelServer
Throws:
java.lang.IllegalStateException
TunnelException

finalize

public void finalize()
              throws java.lang.IllegalStateException,
                     TunnelException
Performs cleanup for this ITunnelServer. This involves closing all connections. No connections can be accepted after this method has been called.

Specified by:
finalize in interface ITunnelServer
Throws:
java.lang.IllegalStateException
TunnelException

registerPacker

public void registerPacker(java.lang.Class packer)
Registers an ITunnelPacker that can be used when setting up a connection.

Specified by:
registerPacker in interface ITunnelServer

registerCodec

public void registerCodec(java.lang.Class codec)
Registers an ITunnelCodec that can be used when setting up a connection.

Specified by:
registerCodec in interface ITunnelServer

addMessageConsumer

public void addMessageConsumer(IMessageConsumer consumer)
Adds the IMessageConsumer that receives messages from all connections that this ITunnelServer has set up. This is a convenience method. Calling this method has the same effect as calling addMessageConsumer on all of the individual ITunnels returned by getTunnels. All IMessageConsumers that have been added with this method will automatically be added to all new ITunnels that are create.

Specified by:
addMessageConsumer in interface ITunnelServer

removeMessageConsumer

public void removeMessageConsumer(IMessageConsumer consumer)
Removes the IMessageConsumer all connections that this ITunnelServer has set up. This is a convenience method. Calling this method has the same effect as calling removeMessageConsumer on all of the individual ITunnels returned by getTunnels.

Specified by:
removeMessageConsumer in interface ITunnelServer

getTunnel

public ITunnel getTunnel(int index)
Returns the ITunnel with the provided index.

Specified by:
getTunnel in interface ITunnelServer

getTunnels

public java.util.Iterator getTunnels()
Returns an Iterator for all ITunnels that this ITunnelServer has created.

Specified by:
getTunnels in interface ITunnelServer

getTunnelCount

public int getTunnelCount()
Returns the number of ITunnels that this ITunnelServer has created.

Specified by:
getTunnelCount in interface ITunnelServer

addTunnelServerListener

public void addTunnelServerListener(ITunnelServerListener listener)
Specified by:
addTunnelServerListener in interface ITunnelServer

removeTunnelServerListener

public void removeTunnelServerListener(ITunnelServerListener listener)
Specified by:
removeTunnelServerListener in interface ITunnelServer

tunnelClosed

public void tunnelClosed(TunnelEvent event)
Invoked when the ITunnel has been closed. This happens on the server side when the tunnel on the client side is closed. The source ITunnel is finalized before this method is invoked.

Specified by:
tunnelClosed in interface ITunnelListener

connectionLost

public void connectionLost(TunnelEvent event)
Invoked on an ITunnel on the client side when the connection to the server has been lost. The source ITunnel is finalized before this method is invoked.

Specified by:
connectionLost in interface ITunnelListener

addTunnel

protected void addTunnel(ITunnel tunnel)

removeTunnel

protected void removeTunnel(ITunnel tunnel)

getCodec

protected ITunnelCodec getCodec(java.lang.String codecClassName)

getPacker

protected ITunnelPacker getPacker(java.lang.String packerClassName)

fireTunnelAddedEvent

protected void fireTunnelAddedEvent(ITunnel tunnel)

fireTunnelRemovedEvent

protected void fireTunnelRemovedEvent(ITunnel tunnel)

setUpTunnel

protected void setUpTunnel(java.lang.Object connectionMessage,
                           ITunnel tunnel)
                    throws TunnelException
Try to set up the provided ITunnel based on the information contined in the connection message. If the tunnel was set up successfully it will be added to this tunnel server. The invoker of this method is responsible for calling initialize on the tunnel.

Returns:
a status message that is to be returned by the invoker of this method.
Throws:
TunnelException


Copyright © 2005 Caleigo. All Rights Reserved.