public abstract class BaseServer extends java.lang.Object implements java.io.Closeable, ConnectionListener
Modifier and Type | Class and Description |
---|---|
protected class |
BaseServer.Reaper |
Modifier and Type | Field and Description |
---|---|
protected java.net.InetAddress |
client_bind_addr |
protected int |
client_bind_port |
protected long |
conn_expire_time |
protected java.util.List<ConnectionListener> |
conn_listeners |
protected java.util.Map<Address,Connection> |
conns |
protected boolean |
defer_client_binding |
protected ThreadFactory |
factory |
protected int |
linger |
protected Address |
local_addr |
protected Log |
log |
protected BaseServer.Reaper |
reaper |
protected long |
reaperInterval |
protected Receiver |
receiver |
protected int |
recv_buf_size |
protected java.util.concurrent.atomic.AtomicBoolean |
running |
protected int |
send_buf_size |
protected int |
sock_conn_timeout |
protected java.util.concurrent.locks.Lock |
sock_creation_lock |
protected boolean |
tcp_nodelay |
protected TimeService |
time_service |
protected boolean |
use_peer_connections |
Modifier | Constructor and Description |
---|---|
protected |
BaseServer(ThreadFactory f) |
Modifier and Type | Method and Description |
---|---|
void |
addConnection(Address peer_addr,
Connection conn) |
void |
addConnectionListener(ConnectionListener cml) |
void |
clearConnections()
Used only for testing !
|
java.net.InetAddress |
clientBindAddress() |
BaseServer |
clientBindAddress(java.net.InetAddress addr) |
int |
clientBindPort() |
BaseServer |
clientBindPort(int port) |
void |
close() |
void |
closeConnection(Connection conn,
java.lang.Throwable ex) |
void |
connectionClosed(Connection conn,
java.lang.String reason) |
void |
connectionEstablished(Connection conn) |
boolean |
connectionEstablishedTo(Address address) |
long |
connExpireTime() |
BaseServer |
connExpireTimeout(long t) |
protected abstract Connection |
createConnection(Address dest)
Creates a new connection object to target dest, but doesn't yet connect it
|
boolean |
deferClientBinding() |
BaseServer |
deferClientBinding(boolean defer) |
protected static java.lang.String |
explanation(boolean connection_existed,
boolean replace) |
Connection |
getConnection(Address dest)
Creates a new connection to dest, or returns an existing one
|
int |
getNumConnections() |
int |
getNumOpenConnections() |
boolean |
hasConnection(Address address) |
int |
linger() |
BaseServer |
linger(int linger) |
Address |
localAddress() |
protected static Address |
localAddress(java.net.InetAddress bind_addr,
int local_port,
java.net.InetAddress external_addr,
int external_port) |
Log |
log() |
BaseServer |
log(Log the_log) |
void |
notifyConnectionClosed(Connection conn,
java.lang.String cause) |
void |
notifyConnectionEstablished(Connection conn) |
java.lang.String |
printConnections() |
long |
reaperInterval() |
BaseServer |
reaperInterval(long interval) |
void |
receive(Address sender,
byte[] data,
int offset,
int length)
Called by a
Connection implementation when a message has been received. |
void |
receive(Address sender,
java.nio.ByteBuffer buf)
Called by a
Connection implementation when a message has been received |
int |
receiveBufferSize() |
BaseServer |
receiveBufferSize(int recv_buf_size) |
Receiver |
receiver() |
BaseServer |
receiver(Receiver r) |
void |
removeConnectionIfPresent(Address address,
Connection conn)
Only removes the connection if conns.get(address) == conn
|
void |
removeConnectionListener(ConnectionListener cml) |
void |
replaceConnection(Address address,
Connection conn) |
void |
retainAll(java.util.Collection<Address> current_mbrs)
Removes all connections which are not in current_mbrs
|
boolean |
running() |
void |
send(Address dest,
byte[] data,
int offset,
int length) |
void |
send(Address dest,
java.nio.ByteBuffer data) |
int |
sendBufferSize() |
BaseServer |
sendBufferSize(int send_buf_size) |
protected void |
sendToAll(byte[] data,
int offset,
int length) |
protected void |
sendToAll(java.nio.ByteBuffer data) |
int |
socketConnectionTimeout() |
BaseServer |
socketConnectionTimeout(int timeout) |
void |
start()
Starts accepting connections.
|
void |
stop()
Stops listening for connections and handling traffic.
|
boolean |
tcpNodelay() |
BaseServer |
tcpNodelay(boolean tcp_nodelay) |
TimeService |
timeService() |
BaseServer |
timeService(TimeService ts) |
java.lang.String |
toString() |
boolean |
usePeerConnections() |
BaseServer |
usePeerConnections(boolean flag) |
protected <T> boolean |
validateArgs(Address dest,
T buffer) |
protected Address local_addr
protected final java.util.List<ConnectionListener> conn_listeners
protected final java.util.Map<Address,Connection> conns
protected final java.util.concurrent.locks.Lock sock_creation_lock
protected final ThreadFactory factory
protected long reaperInterval
protected BaseServer.Reaper reaper
protected Receiver receiver
protected final java.util.concurrent.atomic.AtomicBoolean running
protected Log log
protected java.net.InetAddress client_bind_addr
protected int client_bind_port
protected boolean defer_client_binding
protected long conn_expire_time
protected int recv_buf_size
protected int send_buf_size
protected boolean use_peer_connections
protected int sock_conn_timeout
protected boolean tcp_nodelay
protected int linger
protected TimeService time_service
protected BaseServer(ThreadFactory f)
public Receiver receiver()
public BaseServer receiver(Receiver r)
public long reaperInterval()
public BaseServer reaperInterval(long interval)
public Log log()
public BaseServer log(Log the_log)
public Address localAddress()
public java.net.InetAddress clientBindAddress()
public BaseServer clientBindAddress(java.net.InetAddress addr)
public int clientBindPort()
public BaseServer clientBindPort(int port)
public boolean deferClientBinding()
public BaseServer deferClientBinding(boolean defer)
public boolean usePeerConnections()
public BaseServer usePeerConnections(boolean flag)
public int socketConnectionTimeout()
public BaseServer socketConnectionTimeout(int timeout)
public long connExpireTime()
public BaseServer connExpireTimeout(long t)
public TimeService timeService()
public BaseServer timeService(TimeService ts)
public int receiveBufferSize()
public BaseServer receiveBufferSize(int recv_buf_size)
public int sendBufferSize()
public BaseServer sendBufferSize(int send_buf_size)
public int linger()
public BaseServer linger(int linger)
public boolean tcpNodelay()
public BaseServer tcpNodelay(boolean tcp_nodelay)
public boolean running()
public int getNumConnections()
public int getNumOpenConnections()
public void start() throws java.lang.Exception
java.lang.Exception
public void stop()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void receive(Address sender, byte[] data, int offset, int length)
Connection
implementation 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)public void receive(Address sender, java.nio.ByteBuffer buf)
Connection
implementation when a message has been receivedpublic void send(Address dest, byte[] data, int offset, int length) throws java.lang.Exception
java.lang.Exception
public void send(Address dest, java.nio.ByteBuffer data) throws java.lang.Exception
java.lang.Exception
public void connectionClosed(Connection conn, java.lang.String reason)
connectionClosed
in interface ConnectionListener
public void connectionEstablished(Connection conn)
connectionEstablished
in interface ConnectionListener
protected abstract Connection createConnection(Address dest) throws java.lang.Exception
java.lang.Exception
public boolean hasConnection(Address address)
public boolean connectionEstablishedTo(Address address)
public Connection getConnection(Address dest) throws java.lang.Exception
java.lang.Exception
public void replaceConnection(Address address, Connection conn)
public void closeConnection(Connection conn, java.lang.Throwable ex)
public void addConnection(Address peer_addr, Connection conn) throws java.lang.Exception
java.lang.Exception
public void addConnectionListener(ConnectionListener cml)
public void removeConnectionListener(ConnectionListener cml)
public java.lang.String printConnections()
public void removeConnectionIfPresent(Address address, Connection conn)
public void clearConnections()
public void retainAll(java.util.Collection<Address> current_mbrs)
public void notifyConnectionClosed(Connection conn, java.lang.String cause)
public void notifyConnectionEstablished(Connection conn)
public java.lang.String toString()
toString
in class java.lang.Object
protected void sendToAll(byte[] data, int offset, int length)
protected void sendToAll(java.nio.ByteBuffer data)
protected static Address localAddress(java.net.InetAddress bind_addr, int local_port, java.net.InetAddress external_addr, int external_port)
protected <T> boolean validateArgs(Address dest, T buffer)
protected static java.lang.String explanation(boolean connection_existed, boolean replace)
Copyright © 1998-2020 Red Hat. All Rights Reserved.