ch.epfl.lsr.apex.connection
Class APEXEdgeConnection

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

public class APEXEdgeConnection
extends APEXConnection

An APEXEdgeConnection handles the connection between two nodes on the APEX edge (endpoint-relay and vice versa) and adds manager specific policies for the connection.

Author:
Marc Stoecklin

Field Summary
 
Fields inherited from class ch.epfl.lsr.apex.connection.APEXConnection
authenticatedAs, CHANNEL_ESTABLISHED, channelID, CONNECTION_INITIATION, connectionEstablished, connectionThread, currentConnections, entity, internalIDs, knownChannels, manager, messageFile, pollingIntervall, profile, running, task, transID, trialNb
 
Method Summary
 void addAttachedAs(APEXEndpointAddress aea)
          Updates the authenticatedAs table if the manager is successfully attached as the specified endpoint address.
 void attach(APEXEndpointAddress aea, APEXStatus s)
          Attaches as the endpoint address on this connection, say at the entity, and adds the status listener to the attach message.
protected  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 disconnected()
          Is called if a disconnection is noticed and initiates appropriate solutions (policies for relay and endpoint).
static APEXEdgeConnection getAPEXEdgeConnection(APEXManager manager, String entity, Channel c, Object receivingChannelID)
           APEXEdgeConnectionFACTORY Returns either a new APEXEdgeConnection or an existing, stored in the connection table.
static APEXEdgeConnection getAPEXEdgeConnection(APEXManager manager, String entity, int edgePort)
           APEXEdgeConnectionFACTORY Returns either a new APEXEdgeConnection or an existing stored in the connection table.
static APEXEdgeConnection getAPEXEdgeConnection(String entity)
           APEXEdgeConnectionFACTORY Returns either an existing APEXEdgeConnection stored in the connection table or null.
(package private) static APEXEdgeConnection getConnectionForChannel(Channel c)
          Returns a APEXEdgeConnection or null for a given org.beepcore.beep.core.Channel.
protected  void handleReply(Message replyMessage, APEXMessage message)
          Handles a received reply message to a correspondent (sent) APEX message (attach, bind, terminate, or data).
protected  boolean isAuthenticated(APEXDataMessage m)
          Returns a boolean which depends if the message is authentcated to be sent or not to the hop (either attached or bound).
protected  void messageNotSent(APEXMessage message)
           Is called by the connection thread if the session is down an the message has not been sent.
protected  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).
 void removeAttachedAs(APEXEndpointAddress aea)
          Updates the authenticatedAs table if an the manager is not attached (any more) as the specified endpoint address.
static void removeEdgeConnection(String entity)
          Removes the edge connection entry in the connection table for the specified entity name.
protected  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 run()
           
 boolean sendMessage(APEXDataMessage m, APEXStatus s)
          Sends a message on this connection.
 void terminate(APEXEndpointAddress aea, int code, String content, String xmlLang, APEXStatus s)
          Terminates the endpoint address attachment on this connection, say at the (endpoint) / this (relay) entity, adds the status listener to the terminate message, and removes the endpoint address of the authenticatedAs table.
 void terminate(int transID, int code, String content, String xmlLang, APEXStatus s)
          Terminates a transaction on this connection, say at the entity, and adds the status listener to the terminate message.
 
Methods inherited from class ch.epfl.lsr.apex.connection.APEXConnection
addFirstMessage, addMessage, clearMessageFile, getChannelID, getMessage, getUniqueTransID, newAttachmentOrBinding, updateTransID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAPEXEdgeConnection

public static APEXEdgeConnection getAPEXEdgeConnection(APEXManager manager,
                                                       String entity,
                                                       Channel c,
                                                       Object receivingChannelID)

APEXEdgeConnectionFACTORY

Returns either a new APEXEdgeConnection or an existing, stored in the connection table.

Parameters:
manager - The manager
entity - The entity name
c - The existing channel
receivingChannelID - The receiver's channel identifier
Returns:
A resulting edge connection

getAPEXEdgeConnection

public static APEXEdgeConnection getAPEXEdgeConnection(String entity)

APEXEdgeConnectionFACTORY

Returns either an existing APEXEdgeConnection stored in the connection table or null.

Parameters:
entity - The entity name
Returns:
An edge connection or null

getAPEXEdgeConnection

