A
- The type of the address, e.g. Address
C
- The type of the connection, e.g. TcpConnection
public abstract class BaseServer<A extends Address,C extends Connection> extends java.lang.Object implements Server<A>, java.io.Closeable
Modifier and Type | Class and Description |
---|---|
static interface |
BaseServer.ConnectionListener<A,V extends Connection> |
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<BaseServer.ConnectionListener<A,C>> |
conn_listeners |
protected java.util.Map<A,C> |
conns |
protected boolean |
defer_client_binding |
protected ThreadFactory |
factory |
protected int |
linger |
protected A |
local_addr |
protected Log |
log |
protected BaseServer.Reaper |
reaper |
protected long |
reaperInterval |
protected Receiver<A> |
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 SocketFactory |
socket_factory |
protected boolean |
tcp_nodelay |
protected TimeService |
time_service |
Constructor and Description |
---|
BaseServer(ThreadFactory f,
SocketFactory socket_factory,
Receiver<A> r,
long reaper_interval,
long conn_expire_time) |
Modifier and Type | Method and Description |
---|---|
void |
addConnection(A peer_addr,
C conn) |
void |
addConnectionListener(BaseServer.ConnectionListener<A,C> cml) |
java.net.InetAddress |
clientBindAddress() |
BaseServer<A,C> |
clientBindAddress(java.net.InetAddress addr) |
int |
clientBindPort() |
BaseServer<A,C> |
clientBindPort(int port) |
void |
close() |
boolean |
connectionEstablishedTo(A address) |
long |
connExpireTime() |
BaseServer<A,C> |
connExpireTimeout(long t) |
protected abstract C |
createConnection(A dest)
Creates a new connection object to target dest, but doesn't yet connect it
|
boolean |
deferClientBinding() |
BaseServer<A,C> |
deferClientBinding(boolean defer) |
protected static java.lang.String |
explanation(boolean connection_existed,
boolean replace) |
C |
getConnection(A dest)
Creates a new connection to dest, or returns an existing one
|
int |
getNumConnections() |
int |
getNumOpenConnections() |
boolean |
hasConnection(A address) |
int |
linger() |
BaseServer<A,C> |
linger(int linger) |
A |
localAddress() |
Log |
log() |
BaseServer<A,C> |
log(Log the_log) |
void |
notifyConnectionClosed(A address) |
void |
notifyConnectionOpened(A address,
C conn) |
java.lang.String |
printConnections() |
long |
reaperInterval() |
BaseServer<A,C> |
reaperInterval(long interval) |
void |
receive(A sender,
byte[] data,
int offset,
int length)
Called by a
Connection implementation when a message has been received |
void |
receive(A sender,
java.nio.ByteBuffer buf)
Called by a
Connection implementation when a message has been received |
int |
receiveBufferSize() |
BaseServer<A,C> |
receiveBufferSize(int recv_buf_size) |
Receiver<A> |
receiver() |
BaseServer<A,C> |
receiver(Receiver<A> r)
Sets a receiver
|
void |
removeConnectionIfPresent(A address,
C conn)
Only removes the connection if conns.get(address) == conn
|
void |
removeConnectionListener(BaseServer.ConnectionListener<A,C> cml) |
void |
replaceConnection(A address,
C conn) |
void |
retainAll(java.util.Collection<A> current_mbrs)
Removes all connections which are not in current_mbrs
|
void |
send(A dest,
byte[] data,
int offset,
int length)
Sends a message to a destination
|
void |
send(A dest,
java.nio.ByteBuffer data)
Sends a message to a destination
|
int |
sendBufferSize() |
BaseServer<A,C> |
sendBufferSize(int send_buf_size) |
int |
socketConnectionTimeout() |
BaseServer<A,C> |
socketConnectionTimeout(int timeout) |
SocketFactory |
socketFactory() |
BaseServer<A,C> |
socketFactory(SocketFactory factory) |
void |
start()
Starts the server.
|
void |
stop()
Stops the server, e.g.
|
boolean |
tcpNodelay() |
BaseServer<A,C> |
tcpNodelay(boolean tcp_nodelay) |
TimeService |
timeService() |
BaseServer<A,C> |
timeService(TimeService ts) |
java.lang.String |
toString() |
protected <T> boolean |
validateArgs(A dest,
T buffer) |
protected final java.util.List<BaseServer.ConnectionListener<A extends Address,C extends Connection>> conn_listeners
protected final java.util.Map<A extends Address,C extends Connection> conns
protected final java.util.concurrent.locks.Lock sock_creation_lock
protected final ThreadFactory factory
protected long reaperInterval
protected final BaseServer.Reaper reaper
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 int sock_conn_timeout
protected boolean tcp_nodelay
protected int linger
protected SocketFactory socket_factory
protected TimeService time_service
public BaseServer(ThreadFactory f, SocketFactory socket_factory, Receiver<A> r, long reaper_interval, long conn_expire_time) throws java.lang.Exception
java.lang.Exception
public BaseServer<A,C> receiver(Receiver<A> r)
Server
public long reaperInterval()
public BaseServer<A,C> reaperInterval(long interval)
public Log log()
public BaseServer<A,C> log(Log the_log)
public A localAddress()
public SocketFactory socketFactory()
public BaseServer<A,C> socketFactory(SocketFactory factory)
public java.net.InetAddress clientBindAddress()
public BaseServer<A,C> clientBindAddress(java.net.InetAddress addr)
public int clientBindPort()
public BaseServer<A,C> clientBindPort(int port)
public boolean deferClientBinding()
public BaseServer<A,C> deferClientBinding(boolean defer)
public int socketConnectionTimeout()
public BaseServer<A,C> socketConnectionTimeout(int timeout)
public long connExpireTime()
public BaseServer<A,C> connExpireTimeout(long t)
public TimeService timeService()
public BaseServer<A,C> timeService(TimeService ts)
public int receiveBufferSize()
public BaseServer<A,C> receiveBufferSize(int recv_buf_size)
public int sendBufferSize()
public BaseServer<A,C> sendBufferSize(int send_buf_size)
public int linger()
public BaseServer<A,C> linger(int linger)
public boolean tcpNodelay()
public BaseServer<A,C> tcpNodelay(boolean tcp_nodelay)
public void start() throws java.lang.Exception
Server
public void stop()
Server
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(A sender, byte[] data, int offset, int length)
Connection
implementation when a message has been receivedpublic void receive(A sender, java.nio.ByteBuffer buf)
Connection
implementation when a message has been receivedpublic void send(A dest, byte[] data, int offset, int length) throws java.lang.Exception
Server
public void send(A dest, java.nio.ByteBuffer data) throws java.lang.Exception
Server
protected abstract C createConnection(A dest) throws java.lang.Exception
java.lang.Exception
public boolean hasConnection(A address)
public boolean connectionEstablishedTo(A address)
public C getConnection(A dest) throws java.lang.Exception
java.lang.Exception
public void addConnection(A peer_addr, C conn) throws java.lang.Exception
java.lang.Exception
public void addConnectionListener(BaseServer.ConnectionListener<A,C> cml)
public void removeConnectionListener(BaseServer.ConnectionListener<A,C> cml)
public int getNumConnections()
public int getNumOpenConnections()
public java.lang.String printConnections()
public void removeConnectionIfPresent(A address, C conn)
public void retainAll(java.util.Collection<A> current_mbrs)
public void notifyConnectionClosed(A address)
public java.lang.String toString()
toString
in class java.lang.Object
protected <T> boolean validateArgs(A dest, T buffer)
protected static java.lang.String explanation(boolean connection_existed, boolean replace)
Copyright © 1998-2020 Red Hat. All Rights Reserved.