net.sf.beep4j.internal.profile
Class ChannelManagementProfileImpl

java.lang.Object
  extended by net.sf.beep4j.internal.profile.ChannelManagementProfileImpl
All Implemented Interfaces:
ChannelHandler, ChannelManagementProfile

public class ChannelManagementProfileImpl
extends java.lang.Object
implements ChannelHandler, ChannelManagementProfile

Implementation of ChannelManagementProfile interface.

Author:
Simon Raess

Constructor Summary
ChannelManagementProfileImpl(boolean initiator)
           
 
Method Summary
 void channelClosed()
          Invoked by the framework when the other peer decided to close this channel.
 void channelCloseRequested(CloseChannelRequest request)
          Invoked by the framework when the other peer requested to close the channel.
 void channelOpened(Channel c)
          Invoked by the framework when the channel has been successfully started.
 void channelStartFailed(int code, java.lang.String message)
          This method is only called on channels created through the startChannel methods of the Session.
 void closeChannel(int channelNumber, CloseChannelCallback callback)
          Send a close channel message.
 void closeSession(CloseCallback callback)
          Closes the session.
 boolean connectionEstablished(java.net.SocketAddress address, SessionHandler sessionHandler, Reply response)
          Invoked by the session when the connection has been established.
 ChannelHandler createChannelHandler(SessionManager manager)
          Invoked by the framework to initialize the channel and to get the ChannelHandler for the profile.
protected  ChannelManagementMessageBuilder createChannelManagementMessageBuilder()
           
protected  ChannelManagementMessageParser createChannelManagementMessageParser()
           
 Message createError(int code, java.lang.String diagnostics)
           
 Message createGreeting(java.lang.String[] profiles)
           
protected  MessageBuilder createMessageBuilder()
           
 void messageReceived(Message message, Reply handler)
          Invoked by the framework when the other peer sent a message to this peer on this channel.
 BEEPError receivedError(Message message)
          Invoked by the session when an error has been received during the session startup.
 Greeting receivedGreeting(Message message)
          Invoked by the session when a greeting has been received during the session startup.
 void startChannel(int channelNumber, ProfileInfo[] infos, StartChannelCallback callback)
          Sends a start channel message to the other peer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChannelManagementProfileImpl

public ChannelManagementProfileImpl(boolean initiator)
Method Detail

createChannelManagementMessageBuilder

protected ChannelManagementMessageBuilder createChannelManagementMessageBuilder()

createChannelManagementMessageParser

protected ChannelManagementMessageParser createChannelManagementMessageParser()

createMessageBuilder

protected MessageBuilder createMessageBuilder()

channelStartFailed

public void channelStartFailed(int code,
                               java.lang.String message)
This method is only called on channels created through the startChannel methods of the Session. Thus, this method can safely throw an UnsupportedOperationException because it is never called. The channel management profile is created by the session itself when it starts up.

Specified by:
channelStartFailed in interface ChannelHandler
Parameters:
code - the error code
message - the human readable error message
Throws:
java.lang.UnsupportedOperationException - unconditionally

channelOpened

public void channelOpened(Channel c)
Description copied from interface: ChannelHandler
Invoked by the framework when the channel has been successfully started.

Specified by:
channelOpened in interface ChannelHandler
Parameters:
c - the channel that was opened

messageReceived

public void messageReceived(Message message,
                            Reply handler)
Description copied from interface: ChannelHandler
Invoked by the framework when the other peer sent a message to this peer on this channel.

Specified by:
messageReceived in interface ChannelHandler
Parameters:
message - the received message
handler - the handler used to return a response.

channelCloseRequested

public void channelCloseRequested(CloseChannelRequest request)
Description copied from interface: ChannelHandler
Invoked by the framework when the other peer requested to close the channel.

Specified by:
channelCloseRequested in interface ChannelHandler
Parameters:
request - the request

channelClosed

public void channelClosed()
Description copied from interface: ChannelHandler
Invoked by the framework when the other peer decided to close this channel.

Specified by:
channelClosed in interface ChannelHandler

createChannelHandler

public ChannelHandler createChannelHandler(SessionManager manager)
Description copied from interface: ChannelManagementProfile
Invoked by the framework to initialize the channel and to get the ChannelHandler for the profile.

Specified by:
createChannelHandler in interface ChannelManagementProfile
Parameters:
manager - the SessionManager to be used by the profile
Returns:
the ChannelHandler for the profile

connectionEstablished

public boolean connectionEstablished(java.net.SocketAddress address,
                                     SessionHandler sessionHandler,
                                     Reply response)
Description copied from interface: ChannelManagementProfile
Invoked by the session when the connection has been established. The profile must pass this event to the SessionHandler. Depending on the response of the application, either a greeting or an error is sent to the ResponseHandler.

Specified by:
connectionEstablished in interface ChannelManagementProfile
Parameters:
address - address of remote peer
sessionHandler - the SessionHandler of the session
response - the ResponseHandler to be used to generate a response
Returns:
true iff the connection is established. Returning false from this method will drop the connection.

createGreeting

public Message createGreeting(java.lang.String[] profiles)

createError

public Message createError(int code,
                           java.lang.String diagnostics)

receivedGreeting

public Greeting receivedGreeting(Message message)
Description copied from interface: ChannelManagementProfile
Invoked by the session when a greeting has been received during the session startup. Parses the given message into a Greeting object.

Specified by:
receivedGreeting in interface ChannelManagementProfile
Parameters:
message - the message to be parsed
Returns:
the parsed Greeting object

receivedError

public BEEPError receivedError(Message message)
Description copied from interface: ChannelManagementProfile
Invoked by the session when an error has been received during the session startup. Parses the given message into a BEEPError object.

Specified by:
receivedError in interface ChannelManagementProfile
Parameters:
message - the message to be parsed
Returns:
the parsed BEEPError object

startChannel

public void startChannel(int channelNumber,
                         ProfileInfo[] infos,
                         StartChannelCallback callback)
Description copied from interface: ChannelManagementProfile
Sends a start channel message to the other peer.

Specified by:
startChannel in interface ChannelManagementProfile
Parameters:
channelNumber - the channel number of the new peer
infos - the ProfileInfos to be passed inside the profile element in the request
callback - the callback that is invoked when the response is received

closeChannel

public void closeChannel(int channelNumber,
                         CloseChannelCallback callback)
Description copied from interface: ChannelManagementProfile
Send a close channel message. The corresponding method is invoked on the callback to notify this peer about the outcome of the close request.

Specified by:
closeChannel in interface ChannelManagementProfile
Parameters:
channelNumber - the channel to be closed
callback - the callback that is invoked when the response is received

closeSession

public void closeSession(CloseCallback callback)
Description copied from interface: ChannelManagementProfile
Closes the session. The BEEP specification notes that it is possible for a BEEP peer to decline session closing. However, this does not seem to make a lot of sense. So, if this method is invoked, the session is always closed.

Specified by:
closeSession in interface ChannelManagementProfile
Parameters:
callback - the callback used to notify about the response


Copyright © 2007 null. All Rights Reserved.