abstract class BaseSession extends java.lang.Object implements Session, MessageTypes
Session
interface. Stores a
queue, a security context, and a numeric value which uniquely identifies
that context within the local network node. A null
context
and a context ID of 0 are valid; these values indicate there is no
security context for the session.
All methods of Session
's superinterface, LowLevelSession
, are delegated to the queue. The remaining methods
generally are called by, and call, the SessionManager
.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
context
Security context
|
private int |
contextID
Security context identifier
|
private java.util.List<SessionListener> |
listeners
List of objects to receive event notifications.
|
protected static java.util.logging.Logger |
LOG
Logger
|
private Queue |
queue
Message transport queue
|
private boolean |
terminated
Track this session's terminated state.
|
ADDRESS_REPLY, ADDRESS_REQUEST, BEGIN_REPLY, ECHO, ECHO_REPLY, END_REPLY, INIT_CONVERSATION, INIT_REPLY, INIT_ROUTER, INIT_STANDARD, REPLY_ASYNC, REPLY_EXCEPTION_ASYNC, REPLY_EXCEPTION_SYNC, REPLY_SYNC, REQUEST_ASYNCH, REQUEST_SYNCH, UNKNOWN
Modifier | Constructor and Description |
---|---|
protected |
BaseSession(Queue queue,
java.lang.Object context,
int contextID)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addSessionListener(SessionListener listener)
Add a new instance into the list of objects which will be notified
of session events.
|
boolean |
addSessionListener(SessionListener listener,
boolean check)
Add a new instance into the list of objects which will be notified
of session events.
|
protected void |
cleanupContext()
Terminate the current session with the security manager.
|
java.lang.Object |
echo(java.io.Serializable obj,
int timeout,
RoutingKey key)
Send an echo request message using provided data as a message payload
and wait for reply.
|
(package private) void |
echoReply(Message msg)
Respond to an echo request by simply changing the message type to
ECHO_REPLY and sending it back to its source node. |
(package private) void |
end()
End the network session.
|
void |
forward(Message message)
Preprocess the given message and then send it as an asynchronous request
without waiting for a reply.
|
(package private) java.lang.Object |
getContext()
Get the security context for this session.
|
(package private) int |
getContextID()
Get the session's security context ID.
|
java.lang.Exception |
getException()
Return the exception which was thrown for an exceptional termination of
the session, if any.
|
int |
getNodeAddress()
Get the node address assigned to the session.
|
(package private) Queue |
getQueue()
Get the session's queue.
|
int |
getRemoteAddress()
Get the remote node address known to the session.
|
boolean |
isRunning()
Returns the operational state of this session.
|
protected abstract void |
preprocess(Message message)
Preprocess a message before it is delivered.
|
void |
registerSynchronizer(StateSynchronizer sync)
Sets the instance of the state synchronizer the reader and writer
threads should use, if and only if there is no other state synchronizer
already in use.
|
void |
removeSessionListener(SessionListener listener)
Remove the listener from the list of objects to be notified about
session events.
|
(package private) void |
sendInitializationEvent()
Send notification to all registered nodes that queue is about to start and have to be
initialized.
|
(package private) void |
sendTerminationEvent()
Send notification to all registered nodes that queue is about to terminate.
|
(package private) void |
setContext()
Associate the session's security context with the current thread.
|
void |
terminate()
Terminate the network session.
|
java.lang.Object |
transact(Message message,
int timeout)
Preprocess the given message and then send it as a synchronous request
and wait for reply.
|
protected static final java.util.logging.Logger LOG
private final java.util.List<SessionListener> listeners
private final Queue queue
private final int contextID
private java.lang.Object context
private boolean terminated
protected BaseSession(Queue queue, java.lang.Object context, int contextID)
queue
- Message transport.context
- Security context.contextID
- Security context ID.public void addSessionListener(SessionListener listener)
addSessionListener
in interface Session
listener
- The listener to add.public boolean addSessionListener(SessionListener listener, boolean check)
If the check
flag is set, then it ensure that the session is still connected
before adding the listener. If the session is not connected, then the listener will not
be added and this will return false
.
addSessionListener
in interface Session
listener
- The listener to add.check
- Flag to check session state before adding.true
if the listener was added. false
otherwise.public void removeSessionListener(SessionListener listener)
removeSessionListener
in interface Session
listener
- The listener to remove.public void registerSynchronizer(StateSynchronizer sync)
registerSynchronizer
in interface Session
sync
- The synchronizer to register or null
if the
currently registered synchronizer should be deregistered.public void terminate()
public java.lang.Object transact(Message message, int timeout) throws java.lang.Exception
The message passed as a parameter must be completely filled with all required information - routing key should point to valid entry point. If addresses in the routing key are not set then destination is assumed at directly connected node and appropriate addresses are assigned automatically.
Caller can specify timeout for waiting reply message. If timeout is set to 0 then queue will wait for reply as long as queue is running.
transact
in interface Session
message
- Request message.timeout
- Reply wait timeout.java.lang.Exception
- if reply received from remote side has an exception as its
payload, or if a timeout occurs before the reply message is
received, or if a problem occurs during transmission.public void forward(Message message)
REQUEST_ASYNCH
.public java.lang.Object echo(java.io.Serializable obj, int timeout, RoutingKey key) throws ProtocolViolation, java.lang.InterruptedException, RequestTimeoutException, java.lang.Exception
If instance of RoutingKey
is provided then message is
sent to node pointed by the RoutungKey
. Otherwise
directly connected node is assumed. Note that processing of the ECHO
message ignores entry point information in RoutingKey
so
an instance of RoutingKey created with default constructor can
be used.
Caller can specify timeout for waiting reply message. If this is not necessary then 0 should be passed as If timeout is set to 0 then queue will wait for reply as long as queue is running.
echo
in interface Session
obj
- Message payload.timeout
- Reply wait timeout.key
- The destination node address information.java.lang.InterruptedException
- forwarded from transactImpl()RequestTimeoutException
- forwarded from transactImpl()ProtocolViolation
- in case of protocol errors.java.lang.Exception
- Is thrown if a timeout occurs before the reply message
is received or if a problem occurs during transmission.public int getNodeAddress()
getNodeAddress
in interface LowLevelSession
public int getRemoteAddress()
getRemoteAddress
in interface LowLevelSession
public boolean isRunning()
isRunning
in interface LowLevelSession
true
if the session is running (operational)
and false
if the session is closed.public java.lang.Exception getException()
If not null
, it will contain the queue termination reason.
getException
in interface LowLevelSession
null
if the session is not yet terminated or if the session's
termination was not abnormal.protected abstract void preprocess(Message message)
message
- Message to be processed.protected void cleanupContext()
Queue getQueue()
int getContextID()
final void end()
void echoReply(Message msg)
ECHO_REPLY
and sending it back to its source node.msg
- Echo message.void setContext()
void sendInitializationEvent()
void sendTerminationEvent()
java.lang.Object getContext()