Package org.apache.cassandra.net
Class OutboundConnection
- java.lang.Object
-
- org.apache.cassandra.net.OutboundConnection
-
public class OutboundConnection extends java.lang.Object
Represents a connection type to a peer, and handles the state transistions on the connection and the nettyChannel
. The underlying socket is not opened until explicitly requested (by sending a message). TODO: complete this description Aside from a few administrative methods, the main entry point to sending a message isenqueue(Message)
. Any thread may send a message (enqueueing it toqueue
), but only one thread may consume messages from this queue. There is a single delivery thread - either the event loop, or a companion thread - that has logical ownership of the queue, but other threads may temporarily take ownership in order to perform book keeping, pruning, etc., to ensure system stability.OutboundConnection.Delivery.run()
is the main entry point for consuming messages from the queue, and executes either on the event loop or on a non-dedicated companion thread. This processing is activated viaOutboundConnection.Delivery.execute()
. Almost all internal state maintenance on this class occurs on the eventLoop, a single threaded executor which is assigned in the constructor. Further details are outlined below in the class. Some behaviours require coordination between the eventLoop and the companion thread (if any). Some minimal set of behaviours are permitted to occur on producers to ensure the connection remains healthy and does not overcommit resources. All methods are safe to invoke from any thread unless otherwise stated.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.netty.util.concurrent.Future<java.lang.Void>
close(boolean flushQueue)
Permanently close this connection.long
connectionAttempts()
long
dropped()
void
enqueue(Message message)
This is the main entry point for enqueuing a message to be sent to the remote peer.long
errorBytes()
long
errorCount()
long
expiredBytes()
long
expiredCount()
boolean
hasPending()
boolean
interrupt()
Close any currently open connection, forcing a reconnect if there are messages outstanding (or leaving it closed for now otherwise)boolean
isConnected()
long
overloadedBytes()
long
overloadedCount()
long
pendingBytes()
int
pendingCount()
long
sentBytes()
long
sentCount()
long
submittedCount()
long
successfulConnections()
java.lang.String
toString()
ConnectionType
type()
-
-
-
Method Detail
-
enqueue
public void enqueue(Message message) throws java.nio.channels.ClosedChannelException
This is the main entry point for enqueuing a message to be sent to the remote peer.- Throws:
java.nio.channels.ClosedChannelException
-
interrupt
public boolean interrupt()
Close any currently open connection, forcing a reconnect if there are messages outstanding (or leaving it closed for now otherwise)
-
close
public io.netty.util.concurrent.Future<java.lang.Void> close(boolean flushQueue)
Permanently close this connection. Immediately prevent any new messages from being enqueued - these will throw ClosedChannelException. The close itself happens asynchronously on the eventLoop, so a Future is returned to help callers wait for its completion. The flushQueue parameter indicates if any outstanding messages should be delivered before closing the connection. - If false, any already flushed or in-progress messages are completed, and the remaining messages are cleared before the connection is promptly torn down. - If true, we attempt delivery of all queued messages. If necessary, we will continue to open new connections to the remote host until they have been delivered. Only if we continue to fail to open a connection for an extended period of time will we drop any outstanding messages and close the connection.
-
isConnected
public boolean isConnected()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hasPending
public boolean hasPending()
-
pendingCount
public int pendingCount()
-
pendingBytes
public long pendingBytes()
-
sentCount
public long sentCount()
-
sentBytes
public long sentBytes()
-
submittedCount
public long submittedCount()
-
dropped
public long dropped()
-
overloadedBytes
public long overloadedBytes()
-
overloadedCount
public long overloadedCount()
-
expiredCount
public long expiredCount()
-
expiredBytes
public long expiredBytes()
-
errorCount
public long errorCount()
-
errorBytes
public long errorBytes()
-
successfulConnections
public long successfulConnections()
-
connectionAttempts
public long connectionAttempts()
-
type
public ConnectionType type()
-
-