org.apache.cassandra.net
Class MessagingService

java.lang.Object
  extended by org.apache.cassandra.net.MessagingService
All Implemented Interfaces:
IMessagingService

public class MessagingService
extends java.lang.Object
implements IMessagingService


Field Summary
static java.lang.String responseStage_
           
static java.lang.String responseVerbHandler_
           
 
Constructor Summary
protected MessagingService()
           
 
Method Summary
static int byteArrayToInt(byte[] bytes)
           
static int byteArrayToInt(byte[] bytes, int offset)
           
static short byteArrayToShort(byte[] bytes)
           
static short byteArrayToShort(byte[] bytes, int offset)
           
 java.lang.Object clone()
           
static java.nio.ByteBuffer constructStreamHeader(boolean compress, boolean stream)
           
static void debugOn(boolean on)
           
 void deregisterAllVerbHandlers(EndPoint localEndPoint)
          Deregister all verbhandlers corresponding to localEndPoint.
 void deregisterVerbHandlers(java.lang.String type)
          Deregister a verbhandler corresponding to the verb from the Messaging Service.
static void flushAndshutdown()
           
static IAsyncResult getAsyncResult(java.lang.String key)
           
static int getBits(int x, int p, int n)
           
static TcpConnection getConnection(EndPoint from, EndPoint to)
           
static org.apache.cassandra.net.TcpConnectionManager getConnectionPool(EndPoint from, EndPoint to)
           
static java.util.concurrent.ExecutorService getDeserializationExecutor()
           
static IMessagingService getMessagingInstance()
           
static ConnectionStatistics[] getPoolStatistics()
           
static byte[] getProtocol()
           
static java.util.concurrent.ExecutorService getReadExecutor()
           
static IAsyncCallback getRegisteredCallback(java.lang.String key)
           
static SerializerType getSerializerType()
           
 IVerbHandler getVerbHandler(java.lang.String type)
          This method returns the verb handler associated with the registered verb.
static int getVersion()
           
static java.util.concurrent.ExecutorService getWriteExecutor()
           
 byte[] hash(java.lang.String type, byte[] data)
           
static boolean isDebugOn()
           
static boolean isEqual(byte[] digestA, byte[] digestB)
           
static boolean isLocalEndPoint(EndPoint ep)
           
static boolean isProtocolValid(byte[] protocol)
           
static boolean isStreaming()
           
 void listen(EndPoint localEp)
          Listen on the specified port.
 void listenUDP(EndPoint localEp)
          Listen on the specified port.
static java.nio.ByteBuffer packIt(byte[] bytes, boolean compress, boolean stream, boolean listening)
           
static void receive(Message message)
           
 void registerVerbHandlers(java.lang.String type, IVerbHandler verbHandler)
          Register a verb and the corresponding verb handler with the Messaging Service.
static void removeAsyncResult(java.lang.String key)
           
static void removeRegisteredCallback(java.lang.String key)
           
 void sendOneWay(Message message, EndPoint to)
          Send a message to a given endpoint.
 java.lang.String sendRR(Message[][] messages, EndPoint[][] to, IAsyncCallback cb)
          Send a message to a given endpoint.
 java.lang.String sendRR(Message[] messages, EndPoint[] to, IAsyncCallback cb)
          Send a message to a given endpoint.
 IAsyncResult sendRR(Message message, EndPoint to)
          Send a message to a given endpoint.
 java.lang.String sendRR(Message message, EndPoint[] to, IAsyncCallback cb)
          Send a message to the given set of endpoints and informs the MessagingService to wait for at least howManyResults responses to determine success of failure.
 java.lang.String sendRR(Message message, EndPoint to, IAsyncCallback cb)
          Send a message to a given endpoint.
 void sendUdpOneWay(Message message, EndPoint to)
          Send a message to a given endpoint.
static void serializerType(java.lang.String type)
           
static void setStreamingMode(boolean bVal)
           
static void setVersion(int version)
           
static void shutdown()
           
 void stream(java.lang.String file, long startPosition, long total, EndPoint from, EndPoint to)
          Stream a file from source to destination.
static byte[] toByteArray(int i)
           
static byte[] toByteArray(short s)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

responseVerbHandler_

public static final java.lang.String responseVerbHandler_
See Also:
Constant Field Values

responseStage_

public static final java.lang.String responseStage_
See Also:
Constant Field Values
Constructor Detail

