Package org.jgroups.protocols
Class TCP_NIO2
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.TP
-
- org.jgroups.protocols.BasicTCP
-
- org.jgroups.protocols.TCP_NIO2
-
- All Implemented Interfaces:
ConnectionListener,Receiver,Lifecycle,DiagnosticsHandler.ProbeHandler
public class TCP_NIO2 extends BasicTCP
Protocol using TCP/IP to send and receive messages. Contrary toTCP, TCP_NIO uses non-blocking I/O (NIO), which eliminates the thread per connection model. Instead, TCP_NIO uses a single selector to poll for incoming messages and dispatches handling of those to a (configurable) thread pool.Most of the functionality is in
NioServer. TCP_NIO sends messages usingBaseServer.send(Address,byte[],int,int)and registers with the server to receive messages.- Since:
- 3.6.5
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancopy_on_partial_writeprotected intmax_send_buffersprotected longreader_idle_timeprotected NioServerserver-
Fields inherited from class org.jgroups.protocols.BasicTCP
client_bind_addr, client_bind_port, conn_expire_time, defer_client_bind_addr, enable_suspect_events, linger, log_details, max_length, num_suspect_events, peer_addr_read_timeout, reaper_interval, recv_buf_size, send_buf_size, sock_conn_timeout, tcp_nodelay, use_acks
-
Fields inherited from class org.jgroups.protocols.TP
async_executor, bind_addr, bind_port, bundler, bundler_type, cluster_name, connectLock, diag_handler, external_addr, external_port, header, is_trace, last_discovery_request, LIST, local_physical_addr, local_transport, local_transport_class, log_discard_msgs, log_discard_msgs_version, logical_addr_cache, logical_addr_cache_expiration, logical_addr_cache_max_size, logical_addr_cache_reaper, logical_addr_cache_reaper_interval, members, message_processing_policy, MIN_WAIT_BETWEEN_DISCOVERIES, MSG_OVERHEAD, msg_processing_policy, msg_stats, MULTICAST, port_range, print_function, receive_interfaces, receive_on_all_interfaces, rtt, socket_factory, suppress_log_different_cluster, suppress_log_different_version, suppress_time_different_cluster_warnings, suppress_time_different_version_warnings, thread_factory, thread_naming_pattern, thread_pool, time_service, time_service_interval, timer, timer_handle_non_blocking_tasks, use_vthreads, view, who_has_cache, who_has_cache_timeout
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description TCP_NIO2()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearConnections()booleancopyOnPartialWrite()TCP_NIO2copyOnPartialWrite(boolean c)intgetMaxSendBuffers()intgetOpenConnections()protected PhysicalAddressgetPhysicalAddress()longgetReaderIdleTime()protected voidhandleConnect()protected voidhandleDisconnect()booleanisAcceptorRunning()booleanisSelectorOpen()intnumPartialWrites()intnumSelects()java.lang.StringprintBuffers()java.lang.StringprintConnections()voidreaderIdleTime(long t)voidretainAll(java.util.Collection<Address> members)voidsend(Address dest, byte[] data, int offset, int length)TCP_NIO2setMaxSendBuffers(int m)TCP_NIO2setReaderIdleTime(long r)voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsvoidstop()Called on aJChannel.disconnect(); stops work (e.g.-
Methods inherited from class org.jgroups.protocols.BasicTCP
connectionClosed, connectionEstablished, deferClientBindAddr, deferClientBindAddr, down, enableSuspectEvents, enableSuspectEvents, getClientBindAddr, getClientBindPort, getConnExpireTime, getInfo, getLinger, getMaxLength, getPeerAddrReadTimeout, getReaperInterval, getRecvBufSize, getSendBufSize, getSockConnTimeout, init, logDetails, logDetails, reaperInterval, resetStats, sendUnicast, setClientBindAddr, setClientBindPort, setConnExpireTime, setLinger, setMaxLength, setPeerAddrReadTimeout, setReaperInterval, setRecvBufSize, setSendBufSize, setSockConnTimeout, supportsMulticasting, tcpNodelay, tcpNodelay, useAcks, useAcks
-
Methods inherited from class org.jgroups.protocols.TP
addPhysicalAddressToCache, addPhysicalAddressToCache, bundler, clearDifferentClusterCache, clearDifferentVersionCache, clearLogicalAddressCache, createBundler, createDiagnosticsHandler, defaultHeaders, destroy, disableDiagnostics, doSend, down, dumpTimerTasks, enableAllStats, enableBlockingTimerTasks, enableDiagnostics, enableStats, evictLogicalAddressCache, evictLogicalAddressCache, fetchLocalAddresses, fetchPhysicalAddrs, fetchResponsesFromDiscoveryProtocol, getAllPhysicalAddressesFromCache, getAsyncExecutor, getBindAddr, getBindAddress, getBindPort, getBundler, getBundlerClass, getBundlerType, getClusterName, getClusterNameAscii, getDiagnosticsHandler, getDifferentClusterMessages, getDifferentVersionMessages, getExternalAddr, getExternalPort, getLocalPhysicalAddress, getLocalTransport, getLogDiscardMessages, getLogDiscardMessagesVersion, getLogicalAddrCacheExpiration, getLogicalAddrCacheMaxSize, getLogicalAddrCacheReaperInterval, getLogicalAddressCache, getMessageProcessingPolicy, getMessageStats, getNumberOfThreadDumps, getNumMcastMsgsReceived, getNumMcastMsgsSent, getNumRejectedMsgs, getNumThreads, getNumTimerTasks, getNumUcastMsgsReceived, getNumUcastMsgsSent, getPhysicalAddressFromCache, getPortRange, getReceiveInterfaces, getRTT, getSocketFactory, getSuppressTimeDifferentClusterWarnings, getSuppressTimeDifferentVersionWarnings, getThreadFactory, getThreadNamingPattern, getThreadPool, getTimer, getTimerClass, getTimerThreads, getTimeService, getTimeServiceInterval, getWhoHasCacheTimeout, handleMessageBatch, handleProbe, handleSingleMessage, isLogicalAddressCacheReaperRunning, isMulticastCapable, isReceiveOnAllInterfaces, isTrace, isTrace, localPhysicalAddress, logDiscardMsgs, logDiscardMsgs, logDiscardMsgsVersion, logDiscardMsgsVersion, loggerType, msgProcessingPolicy, msgProcessingPolicy, passBatchUp, passMessageUp, printLogicalAddressCache, printWhoHasCache, processBatch, receive, receive, receiveOnAllInterfaces, receiveOnAllInterfaces, registerLocalAddress, registerProbeHandler, removeCancelledTimerTasks, removeLogicalAddressFromCache, sameCluster, sendTo, sendToAll, sendUnicasts, setAddress, setAsyncExecutor, setBindAddr, setBindAddress, setBindPort, setBindToAllInterfaces, setBundler, setBundlerType, setDiagnosticsHandler, setExternalAddr, setExternalPort, setInAllThreadFactories, setLevel, setLocalTransport, setLocalTransport, setLogDiscardMessages, setLogDiscardMessagesVersion, setLogicalAddrCacheExpiration, setLogicalAddrCacheMaxSize, setLogicalAddrCacheReaperInterval, setMessageProcessingPolicy, setPortRange, setSocketFactory, setSourceAddress, setSuppressTimeDifferentClusterWarnings, setSuppressTimeDifferentVersionWarnings, setThreadFactory, setThreadNames, setThreadPool, setTimer, setTimeService, setTimeServiceInterval, setWhoHasCacheTimeout, startDiagnostics, stopDiagnostics, supportedKeys, timestamp, toString, unicastDestMismatch, unregisterProbeHandler, unsetThreadNames, useVirtualThreads, useVirtualThreads, versionMatch, view
-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, down, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setPolicies, setProtocolStack, setUpProtocol, setValue, statsEnabled, up, up, up
-
-
-
-
Field Detail
-
server
protected NioServer server
-
max_send_buffers
protected int max_send_buffers
-
copy_on_partial_write
protected boolean copy_on_partial_write
-
reader_idle_time
protected long reader_idle_time
-
-
Method Detail
-
getMaxSendBuffers
public int getMaxSendBuffers()
-
setMaxSendBuffers
public TCP_NIO2 setMaxSendBuffers(int m)
-
copyOnPartialWrite
public boolean copyOnPartialWrite()
-
copyOnPartialWrite
public TCP_NIO2 copyOnPartialWrite(boolean c)
-
getReaderIdleTime
public long getReaderIdleTime()
-
setReaderIdleTime
public TCP_NIO2 setReaderIdleTime(long r)
-
getOpenConnections
public int getOpenConnections()
-
printConnections
public java.lang.String printConnections()
- Specified by:
printConnectionsin classBasicTCP
-
printBuffers
public java.lang.String printBuffers()
-
clearConnections
public void clearConnections()
-
isSelectorOpen
public boolean isSelectorOpen()
-
isAcceptorRunning
public boolean isAcceptorRunning()
-
numSelects
public int numSelects()
-
numPartialWrites
public int numPartialWrites()
-
readerIdleTime
public void readerIdleTime(long t)
-
send
public void send(Address dest, byte[] data, int offset, int length) throws java.lang.Exception
-
retainAll
public void retainAll(java.util.Collection<Address> members)
-
start
public void start() throws java.lang.ExceptionDescription copied from class:TPCreates the unicast and multicast sockets and starts the unicast and multicast receiver threads- Specified by:
startin interfaceLifecycle- Overrides:
startin classTP- Throws:
java.lang.Exception- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)will throw an exception
-
stop
public void stop()
Description copied from class:ProtocolCalled on aJChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom.
-
handleConnect
protected void handleConnect() throws java.lang.Exception- Overrides:
handleConnectin classTP- Throws:
java.lang.Exception
-
handleDisconnect
protected void handleDisconnect()
- Overrides:
handleDisconnectin classTP
-
getPhysicalAddress
protected PhysicalAddress getPhysicalAddress()
- Specified by:
getPhysicalAddressin classTP
-
-