ch.epfl.lsr.apex.connection
Class APEXConnection

java.lang.Object
  extended bych.epfl.lsr.apex.connection.APEXConnection
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
APEXEdgeConnection, APEXMeshConnection

public abstract class APEXConnection
extends Object
implements Runnable

An APEXConnection is a connection thread that takes messages to send on this connection in a linked list (file) and sends them on after another to the destination.

The APEXConnection, due to its abstract property, must be redefined as either an APEXMeshConnection for relay-relay connections or an APEXEdgeConnection for relay-endpoint connections.

Author:
Marc Stoecklin
See Also:
APEXMeshConnection, APEXEdgeConnection

Field Summary
protected  Hashtable authenticatedAs
          A table of authenticated names of this entity on this connection
static int CHANNEL_ESTABLISHED
           
protected  Object channelID
          A unique channel identifier for this connection
static int CONNECTION_INITIATION
           
protected  boolean connectionEstablished
          indicates the state of the connection
protected  APEXConnectionThread connectionThread
          The actual connection runs in a connection thread for this connection
protected static Hashtable currentConnections
           A static table for all currently running connections.
protected  String entity
          The general entity name for this connection (relay or endpoint name)
protected  Hashtable internalIDs
          A table of internal identifiers to map back attached endpoints or bound relays to correspondent transaction identifiers
protected static Hashtable knownChannels
           A static table for already known channels to link different attaching endpoints or relays (for a relay) and different domains (for an endpoint) on the same connection.
protected  APEXManager manager
          The associated manager for call-backs
protected  LinkedList messageFile
          A message file (channel) FIFO
protected  long pollingIntervall
          The polling interval for connection control: 10 sec
protected  APEXProfile profile
          The profile associated to this connection
protected  boolean running
          indicates the state thread
protected  int task
          the state of the connection
protected  Integer transID
          The transaction identifier counter for this connection
protected  int trialNb
          Attempt counter on reconnection
 
Constructor Summary
APEXConnection()
           
 
Method Summary
protected  void addFirstMessage(APEXMessage m)
          Adds a message to the first position of the FIFO message file.
protected  void addMessage(APEXMessage m)
          Adds a message to the FIFO message file.
protected abstract  void channelEstablished()
          Is called by the connection thread if an APEX channel is successfully established - allows to update the status of the connection.
protected  void clearMessageFile()
          Flushes the whole message file irrevocable.
 Object getChannelID()
          Returns the channel identifier associated to this connection.
protected  APEXMessage getMessage()
          Blocking method which is called by the connection thread in order to get a new message to send.
 int getUniqueTransID()
          Returns a unique transaction identifier for this connection.
protected abstract  void handleReply(Message replyMessage, APEXMessage message)
          Handles a received reply message to a correspondent (sent) APEX message (attach, bind, terminate, or data).
protected abstract  boolean isAuthenticated(APEXDataMessage message)
          Returns a boolean which depends if the message is authentcated to be sent or not to the hop (either attached or bound).
protected abstract  void messageNotSent(APEXMessage message)
           Is called by the connection thread if the session is down an the message has not been sent.
protected  void newAttachmentOrBinding()
          Is called on a new attachment or binding in order to release blocked connection threads in the getMessage table.
protected abstract  void noConnectionEstablished()
          Is called by the connection thread if no connection is established and initiates correspondent actions (according the connection type and the underlying manager).
protected abstract  void requestedChannelNotStarted()
          Is called by the connection thread if no APEX channel is established and initiates correspondent actions (according the connection type and the underlying manager).
 void updateTransID(int aTransID)
          Updates the internal transID counter if the opposite hop used a new transaction identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

CONNECTION_INITIATION

public static final int CONNECTION_INITIATION
See Also:
Constant Field Values

CHANNEL_ESTABLISHED

public static final int CHANNEL_ESTABLISHED
See Also:
Constant Field Values

