org.apache.cassandra.net
Class MessagingService

java.lang.Object
  extended by org.apache.cassandra.net.MessagingService
All Implemented Interfaces:
ILatencyPublisher, MessagingServiceMBean

public class MessagingService
extends java.lang.Object
implements MessagingServiceMBean, ILatencyPublisher


Field Summary
static MessagingService instance
           
static int PROTOCOL_MAGIC
          we preface every message with this number so the recipient can validate the sender is sane
 
Constructor Summary
protected MessagingService()
           
 
Method Summary
 void addCallback(IAsyncCallback cb, java.lang.String messageId)
           
 java.lang.Object clone()
           
static java.nio.ByteBuffer constructStreamHeader(StreamHeader streamHeader, boolean compress)
           
 void convict(java.net.InetAddress ep)
          called from gossiper when it notices a node is not responding.
static int getBits(int x, int p, int n)
           
 java.util.Map<java.lang.String,java.lang.Long> getCommandCompletedTasks()
          Completed tasks for Command(Mutations, Read etc) TCP Connections
 java.util.Map<java.lang.String,java.lang.Integer> getCommandPendingTasks()
          Pending tasks for Command(Mutations, Read etc) TCP Connections
static OutboundTcpConnection getConnection(java.net.InetAddress to, Message msg)
           
static org.apache.cassandra.net.OutboundTcpConnectionPool getConnectionPool(java.net.InetAddress to)
           
static IMessageCallback getRegisteredCallback(java.lang.String messageId)
           
static long getRegisteredCallbackAge(java.lang.String messageId)
           
 java.util.Map<java.lang.String,java.lang.Long> getResponseCompletedTasks()
          Completed tasks for Response(GOSSIP & RESPONSE) TCP Connections
 java.util.Map<java.lang.String,java.lang.Integer> getResponsePendingTasks()
          Pending tasks for Response(GOSSIP & RESPONSE) TCP Connections
 IVerbHandler getVerbHandler(StorageService.Verb type)
          This method returns the verb handler associated with the registered verb.
 byte[] hash(java.lang.String type, byte[] data)
           
static int incrementDroppedMessages(StorageService.Verb verb)
           
 void listen(java.net.InetAddress localEp)
          Listen on the specified port.
static java.nio.ByteBuffer packIt(byte[] bytes, boolean compress)
           
static void receive(Message message)
           
 void register(ILatencySubscriber subcriber)
           
 void registerVerbHandlers(StorageService.Verb verb, IVerbHandler verbHandler)
          Register a verb and the corresponding verb handler with the Messaging Service.
static IMessageCallback removeRegisteredCallback(java.lang.String messageId)
           
static void responseReceivedFrom(java.lang.String messageId, java.net.InetAddress from)
           
 void sendOneWay(Message message, java.net.InetAddress to)
          Send a message to a given endpoint.
 java.lang.String sendRR(Message[] messages, java.util.List<java.net.InetAddress> to, IAsyncCallback cb)
          Send a message to a given endpoint.
 java.lang.String sendRR(Message message, java.util.Collection<java.net.InetAddress> to, IAsyncCallback cb)
          Send a message to a given endpoint.
 IAsyncResult sendRR(Message message, java.net.InetAddress to)
           
 java.lang.String sendRR(Message message, java.net.InetAddress to, IAsyncCallback cb)
          Send a message to a given endpoint.
static void shutdown()
           
 void stream(StreamHeader header, java.net.InetAddress to)
          Stream a file from source to destination.
static void validateMagic(int magic)
           
static void waitFor()
          blocks until the processing pools are empty and done.
 void waitUntilListening()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_MAGIC

public static final int PROTOCOL_MAGIC
we preface every message with this number so the recipient can validate the sender is sane

See Also:
Constant Field Values

instance

public static final MessagingService instance
Constructor Detail

MessagingService

protected MessagingService()
Method Detail

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)

convict

public void convict(java.net.InetAddress ep)
called from gossiper when it notices a node is not responding.


listen

public void listen(java.net.InetAddress localEp)
            throws java.io.IOException
Listen on the specified port.

Parameters:
localEp - InetAddress whose port to listen on.
Throws:
java.io.IOException

waitUntilListening

