Package org.jgroups.blocks.cs
Class TcpServer
- java.lang.Object
- 
- org.jgroups.blocks.cs.BaseServer
- 
- org.jgroups.blocks.cs.TcpBaseServer
- 
- org.jgroups.blocks.cs.TcpServer
 
 
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable,- ConnectionListener
 
 public class TcpServer extends TcpBaseServer Class that manages allows to send and receive messages via TCP sockets. Uses 1 thread/connection to read messages.- Author:
- Vladimir Blagojevic, Bela Ban
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classTcpServer.AcceptorAcceptor thread.- 
Nested classes/interfaces inherited from class org.jgroups.blocks.cs.BaseServerBaseServer.Reaper
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected java.lang.Threadacceptorprotected booleanlog_accept_errorprotected java.net.ServerSocketsrv_sock- 
Fields inherited from class org.jgroups.blocks.cs.TcpBaseServerbuffered_inputstream_size, buffered_outputstream_size, max_send_queue, non_blocking_sends, peer_addr_read_timeout, use_lock_to_send
 - 
Fields inherited from class org.jgroups.blocks.cs.BaseServerclient_bind_addr, client_bind_port, conn_expire_time, conn_listeners, conns, defer_client_binding, factory, linger, local_addr, locks, log, log_details, max_length, reaper, reaperInterval, receiver, recv_buf_size, running, send_buf_size, sock_conn_timeout, socket_factory, tcp_nodelay, time_service, use_acks, use_peer_connections
 
- 
 - 
Constructor SummaryConstructors Constructor Description TcpServer(java.net.InetAddress bind_addr, int port)Creates an instance ofTcpServerthat creates a server socket and listens for connections.TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory, java.net.InetAddress bind_addr, int srv_port, int end_port, java.net.InetAddress external_addr, int external_port, int recv_buf_size)TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory, java.net.InetAddress bind_addr, int srv_port, int end_port, java.net.InetAddress external_addr, int external_port, int recv_buf_size, java.lang.String service_name)Creates an instance ofTcpServerthat creates a server socket and listens for connections Needs to be started next.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetLogAcceptError()TcpServersetLogAcceptError(boolean l)voidstart()Starts accepting connections.voidstop()Stops listening for connections and handling traffic.- 
Methods inherited from class org.jgroups.blocks.cs.TcpBaseServercreateConnection, getBufferedInputStreamSize, getBufferedOutputStreamSize, maxSendQueue, maxSendQueue, nonBlockingSends, nonBlockingSends, peerAddressReadTimeout, peerAddressReadTimeout, setBufferedInputStreamSize, setBufferedOutputStreamSize, useLockToSend, useLockToSend
 - 
Methods inherited from class org.jgroups.blocks.cs.BaseServeraddConnection, addConnectionListener, clearConnections, clientBindAddress, clientBindAddress, clientBindPort, clientBindPort, close, closeConnection, closeConnection, closeConnection, closeConnection, connected, connectionClosed, connectionEstablished, connectionEstablishedTo, connExpireTime, connExpireTimeout, deferClientBinding, deferClientBinding, explanation, flush, flushAll, forAllConnections, getConnection, getLock, getMaxLength, getNumConnections, getNumOpenConnections, hasConnection, linger, linger, localAddress, localAddress, log, log, logDetails, logDetails, notifyConnectionClosed, notifyConnectionEstablished, printConnections, reaperInterval, reaperInterval, receive, receive, receive, receiveBufferSize, receiveBufferSize, receiver, receiver, removeConnectionIfPresent, removeConnectionListener, replaceConnection, retainAll, running, send, send, sendBufferSize, sendBufferSize, sendToAll, sendToAll, setMaxLength, socketConnectionTimeout, socketConnectionTimeout, socketFactory, socketFactory, tcpNodelay, tcpNodelay, timeService, timeService, toString, toString, useAcks, useAcks, usePeerConnections, usePeerConnections, validateArgs
 
- 
 
- 
- 
- 
Constructor Detail- 
TcpServerpublic TcpServer(java.net.InetAddress bind_addr, int port) throws java.lang.ExceptionCreates an instance ofTcpServerthat creates a server socket and listens for connections. The end port defaults to (port + 50). Needs to be started next.- Parameters:
- bind_addr- The local address to bind to. If null, the address will be picked by the OS
- port- The local port to bind to. If 0, the port will be picked by the OS.
- Throws:
- java.lang.Exception- Thrown if the creation failed
 
 - 
TcpServerpublic TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory, java.net.InetAddress bind_addr, int srv_port, int end_port, java.net.InetAddress external_addr, int external_port, int recv_buf_size) throws java.lang.Exception - Throws:
- java.lang.Exception
 
 - 
TcpServerpublic TcpServer(ThreadFactory thread_factory, SocketFactory socket_factory, java.net.InetAddress bind_addr, int srv_port, int end_port, java.net.InetAddress external_addr, int external_port, int recv_buf_size, java.lang.String service_name) throws java.lang.Exception Creates an instance ofTcpServerthat creates a server socket and listens for connections Needs to be started next.- Parameters:
- thread_factory- The thread factory used to create new threads
- socket_factory- The socket factory used to create sockets
- bind_addr- The local address to bind to. If null, the address will be picked by the OS
- srv_port- The local port to bind to. If 0, the port will be picked by the OS.
- end_port- If srv_port is taken, the next port is tried, until end_port has been reached, in which case an exception will be thrown. If srv_port == end_port, only 1 port will be tried.
- external_addr- The external address in case of NAT. Ignored if null.
- external_port- The external port on the NA. If 0, srv_port is used.
- recv_buf_size- The size of the initial TCP receive window (in bytes)
- service_name- The name of the service
- Throws:
- java.lang.Exception- Thrown if the creation failed
 
 
- 
 - 
Method Detail- 
getLogAcceptErrorpublic boolean getLogAcceptError() 
 - 
setLogAcceptErrorpublic TcpServer setLogAcceptError(boolean l) 
 - 
startpublic void start() throws java.lang.ExceptionDescription copied from class:BaseServerStarts accepting connections. Typically, socket handler or selectors thread are started here.- Overrides:
- startin class- BaseServer
- Throws:
- java.lang.Exception
 
 - 
stoppublic void stop() Description copied from class:BaseServerStops listening for connections and handling traffic. Typically, socket handler or selector threads are stopped, and server sockets or channels are closed.- Overrides:
- stopin class- BaseServer
 
 
- 
 
-