Class Session

java.lang.Object
com.bea.wcp.diameter.Session
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
ClientSession, ClientSession, ShSession, Simulator.ServerSession, SyClientSession

public class Session extends Object implements Externalizable
Base class for Diameter application sessions. Diameter applications extend this class in order to provide application-specific handling of requests or answer messages for the application.
Author:
Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
See Also:
  • Constructor Details

    • Session

      public Session()
      Used by Externalizable.
    • Session

      public Session(Application app, String id, Object parent)
      Creates a new server Session for the specified Application and session id. This constructor is used by server applications when creating a Session for an existing session id.
      Parameters:
      app - the Application for the session
      id - the session id
      parent - the Parent Session of this session
      Throws:
      IllegalStateException - if a session with the same id has already been created
    • Session

      public Session(Application app, String id)
      Creates a new server Session for the specified Application and session id. This constructor is used by server applications when creating a Session for an existing session id.
      Parameters:
      app - the Application for the session
      id - the session id
      Throws:
      IllegalStateException - if a session with the same id has already been created
    • Session

      public Session(Application app)
      Creates a new client Session for the specified Application. The session id will be created by calling @{link Application#createSessionId()}.
      Parameters:
      app - the Application for the session
  • Method Details

    • setListener

      public void setListener(SessionListener listener)
      Sets the SessionListener for this session. The listener will be invoked for all messages received by the session.
      Parameters:
      listener - the new SessionListener
    • getListener

      public SessionListener getListener()
      Returns the SessionListener for this session.
      Returns:
      the SessionListener, or null if none.
      Since:
      3.1
    • getAdapter

      public Object getAdapter()
    • setAdapter

      public void setAdapter(Object adapter)
    • getId

      public final String getId()
      Returns the session identifier.
    • getApplication

      public final Application getApplication()
      Returns the Application for this Session.
    • setAttribute

      public void setAttribute(String name, Object value)
      Sets the new value of a session attribute, replacing any previous value.
      Parameters:
      name - the attribute name
      value - the new attribute value
    • getAttribute

      public Object getAttribute(String name)
      Returns the value of the specified session attribute.
      Parameters:
      name - the attribute name
      Returns:
      the attribute value, or null if not found
    • removeAttribute

      public void removeAttribute(String name)
      Removes the session attribute with the specified name.
      Parameters:
      name - the attribute name
    • terminate

      public void terminate()
      Terminates the session.
    • isTerminated

      public boolean isTerminated()
      Returns true if this session has been terminated.
      Returns:
      true if the session is terminated, false if not
    • createRequest

      public Request createRequest(Command cmd)
      Creates a new Request for this session. If the application has a default destination realm and/or host, then they will be used for the new request.
      Parameters:
      cmd - the command for the request
      Returns:
      the new Request
    • notifyListener

      protected void notifyListener(Message msg) throws DiameterException, IOException
      Delivers the specified message to the session listener. Does nothing if a session listener has not been set. Sessions which override rcvRequest() or rcvAnswer() must use this method to optionally forward the message to the session listener.
      Parameters:
      msg - the message to be delivered
      Throws:
      DiameterException
      IOException
    • rcvMessage

      public void rcvMessage(Message msg) throws DiameterException, IOException
      Called when a new Request or Answer has been received for this session. The default behavior is to call rcvRequest() for a request or rcvAnswer() for an answer message. Session implementations should not override this method directly but override rcvRequest() or rcvAnswer() instead.
      Parameters:
      msg - the message that has been received
      Throws:
      IOException - if an error occured while processing the message
      DiameterException
    • rcvRequest

      protected void rcvRequest(Request req) throws DiameterException, IOException
      Called when a new request message has been received for this session. Session implementations should override this method to provide application specific handling of requests. The default behavior is to send the error answer UNABLE_TO_COMPLY.
      Parameters:
      req - the request that has been received
      Throws:
      IOException - if an error occurred while processing the request
      DiameterException
    • rcvAnswer

      protected void rcvAnswer(Answer ans) throws DiameterException, IOException
      Called when an answer message has been received for this session. Session implementations should override this method to provide application specific handling of answer messages. The default behavior is to ignore the answer.
      Parameters:
      ans - the answer message that has been received
      Throws:
      IOException - if an error occured while processing the answer
      DiameterException
    • sndMessage

      public void sndMessage(Message msg) throws IOException
      Called by the container when a message is about to be sent but before it has been committed. This gives the Session a chance to update any state that may change when a message has been sent out.
      Parameters:
      msg - the message being sent
      Throws:
      IOException - if an I/O error occurred while sending the message
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • appendXml

      public XmlBuffer appendXml(XmlBuffer xb)
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput is) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException