org.apache.cassandra.net
Class MessagingService

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

public final class MessagingService
extends java.lang.Object
implements MessagingServiceMBean


Nested Class Summary
static class MessagingService.Verb
           
 
Field Summary
static java.util.EnumMap<MessagingService.Verb,IVersionedSerializer<?>> callbackDeserializers
          A Map of what kind of serializer to wire up to a REQUEST_RESPONSE callback, based on outbound Verb.
static int current_version
           
static java.util.EnumSet<MessagingService.Verb> DROPPABLE_VERBS
          Verbs it's okay to drop if the request has been queued longer than the request timeout.
static java.lang.String MBEAN_NAME
           
static MessagingService.Verb[] VERBS
           
static java.util.EnumMap<MessagingService.Verb,IVersionedSerializer<?>> verbSerializers
          Messages we receive in IncomingTcpConnection have a Verb that tells us what kind of message it is.
static java.util.EnumMap<MessagingService.Verb,Stage> verbStages
           
static int VERSION_10
           
static int VERSION_11
           
static int VERSION_117
           
static int VERSION_12
           
 
Method Summary
 java.lang.String addCallback(IMessageCallback cb, MessageOut message, java.net.InetAddress to, long timeout)
           
 void addLatency(java.net.InetAddress address, long latency)
           
 void clearCallbacksUnsafe()
           
 java.nio.ByteBuffer constructStreamHeader(StreamHeader streamHeader, boolean compress, int version)
           
 void convict(java.net.InetAddress ep)
          called from gossiper when it notices a node is not responding.
 void destroyConnectionPool(java.net.InetAddress to)
           
static int getBits(int packed, int start, int count)
           
 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.Long> getCommandDroppedTasks()
          Dropped 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
 int getCommandPendingTasks(java.net.InetAddress address)
           
 OutboundTcpConnection getConnection(java.net.InetAddress to, MessageOut msg)
           
 OutboundTcpConnectionPool getConnectionPool(java.net.InetAddress to)
           
 java.util.Map<java.lang.String,java.lang.Integer> getDroppedMessages()
          dropped message counts for server lifetime
 java.util.Map<java.lang.String,java.lang.Integer> getRecentlyDroppedMessages()
          dropped message counts since last called
 java.util.Map<java.lang.String,java.lang.Long> getRecentTimeoutsPerHost()
          Number of timeouts since last check per host.
 long getRecentTotalTimouts()
          Number of timeouts since last check.
 CallbackInfo getRegisteredCallback(java.lang.String messageId)
           
 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
 java.util.Map<java.lang.String,java.lang.Long> getTimeoutsPerHost()
          Number of timeouts per host
 long getTotalTimeouts()
          Total number of timeouts happened on this node
 IVerbHandler getVerbHandler(MessagingService.Verb type)
          This method returns the verb handler associated with the registered verb.
 java.lang.Integer getVersion(java.net.InetAddress address)
           
 int getVersion(java.lang.String address)
           
 void incrementDroppedMessages(MessagingService.Verb verb)
           
static MessagingService instance()
           
 boolean knowsVersion(java.net.InetAddress endpoint)
           
 void listen(java.net.InetAddress localEp)
          Listen on the specified port.
 void maybeAddLatency(IMessageCallback cb, java.net.InetAddress address, long latency)
          Track latency information for the dynamic snitch
 void receive(MessageIn message, java.lang.String id, long timestamp)
           
 void register(ILatencySubscriber subcriber)
           
 void registerVerbHandlers(MessagingService.Verb verb, IVerbHandler verbHandler)
          Register a verb and the corresponding verb handler with the Messaging Service.
 CallbackInfo removeRegisteredCallback(java.lang.String messageId)
           
 void resetVersion(java.net.InetAddress endpoint)
           
 void sendOneWay(MessageOut message, java.net.InetAddress to)
           
 void sendOneWay(MessageOut message, java.lang.String id, java.net.InetAddress to)
          Send a message to a given endpoint.
 void sendReply(MessageOut message, java.lang.String id, java.net.InetAddress to)
           