public static APEXEdgeConnection getAPEXEdgeConnection(APEXManager manager,
                                                       String entity,
                                                       int edgePort)

APEXEdgeConnectionFACTORY

Returns either a new APEXEdgeConnection or an existing stored in the connection table.

Parameters:
manager - The manager (endpoint)
entity - The entity name to connect to
edgePort - The edge port
Returns:
The resulting edge connection

getConnectionForChannel

static APEXEdgeConnection getConnectionForChannel(Channel c)
Returns a APEXEdgeConnection or null for a given org.beepcore.beep.core.Channel.

Parameters:
c - The channel
Returns:
A APEXEdgeConnection or null

removeEdgeConnection

public static void removeEdgeConnection(String entity)
Removes the edge connection entry in the connection table for the specified entity name.

Parameters:
entity - The entity name

isAuthenticated

protected boolean isAuthenticated(APEXDataMessage m)
Description copied from class: APEXConnection
Returns a boolean which depends if the message is authentcated to be sent or not to the hop (either attached or bound).

Specified by:
isAuthenticated in class APEXConnection

addAttachedAs

public void addAttachedAs(APEXEndpointAddress aea)
Updates the authenticatedAs table if the manager is successfully attached as the specified endpoint address.

Parameters:
aea - The attached endpoint address

removeAttachedAs

public void removeAttachedAs(APEXEndpointAddress aea)
Updates the authenticatedAs table if an the manager is not attached (any more) as the specified endpoint address.

Parameters:
aea - The not attached endpoint address

attach

public void attach(APEXEndpointAddress aea,
                   APEXStatus s)
Attaches as the endpoint address on this connection, say at the entity, and adds the status listener to the attach message.

Parameters:
aea - The endpoint address to be attached
s - The status listener or null for none

terminate

public void terminate(APEXEndpointAddress aea,
                      int code,
                      String content,
                      String xmlLang,
                      APEXStatus s)
Terminates the endpoint address attachment on this connection, say at the (endpoint) / this (relay) entity, adds the status listener to the terminate message, and removes the endpoint address of the authenticatedAs table.

Parameters:
aea - The endpoint address to be terminated
code - An optional (applicational) code or 0
content - The content or null for none
xmlLang - The xml:lang or null for none
s - The status listener or null for none

terminate

public void terminate(int transID,
                      int code,
                      String content,
                      String xmlLang,
                      APEXStatus s)
Terminates a transaction on this connection, say at the entity, and adds the status listener to the terminate message.

Parameters:
transID -
code - An optional (applicational) code or 0
content - The content or null for none
xmlLang - The xml:lang or null for none
s - The status listener or null for none

handleReply

protected void handleReply(Message replyMessage,
                           APEXMessage message)
Description copied from class: APEXConnection
Handles a received reply message to a correspondent (sent) APEX message (attach, bind, terminate, or data).

Specified by:
handleReply in class APEXConnection
Parameters:
replyMessage - The received reply message
message - The sent APEX message

messageNotSent

protected void messageNotSent(APEXMessage message)
Description copied from class: APEXConnection

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.

Specified by:
messageNotSent in class APEXConnection
Parameters:
message - The unsent message

noConnectionEstablished

protected void noConnectionEstablished()
Description copied from class: APEXConnection
Is called by the connection thread if no connection is established and initiates correspondent actions (according the connection type and the underlying manager).

Specified by:
noConnectionEstablished in class APEXConnection

disconnected

protected void disconnected()
Is called if a disconnection is noticed and initiates appropriate solutions (policies for relay and endpoint).


requestedChannelNotStarted

protected void requestedChannelNotStarted()
Description copied from class: APEXConnection
Is called by the connection thread if no APEX channel is established and initiates correspondent actions (according the connection type and the underlying manager).

Specified by:
requestedChannelNotStarted in class APEXConnection

channelEstablished

protected void channelEstablished()
Description copied from class: APEXConnection
Is called by the connection thread if an APEX channel is successfully established - allows to update the status of the connection.

Specified by:
channelEstablished in class APEXConnection

sendMessage

public boolean sendMessage(APEXDataMessage m,
                           APEXStatus s)
Sends a message on this connection.

Parameters:
m - The message to be sent
s - The status listener or null
Returns:
A boolean indication if the originator is attached or trying to attach; false if the originator is unknown

run

public void run()