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:
Receiver,AdditionalJmxObjects,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, linger, max_length, peer_addr_read_timeout, reaper_interval, recv_buf_size, send_buf_size, sock_conn_timeout, tcp_nodelay
-
Fields inherited from class org.jgroups.protocols.TP
avg_batch_size, bind_addr, bind_port, bundler, bundler_capacity, bundler_num_spins, bundler_type, bundler_wait_strategy, cluster_name, connectLock, diag_enable_tcp, diag_enable_udp, diag_handler, diagnostics_addr, diagnostics_bind_addr, diagnostics_bind_interfaces, diagnostics_passcode, diagnostics_port, diagnostics_port_range, diagnostics_ttl, drop_when_full, enable_diagnostics, external_addr, external_port, header, internal_pool, internal_thread_factory, is_trace, last_discovery_request, LIST, local_addr, local_physical_addr, 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, loopback_copy, loopback_separate_thread, max_bundle_size, members, message_processing_policy, MIN_WAIT_BETWEEN_DISCOVERIES, MSG_OVERHEAD, msg_processing_max_buffer_size, msg_processing_policy, msg_stats, MULTICAST, port_range, preregistered_probe_handlers, print_function, receive_interfaces, receive_on_all_interfaces, socket_factory, spawn_thread_on_full_pool, suppress_log_different_cluster, suppress_log_different_version, suppress_time_different_cluster_warnings, suppress_time_different_version_warnings, thread_dump_path, thread_dumps, thread_dumps_threshold, thread_factory, thread_naming_pattern, thread_pool, thread_pool_enabled, thread_pool_keep_alive_time, thread_pool_max_threads, thread_pool_min_threads, time_service, time_service_interval, timer, timer_handle_non_blocking_tasks, use_common_fork_join_pool, use_fibers, use_fork_join_pool, use_ip_addrs, view, who_has_cache, who_has_cache_timeout
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, 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()intgetOpenConnections()protected PhysicalAddressgetPhysicalAddress()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)voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsvoidstop()This method is called on aJChannel.disconnect().-
Methods inherited from class org.jgroups.protocols.BasicTCP
deferClientBindAddr, deferClientBindAddr, down, getClientBindAddr, getClientBindPort, getConnExpireTime, getInfo, getLinger, getMaxLength, getPeerAddrReadTimeout, getReaperInterval, getRecvBufSize, getSendBufSize, getSockConnTimeout, init, reaperInterval, receive, sendMulticast, sendUnicast, setClientBindAddr, setClientBindPort, setConnExpireTime, setLinger, setMaxLength, setPeerAddrReadTimeout, setReaperInterval, setRecvBufSize, setSendBufSize, setSockConnTimeout, supportsMulticasting, tcpNodelay, tcpNodelay
-
Methods inherited from class org.jgroups.protocols.TP
_send, addPhysicalAddressToCache, addPhysicalAddressToCache, avgBatchSize, bundler, bundlerNumSpins, bundlerNumSpins, bundlerStats, bundlerStatsReset, bundlerWaitStrategy, bundlerWaitStrategy, clearDifferentClusterCache, clearDifferentVersionCache, clearLogicalAddressCache, createBundler, createDiagnosticsHandler, createThreadPool, destroy, diagEnableTcp, diagEnableUdp, diagTcpEnabled, disableDiagnostics, doSend, down, dumpTimerTasks, enableBlockingTimerTasks, enableDiagnostics, evictLogicalAddressCache, evictLogicalAddressCache, fetchLocalAddresses, fetchPhysicalAddrs, fetchResponsesFromDiscoveryProtocol, getAllPhysicalAddressesFromCache, getAvgBatchSize, getBindAddress, getBindPort, getBundler, getBundlerBufferSize, getBundlerCapacity, getBundlerClass, getClusterName, getClusterNameAscii, getDiagnosticsHandler, getDifferentClusterMessages, getDifferentVersionMessages, getDropWhenFull, getInternalThreadPool, getInternalThreadPoolSize, getInternalThreadPoolSizeLargest, getInternalThreadPoolThreadFactory, getJmxObjects, getLocalAddress, getLocalPhysicalAddress, getLogDiscardMessages, getLogDiscardMessagesVersion, getMaxBundleSize, getMessageProcessingMaxBufferSize, getMessageStats, getNumberOfThreadDumps, getNumMessagesSent, getNumThreads, getNumTimerTasks, getPhysicalAddressFromCache, getPortRange, getReceiveInterfaces, getSocketFactory, getThreadDumpsThreshold, getThreadFactory, getThreadNamingPattern, getThreadPool, getThreadPoolKeepAliveTime, getThreadPoolMaxThreads, getThreadPoolMinThreads, getThreadPoolSize, getThreadPoolSizeActive, getThreadPoolSizeLargest, getThreadPoolThreadFactory, getTimer, getTimerClass, getTimerThreads, getTimeService, getUseIpAddresses, handleMessageBatch, handleProbe, handleSingleMessage, incrBatchesSent, incrNumSingleMsgsSent, isDiagnosticsEnabled, isDiagnosticsRunning, isDiagUdEnabled, isLogicalAddressCacheReaperRunning, isMulticastCapable, isReceiveOnAllInterfaces, localAddress, loggerType, loopback, passBatchUp, passMessageUp, printLogicalAddressCache, printWhoHasCache, processBatch, receive, receive, registerLocalAddress, registerProbeHandler, removeCancelledTimerTasks, removeLogicalAddressFromCache, resetStats, resetThreadDumps, runInNewThread, send, sendToMembers, sendToSingleMember, setBindAddress, setBindPort, setBindToAllInterfaces, setBundler, setBundlerCapacity, setDiagnosticsEnabled, setDiagnosticsHandler, setDropWhenFull, setInAllThreadFactories, setInternalThreadPool, setInternalThreadPoolThreadFactory, setLevel, setLogDiscardMessages, setLogDiscardMessagesVersion, setMaxBundleSize, setMessageProcessingPolicy, setPortRange, setSocketFactory, setSourceAddress, setThreadDumpsThreshold, setThreadFactory, setThreadNames, setThreadPool, setThreadPoolKeepAliveTime, setThreadPoolMaxThreads, setThreadPoolMinThreads, setThreadPoolThreadFactory, setTimer, setTimeService, shutdownThreadPool, startDiagnostics, stopDiagnostics, submitToThreadPool, submitToThreadPool, supportedKeys, timestamp, toString, unicastDestMismatch, unregisterProbeHandler, unsetThreadNames, useFibers, versionMatch, view
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, 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
-
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- 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:ProtocolThis method is called on aJChannel.disconnect(). Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
-
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
-
-