<T> IAsyncResult<T>
sendRR(MessageOut message, java.net.InetAddress to)
           
 java.lang.String sendRR(MessageOut message, java.net.InetAddress to, IMessageCallback cb)
           
 java.lang.String sendRR(MessageOut message, java.net.InetAddress to, IMessageCallback cb, long timeout)
          Send a message to a given endpoint.
 void setCallbackForTests(java.lang.String messageId, CallbackInfo callback)
           
 int setVersion(java.net.InetAddress address, int version)
           
 void shutdown()
          Wait for callbacks and don't allow any more to be created (since they could require writing hints)
 void stream(StreamHeader header, java.net.InetAddress to)
          Stream a file from source to destination.
static void validateMagic(int magic)
           
 void waitForStreaming()
           
 void waitUntilListening()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MBEAN_NAME

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

VERSION_10

public static final int VERSION_10
See Also:
Constant Field Values

VERSION_11

public static final int VERSION_11
See Also:
Constant Field Values

VERSION_117

public static final int VERSION_117
See Also:
Constant Field Values

VERSION_12

public static final int VERSION_12
See Also:
Constant Field Values

current_version

public static final int current_version
See Also:
Constant Field Values

VERBS

public static final MessagingService.Verb[] VERBS

verbStages

public static final java.util.EnumMap<MessagingService.Verb,Stage> verbStages

verbSerializers

public static final java.util.EnumMap<MessagingService.Verb,IVersionedSerializer<?>> verbSerializers
Messages we receive in IncomingTcpConnection have a Verb that tells us what kind of message it is. Most of the time, this is enough to determine how to deserialize the message payload. The exception is the REQUEST_RESPONSE verb, which just means "a reply to something you told me to do." Traditionally, this was fine since each VerbHandler knew what type of payload it expected, and handled the deserialization itself. Now that we do that in ITC, to avoid the extra copy to an intermediary byte[] (See CASSANDRA-3716), we need to wire that up to the CallbackInfo object (see below).


callbackDeserializers

public static final java.util.EnumMap<MessagingService.Verb,IVersionedSerializer<?>> callbackDeserializers
A Map of what kind of serializer to wire up to a REQUEST_RESPONSE callback, based on outbound Verb.


DROPPABLE_VERBS

public static final java.util.EnumSet<MessagingService.Verb> DROPPABLE_VERBS
Verbs it's okay to drop if the request has been queued longer than the request timeout. These all correspond to client requests or something triggered by them; we don't want to drop internal messages like bootstrap or repair notifications.

Method Detail

instance

public static MessagingService instance()

maybeAddLatency

public void maybeAddLatency(IMessageCallback cb,
                            java.net.InetAddress address,
                            long latency)
Track latency information for the dynamic snitch

Parameters:
cb - the callback associated with this message -- this lets us know if it's a message type we're interested in
address - the host that replied to the message
latency -

addLatency

public void addLatency(java.net.InetAddress address,
                       long latency)

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 ConfigurationException
Listen on the specified port.

Parameters:
localEp - InetAddress whose port to listen on.
Throws:
ConfigurationException

waitUntilListening

public void waitUntilListening()

destroyConnectionPool

public void destroyConnectionPool(java.net.InetAddress to)

getConnectionPool

public OutboundTcpConnectionPool getConnectionPool(java.net.InetAddress to)

getConnection

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

registerVerbHandlers