MessagingService

protected MessagingService()
Method Detail

isDebugOn

public static boolean isDebugOn()

debugOn

public static void debugOn(boolean on)

getSerializerType

public static SerializerType getSerializerType()

serializerType

public static void serializerType(java.lang.String type)

getVersion

public static int getVersion()

setVersion

public static void setVersion(int version)

getMessagingInstance

public static IMessagingService getMessagingInstance()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

hash

public byte[] hash(java.lang.String type,
                   byte[] data)

listen

public void listen(EndPoint localEp)
            throws java.io.IOException
Description copied from interface: IMessagingService
Listen on the specified port.

Specified by:
listen in interface IMessagingService
Parameters:
localEp - EndPoint whose port to listen on.
Throws:
java.io.IOException

listenUDP

public void listenUDP(EndPoint localEp)
Description copied from interface: IMessagingService
Listen on the specified port.

Specified by:
listenUDP in interface IMessagingService
Parameters:
localEp - EndPoint whose port to listen on.

getConnectionPool

public static org.apache.cassandra.net.TcpConnectionManager getConnectionPool(EndPoint from,
                                                                              EndPoint to)

getPoolStatistics

public static ConnectionStatistics[] getPoolStatistics()

getConnection

public static TcpConnection getConnection(EndPoint from,
                                          EndPoint to)
                                   throws java.io.IOException
Throws:
java.io.IOException

registerVerbHandlers

public void registerVerbHandlers(java.lang.String type,
                                 IVerbHandler verbHandler)
Description copied from interface: IMessagingService
Register a verb and the corresponding verb handler with the Messaging Service.

Specified by:
registerVerbHandlers in interface IMessagingService
Parameters:
type - name of the verb.
verbHandler - handler for the specified verb

deregisterAllVerbHandlers

public void deregisterAllVerbHandlers(EndPoint localEndPoint)
Description copied from interface: IMessagingService
Deregister all verbhandlers corresponding to localEndPoint.

Specified by:
deregisterAllVerbHandlers in interface IMessagingService

deregisterVerbHandlers

public void deregisterVerbHandlers(java.lang.String type)
Description copied from interface: IMessagingService
Deregister a verbhandler corresponding to the verb from the Messaging Service.

Specified by:
deregisterVerbHandlers in interface IMessagingService
Parameters:
type - name of the verb.

getVerbHandler

public IVerbHandler getVerbHandler(java.lang.String type)
Description copied from interface: IMessagingService
This method returns the verb handler associated with the registered verb. If no handler has been registered then null is returned.

Specified by:
getVerbHandler in interface IMessagingService
Parameters:
type - for which the verb handler is sought
Returns:
a reference to IVerbHandler which is the handler for the specified verb

sendRR

public java.lang.String sendRR(Message message,
                               EndPoint[] to,
                               IAsyncCallback cb)
Description copied from interface: IMessagingService
Send a message to the given set of endpoints and informs the MessagingService to wait for at least howManyResults responses to determine success of failure.

Specified by:
sendRR in interface IMessagingService
Parameters:
message - message to be sent.
to - endpoints to which the message needs to be sent
cb - callback interface which is used to pass the responses
Returns:
an reference to message id used to match with the result

sendRR

public java.lang.String sendRR(Message message,
                               EndPoint to,
                               IAsyncCallback cb)
Description copied from interface: IMessagingService
Send a message to a given endpoint. This method specifies a callback which is invoked with the actual response.

Specified by:
sendRR in interface IMessagingService
Parameters:
message - message to be sent.
to - endpoint to which the message needs to be sent
cb - callback interface which is used to pass the responses or suggest that a timeout occurred to the invoker of the send(). suggest that a timeout occurred to the invoker of the send().
Returns:
an reference to message id used to match with the result

sendRR

public java.lang.String sendRR(Message[] messages,
                               EndPoint[] to,
                               IAsyncCallback cb)
Description copied from interface: IMessagingService
Send a message to a given endpoint. The ith element in the messages array is sent to the ith element in the to array.This method assumes there is a one-one mapping between the messages array and the to array. Otherwise an IllegalArgumentException will be thrown. This method also informs the MessagingService to wait for at least howManyResults responses to determine success of failure.

