org.apache.cassandra.net

## Class MessagingService

- java.lang.Object
- - org.apache.cassandra.net.MessagingService

All Implemented Interfaces:
  MessagingServiceMBean

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

### Nested Class Summary

Nested Classes
`static class` `MessagingService.SocketThread`
`static class` `MessagingService.Verb`

### Field Summary

Fields
`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` `FAILURE_CALLBACK_PARAM`
`static java.lang.String` `FAILURE_RESPONSE_PARAM`
`static java.lang.String` `MBEAN_NAME`
`static byte[]` `ONE_BYTE`
`static int` `PROTOCOL_MAGIC` we preface every message with this number so the recipient can validate the sender is sane
`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_12`
`static int` `VERSION_20`
`static int` `VERSION_21`
`static int` `VERSION_22`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`int` `addCallback(IAsyncCallback cb, MessageOut<?> message, java.net.InetAddress to, long timeout, ConsistencyLevel consistencyLevel, boolean allowHints)`
`int` `addCallback(IAsyncCallback cb, MessageOut message, java.net.InetAddress to, long timeout, boolean failureCallback)`
`void` `addLatency(java.net.InetAddress address, long latency)`
`void` `addMessageSink(IMessageSink sink)`
`boolean` `areAllNodesAtLeast22()`
`void` `clearCallbacksUnsafe()`
`void` `clearMessageSinks()`
`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)`
`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.Long>` `getGossipMessageCompletedTasks()` Completed tasks for gossip message TCP Connections
`java.util.Map<java.lang.String,java.lang.Long>` `getGossipMessageDroppedTasks()` Dropped tasks for gossip message TCP Connections
`java.util.Map<java.lang.String,java.lang.Integer>` `getGossipMessagePendingTasks()` Pending tasks for gossip message TCP Connections
`java.util.Map<java.lang.String,java.lang.Long>` `getLargeMessageCompletedTasks()` Completed tasks for large message) TCP Connections
`java.util.Map<java.lang.String,java.lang.Long>` `getLargeMessageDroppedTasks()` Dropped tasks for large message TCP Connections
`java.util.Map<java.lang.String,java.lang.Integer>` `getLargeMessagePendingTasks()` Pending tasks for large message TCP Connections
`int` `getLargeMessagePendingTasks(java.net.InetAddress address)`
`int` `getRawVersion(java.net.InetAddress endpoint)`
`CallbackInfo` `getRegisteredCallback(int messageId)`
`long` `getRegisteredCallbackAge(int messageId)`
`java.util.Map<java.lang.String,java.lang.Long>` `getSmallMessageCompletedTasks()` Completed tasks for small message TCP Connections
`java.util.Map<java.lang.String,java.lang.Long>` `getSmallMessageDroppedTasks()` Dropped tasks for small message TCP Connections
`java.util.Map<java.lang.String,java.lang.Integer>` `getSmallMessagePendingTasks()` Pending tasks for small message TCP Connections
`java.util.List<MessagingService.SocketThread>` `getSocketThreads()`
`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.
`int` `getVersion(java.net.InetAddress endpoint)`
`int` `getVersion(java.lang.String endpoint)`
`static IPartitioner` `globalPartitioner()`
`void` `incrementDroppedMessages(MessagingService.Verb verb)`
`void` `incrementDroppedMessages(MessagingService.Verb verb, boolean isCrossNodeTimeout)`
`static MessagingService` `instance()`
`boolean` `isListening()`
`boolean` `knowsVersion(java.net.InetAddress endpoint)`
`void` `listen()`
`void` `maybeAddLatency(IAsyncCallback cb, java.net.InetAddress address, long latency)` Track latency information for the dynamic snitch
`void` `receive(MessageIn message, int id, long timestamp, boolean isCrossNodeTimestamp)`
`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(int messageId)`
`void` `resetVersion(java.net.InetAddress endpoint)`
`void` `sendOneWay(MessageOut message, java.net.InetAddress to)`
`void` `sendOneWay(MessageOut message, int id, java.net.InetAddress to)` Send a message to a given endpoint.
`void` `sendReply(MessageOut message, int id, java.net.InetAddress to)`
`int` `sendRR(MessageOut<?> message, java.net.InetAddress to, AbstractWriteResponseHandler<?> handler, boolean allowHints)` Send a mutation message or a Paxos Commit to a given endpoint.
`<T> AsyncOneResponse<T>` `sendRR(MessageOut message, java.net.InetAddress to)`
`int` `sendRR(MessageOut message, java.net.InetAddress to, IAsyncCallback cb)`
`int` `sendRR(MessageOut message, java.net.InetAddress to, IAsyncCallback cb, long timeout, boolean failureCallback)` Send a non-mutation message to a given endpoint.
`int` `sendRRWithFailure(MessageOut message, java.net.InetAddress to, IAsyncCallbackWithFailure cb)`
`void` `setCallbackForTests(int messageId, CallbackInfo callback)`
`int` `setVersion(java.net.InetAddress endpoint, int version)`
`void` `shutdown()` Wait for callbacks and don't allow any more to be created (since they could require writing hints)
`static void` `validateMagic(int magic)`
`static void` `validatePartitioner(AbstractBounds<?> bounds)`
`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_12

    public static final int VERSION_12

