MessagingService (apache-cassandra API)
Date: 2014-10-21

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
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MessagingService.Verb`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `addCallback(IAsyncCallback cb, MessageOut<? extends IMutation> 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)`
    `boolean` | `areAllNodesAtLeast21()`
    `void` | `clearCallbacksUnsafe()`
    `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
    `int` | `getRawVersion(java.net.InetAddress endpoint)`
    `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(int messageId)`
    `long` | `getRegisteredCallbackAge(int 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.
    `int` | `getVersion(java.net.InetAddress endpoint)`
    `int` | `getVersion(java.lang.String endpoint)`
    `void` | `incrementDroppedMessages(MessagingService.Verb verb)`
    `static MessagingService` | `instance()`
    `boolean` | `isListening()`
    `boolean` | `knowsVersion(java.net.InetAddress endpoint)`
    `void` | `listen(java.net.InetAddress localEp)` Listen on the specified port.
    `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)`
    `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<? extends IMutation> message, java.net.InetAddress to, AbstractWriteResponseHandler handler, boolean allowHints)` Send a mutation message 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)`
    `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

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

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

    - #### 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<? extends IMutation> 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<? extends IMutation> message,
                   java.net.InetAddress to,
                   AbstractWriteResponseHandler handler,
                   boolean allowHints)

      Send a mutation 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
        `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)

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

    - #### areAllNodesAtLeast21

          public boolean areAllNodesAtLeast21()

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

    - #### 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 © 2014 The Apache Software Foundation