ch.epfl.lsr.apex.connection
Class APEXConnectionThread

java.lang.Object
  extended bych.epfl.lsr.apex.connection.APEXConnectionThread
All Implemented Interfaces:
Runnable

public class APEXConnectionThread
extends Object
implements Runnable

An APEXConnectionThread is a connection thread either initiates a new connection or works on a extisting one.

It takes messages from its owner (APEXConnection, say mesh or edge connection) and sends these messages.

 
The state machine of the connection thread:

If a channel is not yet opened:

  1. establish session
  2. open channel

Repeating:

  1. wait for a new message to send
  2. send this message
  3. start a reply listener for the reply reference

To close a connection:

  1. close channel
  2. close connection

Author:
Marc Stoecklin
See Also:
APEXConnection, APEXMeshConnection, APEXEdgeConnection

Field Summary
static int CHANNEL_CLOSING
          internal state: closing channel
static int CHANNEL_ESTABLISHMENT
          internal state: establishing channel
static int IDLE
          internal state: idle
static int INIT
          internal state: initiation
static int MESSAGE_TRANSFER
          internal state: transfering fetched message
static int REPLY_LISTENER
          internal state: fetching reply (starting reply listener)
static int SESSION_CLOSING
          internal state: closing session
static int SESSION_ESTABLISHMENT
          internal state: establishing session
static int WAIT_FOR_MESSAGES
          internal state: waiting for messages
static int WAIT_FOR_TASK
          internal state: waiting for a new task
 
Constructor Summary
APEXConnectionThread(APEXConnection connection, APEXManager manager, String domain, Channel channel)
          Instantiate a new APEXConnectionThread for a connection opened by another hop (session and channel establishment becomes unnecessary).
APEXConnectionThread(APEXConnection connection, APEXManager manager, String domain, int port, APEXProfile messageListener)
          Instantiates a new APEXConnectionThread which first establishes the session and channel.
 
Method Summary
 Channel getChannel()
          Returns the open(ed) channel for this thread.
 void run()
           The state machine of the connection thread: If a channel is not yet opened: establish session open channel Repeating: wait for a new message to send send this message start a reply listener for the reply reference To close a connection: close channel close connection
 void setTask(int t)
          Sets the state of the thread
 void stopRun()
          Stopps the connection thread on the next turn.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT

public static final int INIT
internal state: initiation

See Also:
Constant Field Values

IDLE

public static final int IDLE
internal state: idle

See Also:
Constant Field Values

WAIT_FOR_MESSAGES

public static final int WAIT_FOR_MESSAGES
internal state: waiting for messages

See Also:
Constant Field Values

SESSION_ESTABLISHMENT

public static final int SESSION_ESTABLISHMENT
internal state: establishing session

See Also:
Constant Field Values

CHANNEL_ESTABLISHMENT

public static final int CHANNEL_ESTABLISHMENT
internal state: establishing channel

See Also:
Constant Field Values

MESSAGE_TRANSFER

public static final int MESSAGE_TRANSFER
internal state: transfering fetched message

See Also:
Constant Field Values

REPLY_LISTENER

public static final int REPLY_LISTENER
internal state: fetching reply (starting reply listener)

See Also:
Constant Field Values

CHANNEL_CLOSING

public static final int CHANNEL_CLOSING
internal state: closing channel

See Also:
Constant Field Values

SESSION_CLOSING

public static final int SESSION_CLOSING
internal state: closing session

See Also:
Constant Field Values

WAIT_FOR_TASK

public static final int WAIT_FOR_TASK
internal state: waiting for a new task

See Also:
Constant Field Values
Constructor Detail

APEXConnectionThread

public APEXConnectionThread(APEXConnection connection,
                            APEXManager manager,
                            String domain,
                            int port,
                            APEXProfile messageListener)
Instantiates a new APEXConnectionThread which first establishes the session and channel.

Parameters:
connection - The initiating connection
manager - The manager
domain - The domain literal to connect to
port - The port number to connect to
messageListener - The message listener for the connection (the profile)

APEXConnectionThread

public APEXConnectionThread(APEXConnection connection,
                            APEXManager manager,
                            String domain,
                            Channel channel)
Instantiate a new APEXConnectionThread for a connection opened by another hop (session and channel establishment becomes unnecessary).

Parameters:
connection - The initiating connection
manager - The manager
domain - The domain literal connected to
channel - The channel opened by the opposite hop
Method Detail

setTask

public void setTask(int t)
Sets the state of the thread

Parameters:
t - The state

stopRun

public void stopRun()
Stopps the connection thread on the next turn.


getChannel

public Channel getChannel()
Returns the open(ed) channel for this thread.

Returns:
The channel

run

public void run()

The state machine of the connection thread:

If a channel is not yet opened:

  1. establish session
  2. open channel

Repeating:

  1. wait for a new message to send
  2. send this message
  3. start a reply listener for the reply reference

To close a connection:

  1. close channel
  2. close connection

Specified by:
run in interface Runnable