currentConnections

protected static Hashtable currentConnections

A static table for all currently running connections.

A connection is mapped with the domain part of its opposite entity.


knownChannels

protected static Hashtable knownChannels

A static table for already known channels to link different attaching endpoints or relays (for a relay) and different domains (for an endpoint) on the same connection.


trialNb

protected int trialNb
Attempt counter on reconnection


running

protected boolean running
indicates the state thread


task

protected int task
the state of the connection


manager

protected APEXManager manager
The associated manager for call-backs


authenticatedAs

protected Hashtable authenticatedAs
A table of authenticated names of this entity on this connection


messageFile

protected LinkedList messageFile
A message file (channel) FIFO


connectionThread

protected APEXConnectionThread connectionThread
The actual connection runs in a connection thread for this connection


entity

protected String entity
The general entity name for this connection (relay or endpoint name)


profile

protected APEXProfile profile
The profile associated to this connection


internalIDs

protected Hashtable internalIDs
A table of internal identifiers to map back attached endpoints or bound relays to correspondent transaction identifiers


channelID

protected Object channelID
A unique channel identifier for this connection


connectionEstablished

protected boolean connectionEstablished
indicates the state of the connection


pollingIntervall

protected long pollingIntervall
The polling interval for connection control: 10 sec


transID

protected Integer transID
The transaction identifier counter for this connection

Constructor Detail

APEXConnection

public APEXConnection()
Method Detail

handleReply

protected abstract void handleReply(Message replyMessage,
                                    APEXMessage message)
Handles a received reply message to a correspondent (sent) APEX message (attach, bind, terminate, or data).

Parameters:
replyMessage - The received reply message
message - The sent APEX message

messageNotSent

protected abstract void messageNotSent(APEXMessage message)

Is called by the connection thread if the session is down an the message has not been sent.

Dependent on the underlying manager and the connection type (edge or mesh), this method either tries to reconnect or calls the discardMessage method of its manager.

Parameters:
message - The unsent message

noConnectionEstablished

protected abstract void noConnectionEstablished()
Is called by the connection thread if no connection is established and initiates correspondent actions (according the connection type and the underlying manager).


requestedChannelNotStarted

protected abstract void requestedChannelNotStarted()
Is called by the connection thread if no APEX channel is established and initiates correspondent actions (according the connection type and the underlying manager).


channelEstablished

protected abstract void channelEstablished()
Is called by the connection thread if an APEX channel is successfully established - allows to update the status of the connection.


isAuthenticated

protected abstract boolean isAuthenticated(APEXDataMessage message)
Returns a boolean which depends if the message is authentcated to be sent or not to the hop (either attached or bound).


getChannelID

public Object getChannelID()
Returns the channel identifier associated to this connection.

Returns:
The channel identifier

getUniqueTransID

public int getUniqueTransID()
Returns a unique transaction identifier for this connection. This method is synchronized on the internal transID.

Returns:
A unique transaction identifier

updateTransID

public void updateTransID(int aTransID)
Updates the internal transID counter if the opposite hop used a new transaction identifier.

Parameters:
aTransID - The transID used by the opposite hop

getMessage

protected APEXMessage getMessage()
Blocking method which is called by the connection thread in order to get a new message to send.

Returns:
An message which has to be sent by a connection thread

addFirstMessage

protected void addFirstMessage(APEXMessage m)
Adds a message to the first position of the FIFO message file.

Parameters:
m - The message to add

addMessage

protected void addMessage(APEXMessage m)
Adds a message to the FIFO message file.

Parameters:
m - The message to add

clearMessageFile

protected void clearMessageFile()
Flushes the whole message file irrevocable.


newAttachmentOrBinding

protected void newAttachmentOrBinding()
Is called on a new attachment or binding in order to release blocked connection threads in the getMessage table. (Note: a connection thread is blocked no message is authenticated to be sent according the attach / bind status)