Package org.jgroups.blocks.cs
Class BaseServer
java.lang.Object
org.jgroups.blocks.cs.BaseServer
- All Implemented Interfaces:
Closeable,AutoCloseable,ConnectionListener
- Direct Known Subclasses:
NioBaseServer,TcpBaseServer
Abstract class for a server handling sending, receiving and connection management.
- Since:
- 3.6.5
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InetAddressprotected intprotected longprotected final List<ConnectionListener> protected final Map<Address, Connection> protected booleanprotected final ThreadFactoryprotected intprotected Addressprotected final Lockprotected Logprotected booleanprotected intstatic final byte[]protected BaseServer.Reaperprotected longprotected Receiverprotected intprotected final AtomicBooleanprotected intprotected intprotected SocketFactoryprotected booleanprotected TimeServiceprotected booleanprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseServer(ThreadFactory f, SocketFactory sf, int recv_buf_size) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnection(Address peer_addr, Connection conn) voidUsed only for testing !clientBindAddress(InetAddress addr) intclientBindPort(int port) voidclose()booleancloseConnection(Address addr) booleancloseConnection(Address addr, boolean notify) voidcloseConnection(Connection conn) voidcloseConnection(Connection conn, boolean notify) protected static booleanvoidconnectionClosed(Connection conn) voidbooleanconnectionEstablishedTo(Address address) longconnExpireTimeout(long t) protected abstract ConnectioncreateConnection(Address dest) Creates a new connection object to target dest, but doesn't yet connect itbooleandeferClientBinding(boolean defer) protected static Stringexplanation(boolean connection_existed, boolean replace) voidvoidflushAll()voidgetConnection(Address dest) Creates a new connection to dest, or returns an existing onegetConnection(Address dest, boolean retry) intintintbooleanhasConnection(Address address) intlinger()linger(int linger) protected static AddresslocalAddress(InetAddress bind_addr, int local_port, InetAddress external_addr, int external_port) log()booleanlogDetails(boolean l) voidvoidlongreaperInterval(long interval) voidCalled by aConnectionimplementation when a message has been received.voidvoidreceive(Address sender, ByteBuffer buf) Called by aConnectionimplementation when a message has been receivedintreceiveBufferSize(int recv_buf_size) receiver()voidremoveConnectionIfPresent(Address address, Connection conn) Only removes the connection if conns.get(address) == connvoidreplaceConnection(Address address, Connection conn) voidretainAll(Collection<Address> current_mbrs) Removes all connections which are not in current_mbrsbooleanrunning()voidvoidsend(Address dest, ByteBuffer data) intsendBufferSize(int send_buf_size) voidsendToAll(byte[] data, int offset, int length) voidsendToAll(ByteBuffer data) setMaxLength(int len) intsocketConnectionTimeout(int timeout) socketFactory(SocketFactory factory) voidstart()Starts accepting connections.voidstop()Stops listening for connections and handling traffic.booleantcpNodelay(boolean tcp_nodelay) toString()toString(boolean details) booleanuseAcks()useAcks(boolean f) booleanusePeerConnections(boolean flag) protected <T> booleanvalidateArgs(Address dest, T buffer)
-
Field Details
-
lock
-
local_addr
-
conn_listeners
-
conns
-
factory
-
socket_factory
-
reaperInterval
protected long reaperInterval -
reaper
-
receiver
-
running
-
log
-
client_bind_addr
-
client_bind_port
protected int client_bind_port -
defer_client_binding
protected boolean defer_client_binding -
conn_expire_time
protected long conn_expire_time -
recv_buf_size
protected int recv_buf_size -
send_buf_size
protected int send_buf_size -
max_length
protected int max_length -
use_peer_connections
protected boolean use_peer_connections -
use_acks
protected boolean use_acks -
log_details
protected boolean log_details -
sock_conn_timeout
protected int sock_conn_timeout -
tcp_nodelay
protected boolean tcp_nodelay -
linger
protected int linger -
time_service
-
OK
public static final byte[] OK
-
-
Constructor Details
-
BaseServer
-
-
Method Details
-
receiver
-
receiver
-
reaperInterval
public long reaperInterval() -
reaperInterval
-
log
-
log
-
localAddress
-
clientBindAddress
-
clientBindAddress
-
clientBindPort
public int clientBindPort() -
clientBindPort
-
deferClientBinding
public boolean deferClientBinding() -
deferClientBinding
-
socketFactory
-
socketFactory
-
usePeerConnections
public boolean usePeerConnections() -
usePeerConnections
-
useAcks
public boolean useAcks() -
useAcks
-
logDetails
public boolean logDetails() -
logDetails
-
socketConnectionTimeout
public int socketConnectionTimeout() -
socketConnectionTimeout
-
connExpireTime
public long connExpireTime() -
connExpireTimeout
-
timeService
-
timeService
-
receiveBufferSize
public int receiveBufferSize() -
receiveBufferSize
-
sendBufferSize
public int sendBufferSize() -
sendBufferSize
-
getMaxLength
public int getMaxLength() -
setMaxLength
-
linger
public int linger() -
linger
-
tcpNodelay
public boolean tcpNodelay() -
tcpNodelay
-
running
public boolean running() -
getNumConnections
public int getNumConnections() -
getNumOpenConnections
public int getNumOpenConnections() -
start
Starts accepting connections. Typically, socket handler or selectors thread are started here.- Throws:
Exception
-
stop
public void stop()Stops listening for connections and handling traffic. Typically, socket handler or selector threads are stopped, and server sockets or channels are closed. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flush
-
flushAll
public void flushAll() -
receive
Called by aConnectionimplementation when a message has been received. Note that data might be a reused buffer, so unless used to de-serialize an object from it, it should be copied (e.g. if we store a ref to it beyone the scope of this receive() method) -
receive
Called by aConnectionimplementation when a message has been received -
receive
- Throws:
Exception
-
send
- Throws:
Exception
-
send
- Throws:
Exception
-
connectionClosed
- Specified by:
connectionClosedin interfaceConnectionListener
-
connectionEstablished
- Specified by:
connectionEstablishedin interfaceConnectionListener
-
createConnection
Creates a new connection object to target dest, but doesn't yet connect it- Throws:
Exception
-
hasConnection
-
connectionEstablishedTo
-
getConnection
- Throws:
Exception
-
getConnection
Creates a new connection to dest, or returns an existing one- Throws:
Exception
-
replaceConnection
-
closeConnection
-
closeConnection
-
closeConnection
-
closeConnection
-
addConnection
- Throws:
Exception
-
addConnectionListener
-
removeConnectionListener
-
printConnections
-
removeConnectionIfPresent
Only removes the connection if conns.get(address) == conn -
clearConnections
public void clearConnections()Used only for testing ! -
forAllConnections
-
retainAll
Removes all connections which are not in current_mbrs -
notifyConnectionClosed
-
notifyConnectionEstablished
-
toString
-
toString
-
sendToAll
public void sendToAll(byte[] data, int offset, int length) -
sendToAll
-
connected
-
localAddress
protected static Address localAddress(InetAddress bind_addr, int local_port, InetAddress external_addr, int external_port) -
validateArgs
-
explanation
-