public void waitUntilListening()

getConnectionPool

public static org.apache.cassandra.net.OutboundTcpConnectionPool getConnectionPool(java.net.InetAddress to)

getConnection

public static OutboundTcpConnection getConnection(java.net.InetAddress to,
                                                  Message msg)

registerVerbHandlers

public void registerVerbHandlers(StorageService.Verb verb,
                                 IVerbHandler verbHandler)
Register a verb and the corresponding verb handler with the Messaging Service.

Parameters:
verb -
verbHandler - handler for the specified verb

getVerbHandler

public IVerbHandler getVerbHandler(StorageService.Verb type)
This method returns the verb handler associated with the registered verb. If no handler has been registered then null is returned.

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,
                               java.util.Collection<java.net.InetAddress> to,
                               IAsyncCallback cb)
Send a message to a given endpoint.

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

addCallback

public void addCallback(IAsyncCallback cb,
                        java.lang.String messageId)

sendRR

public java.lang.String sendRR(Message message,
                               java.net.InetAddress to,
                               IAsyncCallback cb)
Send a message to a given endpoint. This method specifies a callback which is invoked with the actual response.

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,
                               java.util.List<java.net.InetAddress> to,
                               IAsyncCallback cb)
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.

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

sendOneWay

public void sendOneWay(Message message,
                       java.net.InetAddress to)
Send a message to a given endpoint. This method adheres to the fire and forget style messaging.

Parameters:
message - messages to be sent.
to - endpoint to which the message needs to be sent

sendRR

public IAsyncResult sendRR(Message message,
                           java.net.InetAddress to)

stream

public void stream(StreamHeader header,
                   java.net.InetAddress to)
Stream a file from source to destination. This is highly optimized to not hold any of the contents of the file in memory.

Parameters:
header - Header contains file to stream and other metadata.
to - endpoint to which we need to stream the file.

register

public void register(ILatencySubscriber subcriber)
Specified by:
register in interface ILatencyPublisher

waitFor

public static void waitFor()
                    throws java.lang.InterruptedException
blocks until the processing pools are empty and done.

Throws:
java.lang.InterruptedException

shutdown

public static void shutdown()

receive

public static void receive(Message message)

getRegisteredCallback

public static IMessageCallback getRegisteredCallback(java.lang.String messageId)

removeRegisteredCallback

public static IMessageCallback removeRegisteredCallback(java.lang.String messageId)

getRegisteredCallbackAge

public static long getRegisteredCallbackAge(java.lang.String messageId)

responseReceivedFrom

public static void responseReceivedFrom(java.lang.String messageId,
                                        java.net.InetAddress from)

validateMagic

public static void validateMagic(int magic)
                          throws java.io.IOException
Throws:
java.io.IOException

getBits

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

packIt

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

constructStreamHeader

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

incrementDroppedMessages

public static int incrementDroppedMessages(StorageService.Verb verb)

getCommandPendingTasks

public java.util.Map<java.lang.String,java.lang.Integer> getCommandPendingTasks()
Description copied from interface: MessagingServiceMBean
Pending tasks for Command(Mutations, Read etc) TCP Connections

Specified by:
getCommandPendingTasks in interface MessagingServiceMBean

getCommandCompletedTasks

public java.util.Map<java.lang.String,java.lang.Long> getCommandCompletedTasks()
Description copied from interface: MessagingServiceMBean
Completed tasks for Command(Mutations, Read etc) TCP Connections

Specified by:
getCommandCompletedTasks in interface MessagingServiceMBean

getResponsePendingTasks

public java.util.Map<java.lang.String,java.lang.Integer> getResponsePendingTasks()
Description copied from interface: MessagingServiceMBean
Pending tasks for Response(GOSSIP & RESPONSE) TCP Connections

Specified by:
getResponsePendingTasks in interface MessagingServiceMBean

getResponseCompletedTasks

public java.util.Map<java.lang.String,java.lang.Long> getResponseCompletedTasks()
Description copied from interface: MessagingServiceMBean
Completed tasks for Response(GOSSIP & RESPONSE) TCP Connections

Specified by:
getResponseCompletedTasks in interface MessagingServiceMBean


Copyright © 2011 The Apache Software Foundation