See Also:
  Constant Field Values

#### VERSION_20

    public static final int VERSION_20

See Also:
  Constant Field Values

#### VERSION_21

    public static final int VERSION_21

See Also:
  Constant Field Values

#### VERSION_22

    public static final int VERSION_22

See Also:
  Constant Field Values

#### current_version

    public static final int current_version

See Also:
  Constant Field Values

#### FAILURE_CALLBACK_PARAM

    public static final java.lang.String FAILURE_CALLBACK_PARAM

See Also:
  Constant Field Values

#### ONE_BYTE

    public static final byte[] ONE_BYTE

#### FAILURE_RESPONSE_PARAM

    public static final java.lang.String FAILURE_RESPONSE_PARAM

See Also:
  Constant Field Values

#### 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

#### 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

#### addMessageSink

    public void addMessageSink(IMessageSink sink)

#### clearMessageSinks

    public void clearMessageSinks()

#### instance

    public static MessagingService instance()

#### maybeAddLatency

    public void maybeAddLatency(IAsyncCallback 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()

#### waitUntilListening

    public void waitUntilListening()

#### isListening

    public boolean isListening()

#### 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 int addCallback(IAsyncCallback cb,
                           MessageOut message,
                           java.net.InetAddress to,
                           long timeout,
                           boolean failureCallback)

#### addCallback

    public int addCallback(IAsyncCallback cb,
                           MessageOut<?> message,
                           java.net.InetAddress to,
                           long timeout,
                           ConsistencyLevel consistencyLevel,
                           boolean allowHints)

#### sendRR

    public int sendRR(MessageOut message,
                      java.net.InetAddress to,
                      IAsyncCallback cb)

#### sendRRWithFailure

    public int sendRRWithFailure(MessageOut message,
                                 java.net.InetAddress to,
                                 IAsyncCallbackWithFailure cb)

#### sendRR

    public int sendRR(MessageOut message,
                      java.net.InetAddress to,
                      IAsyncCallback cb,
                      long timeout,
                      boolean failureCallback)

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

#### sendRR

    public int sendRR(MessageOut<?> message,
                      java.net.InetAddress to,
                      AbstractWriteResponseHandler<?> handler,
                      boolean allowHints)

Send a mutation message or a Paxos Commit 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
  `handler` - callback interface which is used to pass the responses or suggest that a timeout occurred to the invoker of the send().
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,
                          int id,
                          java.net.InetAddress to)

#### sendOneWay

    public void sendOneWay(MessageOut message,
                           int 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> AsyncOneResponse<T> sendRR(MessageOut message,
                                          java.net.InetAddress to)

#### register

    public void register(ILatencySubscriber subcriber)

#### clearCallbacksUnsafe

    public void clearCallbacksUnsafe()

#### 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,
                        int id,
                        long timestamp,
                        boolean isCrossNodeTimestamp)

#### setCallbackForTests

    public void setCallbackForTests(int messageId,
                                    CallbackInfo callback)

#### getRegisteredCallback

    public CallbackInfo getRegisteredCallback(int messageId)

#### removeRegisteredCallback

    public CallbackInfo removeRegisteredCallback(int messageId)

#### getRegisteredCallbackAge

    public long getRegisteredCallbackAge(int messageId)

Returns:
  System.nanoTime() when callback was created.

#### 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)

#### areAllNodesAtLeast22

    public boolean areAllNodesAtLeast22()

