net.sf.beep4j.internal
Class SessionImpl

java.lang.Object
  extended by net.sf.beep4j.internal.SessionImpl
All Implemented Interfaces:
FrameHandlerFactory, InternalSession, MessageHandler, SessionManager, Session, TransportContext

public class SessionImpl
extends java.lang.Object
implements MessageHandler, SessionManager, InternalSession, TransportContext, FrameHandlerFactory

Default implementation of the Session interface. Objects of this class are the central object in a BEEP session.

Author:
Simon Raess

Nested Class Summary
protected  class SessionImpl.AbstractSessionState
           
protected  class SessionImpl.AliveState
           
protected  class SessionImpl.DeadState
           
protected  class SessionImpl.DefaultReply
           
protected  class SessionImpl.InitialReply
           
protected  class SessionImpl.InitialState
           
protected static interface SessionImpl.SessionState
           
protected  class SessionImpl.WaitForResponseState
           
 
Constructor Summary
SessionImpl(boolean initiator, SessionHandler sessionHandler, TransportMapping mapping)
           
 
Method Summary
protected  void addSessionListener(SessionListener l)
           
 void channelCloseRequested(int channelNumber, CloseChannelRequest request)
          Requests to close the channel identified by the given channel number.
 StartChannelResponse channelStartRequested(int channelNumber, ProfileInfo[] profiles)
          Requests to start a new channel or cancels the request.
 void close()
          Closes the session.
 void connectionClosed()
          Invoked by the Transport when the underlying physical connection has been closed.
 void connectionEstablished(java.net.SocketAddress address)
          Notifies the context that the physical connection has been established.
protected  InternalChannel createChannel(InternalSession session, java.lang.String profileUri, int channelNumber)
           
protected  ChannelManagementProfile createChannelManagementProfile(boolean initiator)
           
 FrameHandler createFrameHandler()
           
protected  Reply createReply(TransportMapping mapping, int channelNumber, int messageNumber)
           
protected  StreamParser createStreamParser(FrameHandler frameHandler, TransportMapping mapping)
           
 void exceptionCaught(java.lang.Throwable cause)
          Invoked by the Transport to notify the context about an exception that has been caught while sending or processing a message.
protected  void fireChannelClosed(int channel)
           
protected  void fireChannelStarted(int channel)
           
 java.lang.String[] getProfiles()
          Gets the list of profiles supported by the remote peer.
protected  void initChannelManagementProfile()
           
protected  void lock()
           
 void messageReceived(java.nio.ByteBuffer buffer)
          Invoked by the Transport whenever new content has been received.
 void receiveANS(int channelNumber, int messageNumber, int answerNumber, Message message)
          Receive a ANS message.
 void receiveERR(int channelNumber, int messageNumber, Message message)
          Receive a ERR message.
 void receiveMSG(int channelNumber, int messageNumber, Message message)
          Receive a MSG message.
 void receiveNUL(int channelNumber, int messageNumber)
          Receive a NUL message.
 void receiveRPY(int channelNumber, int messageNumber, Message message)
          Receive a RPY message.
 void requestChannelClose(int channelNumber, CloseChannelCallback callback)
           
 void sendMessage(int channelNumber, Message message, ReplyHandler listener)
           
 void sessionCloseRequested(CloseCallback callback)
          Closes the session.
 void startChannel(ProfileInfo[] profiles, ChannelHandlerFactory factory)
          Tries to start a new channel using one of the profiles passed in.
 void startChannel(ProfileInfo profile, ChannelHandler handler)
          Tries to start a new channel using the profile passed in.
 void startChannel(java.lang.String profileUri, ChannelHandler handler)
          Tries to start a new channel using the profile identified by the given uri.
protected  void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionImpl

public SessionImpl(boolean initiator,
                   SessionHandler sessionHandler,
                   TransportMapping mapping)
Method Detail

createStreamParser

protected StreamParser createStreamParser(FrameHandler frameHandler,
                                          TransportMapping mapping)

createChannelManagementProfile

protected ChannelManagementProfile createChannelManagementProfile(boolean initiator)

initChannelManagementProfile

protected void initChannelManagementProfile()

createChannel

protected InternalChannel createChannel(InternalSession session,
                                        java.lang.String profileUri,
                                        int channelNumber)

createReply

protected Reply createReply(TransportMapping mapping,
                            int channelNumber,
                            int messageNumber)

lock

protected void lock()

unlock

protected void unlock()

addSessionListener

protected void addSessionListener(SessionListener l)

fireChannelStarted

protected void fireChannelStarted(int channel)

fireChannelClosed

protected void fireChannelClosed(int channel)

getProfiles

public java.lang.String[] getProfiles()
Description copied from interface: Session
Gets the list of profiles supported by the remote peer. It may be that the peer supports additional profiles, which it did not advertise and which are thus not returned from this method.

Specified by:
getProfiles in interface Session
Returns:
an array of advertised profiles by the other peer

startChannel

public void startChannel(java.lang.String profileUri,
                         ChannelHandler handler)
Description copied from interface: Session
Tries to start a new channel using the profile identified by the given uri. The returned Future can be used to wait until the channel has been established. It returns only after the passed in ChannelHandler.channelOpened(Channel) method returns.

Specified by:
startChannel in interface Session
Parameters:
profileUri - the uri of the profile to be used on the channel
handler - the channel handler for the new channel