Specified by:
sendRR in interface IMessagingService
Parameters:
messages - messages to be sent.
to - endpoints to which the message needs to be sent
cb - callback interface which is used to pass the responses or suggest that a timeout occured to the invoker of the send().
Returns:
an reference to message id used to match with the result

sendRR

public java.lang.String sendRR(Message[][] messages,
                               EndPoint[][] to,
                               IAsyncCallback cb)
Description copied from interface: IMessagingService
Send a message to a given endpoint. The ith element in the messages array is sent to the ith element in the to array.This method assumes there is a one-one mapping between the messages array and the to array. Otherwise an IllegalArgumentException will be thrown. The idea is that multi-groups of messages are grouped as one logical message whose results are harnessed via the IAsyncResult

Specified by:
sendRR in interface IMessagingService
Parameters:
messages - groups of grouped messages.
to - destination for the groups of messages
cb - the callback handler to be invoked for the responses
Returns:
the group id which is basically useless - it is only returned for API's to look compatible.

sendOneWay

public void sendOneWay(Message message,
                       EndPoint to)
Description copied from interface: IMessagingService
Send a message to a given endpoint. This method adheres to the fire and forget style messaging.

Specified by:
sendOneWay in interface IMessagingService
Parameters:
message - messages to be sent.
to - endpoint to which the message needs to be sent

sendRR

public IAsyncResult sendRR(Message message,
                           EndPoint to)
Description copied from interface: IMessagingService
Send a message to a given endpoint.

Specified by:
sendRR in interface IMessagingService
Parameters:
message - message to be sent.
to - endpoint to which the message needs to be sent
Returns:
an reference to an IAsyncResult which can be queried for the response

sendUdpOneWay

public void sendUdpOneWay(Message message,
                          EndPoint to)
Description copied from interface: IMessagingService
Send a message to a given endpoint. This method adheres to the fire and forget style messaging.

Specified by:
sendUdpOneWay in interface IMessagingService
Parameters:
message - messages to be sent.
to - endpoint to which the message needs to be sent

stream

public void stream(java.lang.String file,
                   long startPosition,
                   long total,
                   EndPoint from,
                   EndPoint to)
Description copied from interface: IMessagingService
Stream a file from source to destination. This is highly optimized to not hold any of the contents of the file in memory.

Specified by:
stream in interface IMessagingService
Parameters:
file - name of file to stream.
startPosition - position inside the file
total - number of bytes to stream
to - endpoint to which we need to stream the file.

isStreaming

public static boolean isStreaming()

setStreamingMode

public static void setStreamingMode(boolean bVal)

flushAndshutdown

public static void flushAndshutdown()

shutdown

public static void shutdown()

receive

public static void receive(Message message)

isLocalEndPoint

public static boolean isLocalEndPoint(EndPoint ep)

getRegisteredCallback

public static IAsyncCallback getRegisteredCallback(java.lang.String key)

removeRegisteredCallback

public static void removeRegisteredCallback(java.lang.String key)

getAsyncResult

public static IAsyncResult getAsyncResult(java.lang.String key)

removeAsyncResult

public static void removeAsyncResult(java.lang.String key)

getProtocol

public static byte[] getProtocol()

getReadExecutor

public static java.util.concurrent.ExecutorService getReadExecutor()

getWriteExecutor

public static java.util.concurrent.ExecutorService getWriteExecutor()

getDeserializationExecutor

public static java.util.concurrent.ExecutorService getDeserializationExecutor()

isProtocolValid

public static boolean isProtocolValid(byte[] protocol)

isEqual

public static boolean isEqual(byte[] digestA,
                              byte[] digestB)

toByteArray

public static byte[] toByteArray(int i)

toByteArray

public static byte[] toByteArray(short s)

byteArrayToShort

public static short byteArrayToShort(byte[] bytes)

byteArrayToShort

public static short byteArrayToShort(byte[] bytes,
                                     int offset)

getBits

public static int getBits(int x,
                          int p,
                          int n)

byteArrayToInt

public static int byteArrayToInt(byte[] bytes)

byteArrayToInt

public static int byteArrayToInt(byte[] bytes,
                                 int offset)

packIt

public static java.nio.ByteBuffer packIt(byte[] bytes,
                                         boolean compress,
                                         boolean stream,
                                         boolean listening)

constructStreamHeader

public static java.nio.ByteBuffer constructStreamHeader(boolean compress,
                                                        boolean stream)


Copyright © 2009 The Apache Software Foundation