#### setVersion

    public int setVersion(java.net.InetAddress endpoint,
                          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 int getVersion(java.net.InetAddress endpoint)

#### getVersion

    public int getVersion(java.lang.String endpoint)
                   throws java.net.UnknownHostException

Specified by:
  `getVersion` in interface `MessagingServiceMBean`
Throws:
  `java.net.UnknownHostException`

#### getRawVersion

    public int getRawVersion(java.net.InetAddress endpoint)

#### knowsVersion

    public boolean knowsVersion(java.net.InetAddress endpoint)

#### incrementDroppedMessages

    public void incrementDroppedMessages(MessagingService.Verb verb)

#### incrementDroppedMessages

    public void incrementDroppedMessages(MessagingService.Verb verb,
                                         boolean isCrossNodeTimeout)

#### getLargeMessagePendingTasks

    public java.util.Map<java.lang.String,java.lang.Integer> getLargeMessagePendingTasks()

Description copied from interface: `MessagingServiceMBean`
Pending tasks for large message TCP Connections

Specified by:
  `getLargeMessagePendingTasks` in interface `MessagingServiceMBean`

#### getLargeMessagePendingTasks

    public int getLargeMessagePendingTasks(java.net.InetAddress address)

#### getLargeMessageCompletedTasks

    public java.util.Map<java.lang.String,java.lang.Long> getLargeMessageCompletedTasks()

Description copied from interface: `MessagingServiceMBean`
Completed tasks for large message) TCP Connections

Specified by:
  `getLargeMessageCompletedTasks` in interface `MessagingServiceMBean`

#### getLargeMessageDroppedTasks

    public java.util.Map<java.lang.String,java.lang.Long> getLargeMessageDroppedTasks()

Description copied from interface: `MessagingServiceMBean`
Dropped tasks for large message TCP Connections

Specified by:
  `getLargeMessageDroppedTasks` in interface `MessagingServiceMBean`

#### getSmallMessagePendingTasks

    public java.util.Map<java.lang.String,java.lang.Integer> getSmallMessagePendingTasks()

Description copied from interface: `MessagingServiceMBean`
Pending tasks for small message TCP Connections

Specified by:
  `getSmallMessagePendingTasks` in interface `MessagingServiceMBean`

#### getSmallMessageCompletedTasks

    public java.util.Map<java.lang.String,java.lang.Long> getSmallMessageCompletedTasks()

Description copied from interface: `MessagingServiceMBean`
Completed tasks for small message TCP Connections

Specified by:
  `getSmallMessageCompletedTasks` in interface `MessagingServiceMBean`

#### getSmallMessageDroppedTasks

    public java.util.Map<java.lang.String,java.lang.Long> getSmallMessageDroppedTasks()

Description copied from interface: `MessagingServiceMBean`
Dropped tasks for small message TCP Connections

Specified by:
  `getSmallMessageDroppedTasks` in interface `MessagingServiceMBean`

#### getGossipMessagePendingTasks

    public java.util.Map<java.lang.String,java.lang.Integer> getGossipMessagePendingTasks()

Description copied from interface: `MessagingServiceMBean`
Pending tasks for gossip message TCP Connections

Specified by:
  `getGossipMessagePendingTasks` in interface `MessagingServiceMBean`

#### getGossipMessageCompletedTasks

    public java.util.Map<java.lang.String,java.lang.Long> getGossipMessageCompletedTasks()

Description copied from interface: `MessagingServiceMBean`
Completed tasks for gossip message TCP Connections

Specified by:
  `getGossipMessageCompletedTasks` in interface `MessagingServiceMBean`

#### getGossipMessageDroppedTasks

    public java.util.Map<java.lang.String,java.lang.Long> getGossipMessageDroppedTasks()

Description copied from interface: `MessagingServiceMBean`
Dropped tasks for gossip message TCP Connections

Specified by:
  `getGossipMessageDroppedTasks` 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`

#### getTotalTimeouts

    public long getTotalTimeouts()

Description copied from interface: `MessagingServiceMBean`
Total number of timeouts happened on this node

Specified by:
  `getTotalTimeouts` 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`

#### globalPartitioner

    public static IPartitioner globalPartitioner()

#### validatePartitioner

    public static void validatePartitioner(AbstractBounds<?> bounds)

#### getSocketThreads

    public java.util.List<MessagingService.SocketThread> getSocketThreads()