dk.i1.diameter.session
Class SessionManager

Object
  extended by dk.i1.diameter.node.NodeManager
      extended by dk.i1.diameter.session.SessionManager
All Implemented Interfaces:
ConnectionListener, MessageDispatcher

public class SessionManager
extends NodeManager

A go-between sessions and NodeManager. The SessionManager keeps track of outstanding requests and dispatches answers to the sessions. It also keeps track of the timeouts in the sessions.

SessionManager instances logs with the name "dk.i1.diameter.session", so you can get detailed logging (including hex-dumps of incoming and outgoing packets) by putting "dk.i1.diameter.session.level = ALL" into your log.properties file (or equivalent)


Constructor Summary
SessionManager(NodeSettings settings, Peer[] peers)
          Constructor for SessionManager.
 
Method Summary
protected  void handleAnswer(Message answer, ConnectionKey answer_connkey, Object state)
          Handle an answer to an outstanding request.
protected  void handleRequest(Message request, ConnectionKey connkey, Peer peer)
          Handle incoming request.
 Peer[] peers()
          Retrieve the default set of peers.
 Peer[] peers(Message request)
          Retrieve a set of peers suitable for the specified request.
 void register(Session s)
          Register a session for management.
 void sendRequest(Message request, Session session, Object state)
          Send a request for a session.
 void start()
          Start the session manager.
 void stop(long grace_time)
          Stop the SessionManager.
 void unregister(Session s)
          Unregister a session for management.
 void updateTimeouts(Session s)
          Update the timeouts for a session.
 
Methods inherited from class dk.i1.diameter.node.NodeManager
answer, forwardAnswer, forwardRequest, forwardRequest, handle, handle, node, sendRequest, sendRequest, sendRequest, sendRequest, settings, stop, waitForConnection, waitForConnection, waitForConnectionTimeout
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionManager

public SessionManager(NodeSettings settings,
                      Peer[] peers)
               throws InvalidSettingException
Constructor for SessionManager.

Parameters:
settings - The node settings
peers - The default set of peers. If a subclass overrides the peers() methods then this parameter can be null.
Throws:
InvalidSettingException
Method Detail

start

public void start()
           throws java.io.IOException,
                  UnsupportedTransportProtocolException
Start the session manager. The SessionManager must be started before it can be used by sessions.

Overrides:
start in class NodeManager
Throws:
java.io.IOException
UnsupportedTransportProtocolException

stop

public void stop(long grace_time)
Stop the SessionManager.

Overrides:
stop in class NodeManager
Parameters:
grace_time - Maximum time (milliseconds) to wait for connections to close gracefully.
Since:
grace_time parameter introduced in 0.9.3

handleRequest

protected void handleRequest(Message request,
                             ConnectionKey connkey,
                             Peer peer)
Handle incoming request. Examines the Session-Id AVP and dispatches the request to the session.

Overrides:
handleRequest in class NodeManager
Parameters:
request - The incoming request.
connkey - The connection from where the request came.
peer - The peer that sent the request. This is not the originating peer but the peer directly connected to us that sent us the request.

handleAnswer

protected void handleAnswer(Message answer,
                            ConnectionKey answer_connkey,
                            Object state)
Handle an answer to an outstanding request. Dispatches the answer to the corresponding session by calling either Session.handleAnswer() or Session.handleNonAnswer()

Overrides:
handleAnswer in class NodeManager
Parameters:
answer - The answer message. Null if the connection broke.
answer_connkey - The connection from where the answer came.
state - The state object passed to sendRequest() or forwardRequest()

sendRequest

public void sendRequest(Message request,
                        Session session,
                        Object state)
                 throws NotRoutableException,
                        NotARequestException
Send a request for a session. Sessions must use this method and not NodeManager.sendRequest(), as the SessionManager must keep track of outstanding requests. Note that the session's handleAnswer() method may get called before this method returns.

Parameters:
request - The request to send-
session - The session the request is sent on behalf of.
state - A state object that will be given in the Session.handleAnswer(dk.i1.diameter.Message, java.lang.Object) or Session.handleNonAnswer(int, java.lang.Object) call.
Throws:
NotRoutableException
NotARequestException

peers

public Peer[] peers()
Retrieve the default set of peers.

Returns:
The set of peers specified in the constructor.

peers

public Peer[] peers(Message request)
Retrieve a set of peers suitable for the specified request. A subclass can override this method to implement more intelligent peer selection.

Parameters:
request - The request that will be sent to one of the returned peers.
Returns:
a set of suitable peers.

register

public void register(Session s)
Register a session for management. The BaseSession class calls this method when appropriate

Parameters:
s - The Session to be registered.

unregister

public void unregister(Session s)
Unregister a session for management. The BaseSession class calls this method when appropriate.

Parameters:
s - The Session to be registered.

updateTimeouts

public void updateTimeouts(Session s)
Update the timeouts for a session. When some timeout changes in a session then the session must call this method to let the SessionManager re-calculate the timeout and update internal state accordingly.