org.sdnplatform.sync.internal.rpc
Class AbstractRPCChannelHandler

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelHandler
      extended by org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler
          extended by org.sdnplatform.sync.internal.rpc.AbstractRPCChannelHandler
All Implemented Interfaces:
org.jboss.netty.channel.ChannelDownstreamHandler, org.jboss.netty.channel.ChannelHandler, org.jboss.netty.channel.ChannelUpstreamHandler
Direct Known Subclasses:
BootstrapChannelHandler, RemoteSyncChannelHandler, RPCChannelHandler

public abstract class AbstractRPCChannelHandler
extends org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler

Abstract base class for implementing the RPC protocol. The protocol is defined by a thrift specification; all protocol messages are delivered in a SyncMessage which will provide specific type information.

Author:
readams

Nested Class Summary
protected static class AbstractRPCChannelHandler.ChannelState
           
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
org.jboss.netty.channel.ChannelHandler.Sharable
 
Field Summary
protected  AbstractRPCChannelHandler.ChannelState channelState
           
protected  java.lang.String currentChallenge
           
protected static org.slf4j.Logger logger
           
 
Constructor Summary
AbstractRPCChannelHandler()
           
 
Method Summary
 void channelConnected(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ChannelStateEvent e)
           
 void channelIdle(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.handler.timeout.IdleStateEvent e)
           
protected  void error(ErrorMessage error, org.jboss.netty.channel.Channel channel)
           
 void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ExceptionEvent e)
           
protected abstract  AuthScheme getAuthScheme()
          Get the type of authentication to use for this connection
protected  SyncMessage getError(int transactionId, java.lang.Exception error, MessageType type)
          Generate an error message from the provided transaction ID and exception
protected abstract  java.lang.Short getLocalNodeId()
          Get the node ID for the local node if appropriate
protected  java.lang.String getLocalNodeIdString()
          Get the node ID for the local node as a string for use output
protected abstract  java.lang.Short getRemoteNodeId()
          Get the node ID for the remote node if its connected
protected  java.lang.String getRemoteNodeIdString()
          Get the node ID for the remote node if its connected as a string for use output
protected abstract  byte[] getSharedSecret()
          Get a shared secret to be used for authentication handshake.
protected abstract  int getTransactionId()
          Get a transaction ID suitable for sending an async message