startChannel

public void startChannel(ProfileInfo profile,
                         ChannelHandler handler)
Description copied from interface: Session
Tries to start a new channel using the profile passed in. Use this method if you have to pass initialization data along the start channel request. See Session.startChannel(String, ChannelHandler) for the details.

Specified by:
startChannel in interface Session
Parameters:
profile - the profile
handler - the channel handler for the new channel

startChannel

public void startChannel(ProfileInfo[] profiles,
                         ChannelHandlerFactory factory)
Description copied from interface: Session
Tries to start a new channel using one of the profiles passed in. Use this method if you have to pass initialization data along the start channel request. See Session.startChannel(String, ChannelHandler) for the details.

Specified by:
startChannel in interface Session
Parameters:
profiles - the profiles from which the other peer can choose
factory - the factory that creates new ChannelHandlers for the new channel

close

public void close()
Description copied from interface: Session
Closes the session. Note that this method blocks until all outstanding requests have been sent and all requests received up to the moment this method is called have been properly replied to. It ignores negative replies to a close request from the other peer.

Specified by:
close in interface Session

sendMessage

public void sendMessage(int channelNumber,
                        Message message,
                        ReplyHandler listener)
Specified by:
sendMessage in interface InternalSession

requestChannelClose

public void requestChannelClose(int channelNumber,
                                CloseChannelCallback callback)
Specified by:
requestChannelClose in interface InternalSession

createFrameHandler

public FrameHandler createFrameHandler()
Specified by:
createFrameHandler in interface FrameHandlerFactory

channelStartRequested

public StartChannelResponse channelStartRequested(int channelNumber,
                                                  ProfileInfo[] profiles)
Description copied from interface: SessionManager
Requests to start a new channel or cancels the request.

Specified by:
channelStartRequested in interface SessionManager
Parameters:
channelNumber - the channel number
profiles - the list of acceptable profiles
Returns:
the response from the application

channelCloseRequested

public void channelCloseRequested(int channelNumber,
                                  CloseChannelRequest request)
Description copied from interface: SessionManager
Requests to close the channel identified by the given channel number. The request can either be accepted (resulting in a close channel) or declined (in which case the channel stays open).

Specified by:
channelCloseRequested in interface SessionManager
Parameters:
channelNumber - the channel number
request - the close request

sessionCloseRequested

public void sessionCloseRequested(CloseCallback callback)
Description copied from interface: SessionManager
Closes the session.

Specified by:
sessionCloseRequested in interface SessionManager
Parameters:
callback - the callback that gets notified about the outcome

receiveMSG

public void receiveMSG(int channelNumber,
                       int messageNumber,
                       Message message)
Description copied from interface: MessageHandler
Receive a MSG message.

Specified by:
receiveMSG in interface MessageHandler
Parameters:
channelNumber - the channel number
messageNumber - the message number
message - the Message itself

receiveANS

public void receiveANS(int channelNumber,
                       int messageNumber,
                       int answerNumber,
                       Message message)
Description copied from interface: MessageHandler
Receive a ANS message.

Specified by:
receiveANS in interface MessageHandler
Parameters:
channelNumber - the channel number
messageNumber - the message number
answerNumber - the answer number
message - the Message itself

receiveNUL

public void receiveNUL(int channelNumber,
                       int messageNumber)
Description copied from interface: MessageHandler
Receive a NUL message.

Specified by:
receiveNUL in interface MessageHandler
Parameters:
channelNumber - the channel number
messageNumber - the message number

receiveERR

public void receiveERR(int channelNumber,
                       int messageNumber,
                       Message message)
Description copied from interface: MessageHandler
Receive a ERR message.

Specified by:
receiveERR in interface MessageHandler
Parameters:
channelNumber - the channel number
messageNumber - the message number
message - the Message itself

receiveRPY

public void receiveRPY(int channelNumber,
                       int messageNumber,
                       Message message)
Description copied from interface: MessageHandler
Receive a RPY message.

Specified by:
receiveRPY in interface MessageHandler
Parameters:
channelNumber - the channel number
messageNumber - the message number
message - the Message itself

connectionEstablished

public void connectionEstablished(java.net.SocketAddress address)
Description copied from interface: TransportContext
Notifies the context that the physical connection has been established. This allows the BEEP peer to start initializing the BEEP session by sending the greeting.

Specified by:
connectionEstablished in interface TransportContext
Parameters:
address - the SocketAddress of the remote peer

exceptionCaught

public void exceptionCaught(java.lang.Throwable cause)
Description copied from interface: TransportContext
Invoked by the Transport to notify the context about an exception that has been caught while sending or processing a message.

Specified by:
exceptionCaught in interface TransportContext
Parameters:
cause - the causing exception

messageReceived

public void messageReceived(java.nio.ByteBuffer buffer)
Description copied from interface: TransportContext
Invoked by the Transport whenever new content has been received. This method is invoked whenever a new chunk of bytes arrives. There is no guarantee whatsoever that the received buffer contains a full message. Only the application knows what constitutes a message.

Specified by:
messageReceived in interface TransportContext
Parameters:
buffer - the received bytes

connectionClosed

public void connectionClosed()
Description copied from interface: TransportContext
Invoked by the Transport when the underlying physical connection has been closed.

Specified by:
connectionClosed in interface TransportContext


Copyright © 2007 null. All Rights Reserved.