public void registerVerbHandlers(MessagingService.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(MessagingService.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

addCallback

public java.lang.String addCallback(IMessageCallback cb,
                                    MessageOut message,
                                    java.net.InetAddress to,
                                    long timeout)

sendRR

public java.lang.String sendRR(MessageOut message,
                               java.net.InetAddress to,
                               IMessageCallback cb)

sendRR

public java.lang.String sendRR(MessageOut message,
                               java.net.InetAddress to,
                               IMessageCallback cb,
                               long timeout)
Send a message to a given endpoint. This method specifies a callback which is invoked with the actual response. Also holds the message (only mutation messages) to determine if it needs to trigger a hint (uses StorageProxy for that).

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().
timeout - the timeout used for expiration
Returns:
an reference to message id used to match with the result

sendOneWay

public void sendOneWay(MessageOut message,
                       java.net.InetAddress to)

sendReply

public void sendReply(MessageOut message,
                      java.lang.String id,
                      java.net.InetAddress to)

sendOneWay

public void sendOneWay(MessageOut message,
                       java.lang.String id,
                       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 <T> IAsyncResult<T> sendRR(MessageOut 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)

clearCallbacksUnsafe

public void clearCallbacksUnsafe()

waitForStreaming

public void waitForStreaming()
                      throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

shutdown

public void shutdown()
Wait for callbacks and don't allow any more to be created (since they could require writing hints)


receive

public void receive(MessageIn message,
                    java.lang.String id,
                    long timestamp)

setCallbackForTests

public void setCallbackForTests(java.lang.String messageId,
                                CallbackInfo callback)

getRegisteredCallback

public CallbackInfo getRegisteredCallback(java.lang.String messageId)

removeRegisteredCallback

public CallbackInfo removeRegisteredCallback(java.lang.String messageId)

getRegisteredCallbackAge

public long getRegisteredCallbackAge(java.lang.String messageId)

validateMagic

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

getBits

public static int getBits(int packed,
                          int start,
                          int count)

constructStreamHeader

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

setVersion

public int setVersion(java.net.InetAddress address,
                      int version)
Returns:
the last version associated with address, or @param version if this is the first such version

resetVersion

public void resetVersion(java.net.InetAddress endpoint)

getVersion

public java.lang.Integer getVersion(java.net.InetAddress address)

getVersion

public int getVersion(java.lang.String address)
               throws java.net.UnknownHostException
Specified by:
getVersion in interface MessagingServiceMBean
Throws:
java.net.UnknownHostException

knowsVersion

public boolean knowsVersion(java.net.InetAddress endpoint)

incrementDroppedMessages

public void incrementDroppedMessages(MessagingService.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

getCommandPendingTasks

public int getCommandPendingTasks(java.net.InetAddress address)

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

getCommandDroppedTasks

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

Specified by:
getCommandDroppedTasks 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

getDroppedMessages

public java.util.Map<java.lang.String,java.lang.Integer> getDroppedMessages()
Description copied from interface: MessagingServiceMBean
dropped message counts for server lifetime

Specified by:
getDroppedMessages in interface MessagingServiceMBean

getRecentlyDroppedMessages

public java.util.Map<java.lang.String,java.lang.Integer> getRecentlyDroppedMessages()
Description copied from interface: MessagingServiceMBean
dropped message counts since last called

Specified by:
getRecentlyDroppedMessages in interface MessagingServiceMBean

getTotalTimeouts

public long getTotalTimeouts()
Description copied from interface: MessagingServiceMBean
Total number of timeouts happened on this node

Specified by:
getTotalTimeouts in interface MessagingServiceMBean

getRecentTotalTimouts

public long getRecentTotalTimouts()
Description copied from interface: MessagingServiceMBean
Number of timeouts since last check.

Specified by:
getRecentTotalTimouts in interface MessagingServiceMBean

getTimeoutsPerHost

public java.util.Map<java.lang.String,java.lang.Long> getTimeoutsPerHost()
Description copied from interface: MessagingServiceMBean
Number of timeouts per host

Specified by:
getTimeoutsPerHost in interface MessagingServiceMBean

getRecentTimeoutsPerHost

public java.util.Map<java.lang.String,java.lang.Long> getRecentTimeoutsPerHost()
Description copied from interface: MessagingServiceMBean
Number of timeouts since last check per host.

Specified by:
getRecentTimeoutsPerHost in interface MessagingServiceMBean


Copyright © 2012 The Apache Software Foundation