protected  void handleClusterJoinRequest(ClusterJoinRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleClusterJoinResponse(ClusterJoinResponseMessage response, org.jboss.netty.channel.Channel channel)
           
protected  void handleCursorRequest(CursorRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleCursorResponse(CursorResponseMessage response, org.jboss.netty.channel.Channel channel)
           
protected  void handleDeleteRequest(DeleteRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleDeleteResponse(DeleteResponseMessage response, org.jboss.netty.channel.Channel channel)
           
protected  void handleEchoRequest(EchoRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleError(ErrorMessage error, org.jboss.netty.channel.Channel channel)
           
protected  void handleFullSyncRequest(FullSyncRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleGetRequest(GetRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleGetResponse(GetResponseMessage response, org.jboss.netty.channel.Channel channel)
           
protected  void handleHello(HelloMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handlePutRequest(PutRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handlePutResponse(PutResponseMessage response, org.jboss.netty.channel.Channel channel)
           
protected  void handleRegisterRequest(RegisterRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleRegisterResponse(RegisterResponseMessage response, org.jboss.netty.channel.Channel channel)
           
protected  void handleSMAuthenticated(SyncMessage bsm, org.jboss.netty.channel.Channel channel)
          Handle a generic SyncMessage and dispatch to an appropriate handler
protected  void handleSyncMessage(SyncMessage bsm, org.jboss.netty.channel.Channel channel)
          Handle a generic SyncMessage and dispatch to an appropriate handler
protected  void handleSyncOffer(SyncOfferMessage message, org.jboss.netty.channel.Channel channel)
           
protected  void handleSyncRequest(SyncRequestMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handleSyncValue(SyncValueMessage message, org.jboss.netty.channel.Channel channel)
           
protected  void handleSyncValueResponse(SyncValueResponseMessage message, org.jboss.netty.channel.Channel channel)
           
protected  void handleUnknownMessage(org.jboss.netty.channel.ChannelHandlerContext ctx, java.lang.Object message)
          A handler for messages on the channel that are not of type SyncMessage
protected  void handshake(HelloMessage request, org.jboss.netty.channel.Channel channel)
           
protected  void handshakeChallengeResponse(HelloMessage request, org.jboss.netty.channel.Channel channel)
           
 void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.MessageEvent e)
           
protected  void unexpectedMessage(int transactionId, MessageType type, org.jboss.netty.channel.Channel channel)
          Send an error to the channel indicating that we got an unexpected message for this type of RPC client
 
Methods inherited from class org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler
handleUpstream
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelHandler
bindRequested, channelBound, channelClosed, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequested, writeComplete, writeRequested
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger

currentChallenge

protected java.lang.String currentChallenge

channelState

protected AbstractRPCChannelHandler.ChannelState channelState
Constructor Detail

AbstractRPCChannelHandler

public AbstractRPCChannelHandler()
Method Detail

channelConnected

public void channelConnected(org.jboss.netty.channel.ChannelHandlerContext ctx,
                             org.jboss.netty.channel.ChannelStateEvent e)
                      throws java.lang.Exception
Overrides:
channelConnected in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
java.lang.Exception

channelIdle

public void channelIdle(org.jboss.netty.channel.ChannelHandlerContext ctx,
                        org.jboss.netty.handler.timeout.IdleStateEvent e)
                 throws java.lang.Exception
Overrides:
channelIdle in class org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler
Throws:
java.lang.Exception

exceptionCaught

public void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.ExceptionEvent e)
                     throws java.lang.Exception
Overrides:
exceptionCaught in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
java.lang.Exception

messageReceived

public void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.MessageEvent e)
                     throws java.lang.Exception
Overrides:
messageReceived in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
java.lang.Exception

handleUnknownMessage

protected void handleUnknownMessage(org.jboss.netty.channel.ChannelHandlerContext ctx,
                                    java.lang.Object message)
A handler for messages on the channel that are not of type SyncMessage

Parameters:
ctx - the context
message - the message object

handleSyncMessage

protected void handleSyncMessage(SyncMessage bsm,
                                 org.jboss.netty.channel.Channel channel)
Handle a generic SyncMessage and dispatch to an appropriate handler

Parameters:
bsm - the message
channel - the channel on which the message arrived

handleSMAuthenticated

protected void handleSMAuthenticated(SyncMessage bsm,
                                     org.jboss.netty.channel.Channel channel)
Handle a generic SyncMessage and dispatch to an appropriate handler

Parameters:
bsm - the message
channel - the channel on which the message arrived

handshake

protected void handshake(HelloMessage request,
                         org.jboss.netty.channel.Channel channel)

handshakeChallengeResponse

protected void handshakeChallengeResponse(HelloMessage request,
                                          org.jboss.netty.channel.Channel channel)
                                   throws AuthException
Throws:
AuthException

error

protected void error(ErrorMessage error,
                     org.jboss.netty.channel.Channel channel)

handleHello

protected void handleHello(HelloMessage request,
                           org.jboss.netty.channel.Channel channel)

handleEchoRequest

protected void handleEchoRequest(EchoRequestMessage request,
                                 org.jboss.netty.channel.Channel channel)

handleGetRequest

protected void handleGetRequest(GetRequestMessage request,
                                org.jboss.netty.channel.Channel channel)

handleGetResponse

protected void handleGetResponse(GetResponseMessage response,
                                 org.jboss.netty.channel.Channel channel)

handlePutRequest

protected void handlePutRequest(PutRequestMessage request,
                                org.jboss.netty.channel.Channel channel)

handlePutResponse

protected void handlePutResponse(PutResponseMessage response,
                                 org.jboss.netty.channel.Channel channel)

handleDeleteRequest

protected void handleDeleteRequest(DeleteRequestMessage request,
                                   org.jboss.netty.channel.Channel channel)

handleDeleteResponse

protected void handleDeleteResponse(DeleteResponseMessage response,
                                    org.jboss.netty.channel.Channel channel)

handleSyncValue

protected void handleSyncValue(SyncValueMessage message,
                               org.jboss.netty.channel.Channel channel)

handleSyncValueResponse

protected void handleSyncValueResponse(SyncValueResponseMessage message,
                                       org.jboss.netty.channel.Channel channel)

handleSyncOffer

protected void handleSyncOffer(SyncOfferMessage message,
                               org.jboss.netty.channel.Channel channel)

handleSyncRequest

protected void handleSyncRequest(SyncRequestMessage request,
                                 org.jboss.netty.channel.Channel channel)

handleFullSyncRequest

protected void handleFullSyncRequest(FullSyncRequestMessage request,
                                     org.jboss.netty.channel.Channel channel)

handleCursorRequest

protected void handleCursorRequest(CursorRequestMessage request,
                                   org.jboss.netty.channel.Channel channel)

handleCursorResponse

protected void handleCursorResponse(CursorResponseMessage response,
                                    org.jboss.netty.channel.Channel channel)

handleRegisterRequest

protected void handleRegisterRequest(RegisterRequestMessage request,
                                     org.jboss.netty.channel.Channel channel)

handleRegisterResponse

protected void handleRegisterResponse(RegisterResponseMessage response,
                                      org.jboss.netty.channel.Channel channel)

handleClusterJoinRequest

protected void handleClusterJoinRequest(ClusterJoinRequestMessage request,
                                        org.jboss.netty.channel.Channel channel)

handleClusterJoinResponse

protected void handleClusterJoinResponse(ClusterJoinResponseMessage response,
                                         org.jboss.netty.channel.Channel channel)

handleError

protected void handleError(ErrorMessage error,
                           org.jboss.netty.channel.Channel channel)

getError

protected SyncMessage getError(int transactionId,
                               java.lang.Exception error,
                               MessageType type)
Generate an error message from the provided transaction ID and exception

Parameters:
transactionId - the transaction Id
error - the exception
type - the type of the message that generated the error
Returns:
the SyncError message

unexpectedMessage

protected void unexpectedMessage(int transactionId,
                                 MessageType type,
                                 org.jboss.netty.channel.Channel channel)
Send an error to the channel indicating that we got an unexpected message for this type of RPC client

Parameters:
transactionId - the transaction ID for the message that generated the error
type - The type of the message that generated the error
channel - the channel to write the error

getTransactionId

protected abstract int getTransactionId()
Get a transaction ID suitable for sending an async message

Returns:
the unique transaction ID

getRemoteNodeId

protected abstract java.lang.Short getRemoteNodeId()
Get the node ID for the remote node if its connected

Returns:
the node ID

getRemoteNodeIdString

protected java.lang.String getRemoteNodeIdString()
Get the node ID for the remote node if its connected as a string for use output

Returns:
the node ID

getLocalNodeId

protected abstract java.lang.Short getLocalNodeId()
Get the node ID for the local node if appropriate

Returns:
the node ID. Null if this is a client

getLocalNodeIdString

protected java.lang.String getLocalNodeIdString()
Get the node ID for the local node as a string for use output

Returns:
the node ID

getAuthScheme

protected abstract AuthScheme getAuthScheme()
Get the type of authentication to use for this connection


getSharedSecret

protected abstract byte[] getSharedSecret()
                                   throws AuthException
Get a shared secret to be used for authentication handshake. Throwing an exception will cause authentication to fail

Returns:
the shared secret
Throws:
AuthException