Class BaseServer

java.lang.Object
org.jgroups.blocks.cs.BaseServer
All Implemented Interfaces:
Closeable, AutoCloseable, ConnectionListener
Direct Known Subclasses:
NioBaseServer, TcpBaseServer

public abstract class BaseServer extends Object implements Closeable, ConnectionListener
Abstract class for a server handling sending, receiving and connection management.
Since:
3.6.5
  • Field Details

    • lock

      protected final Lock lock
    • local_addr

      protected Address local_addr
    • conn_listeners

      protected final List<ConnectionListener> conn_listeners
    • conns

      protected final Map<Address,Connection> conns
    • factory

      protected final ThreadFactory factory
    • socket_factory

      protected SocketFactory socket_factory
    • reaperInterval

      protected long reaperInterval
    • reaper

      protected BaseServer.Reaper reaper
    • receiver

      protected Receiver receiver
    • running

      protected final AtomicBoolean running
    • log

      protected Log log
    • client_bind_addr

      protected InetAddress 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

      protected TimeService time_service
    • OK

      public static final byte[] OK
  • Constructor Details

  • Method Details

    • receiver

      public Receiver receiver()
    • receiver

      public BaseServer receiver(Receiver r)
    • reaperInterval

      public long reaperInterval()
    • reaperInterval

      public BaseServer reaperInterval(long interval)
    • log

      public Log log()
    • log

      public BaseServer log(Log the_log)
    • localAddress

      public Address localAddress()
    • clientBindAddress

      public InetAddress clientBindAddress()
    • clientBindAddress

      public BaseServer clientBindAddress(InetAddress addr)
    • clientBindPort

      public int clientBindPort()
    • clientBindPort

      public BaseServer clientBindPort(int port)
    • deferClientBinding

      public boolean deferClientBinding()
    • deferClientBinding

      public BaseServer deferClientBinding(boolean defer)
    • socketFactory

      public SocketFactory socketFactory()
    • socketFactory

      public BaseServer socketFactory(SocketFactory factory)
    • usePeerConnections

      public boolean usePeerConnections()
    • usePeerConnections

      public BaseServer usePeerConnections(boolean flag)
    • useAcks

      public boolean useAcks()
    • useAcks

      public BaseServer useAcks(boolean f)
    • logDetails

      public boolean logDetails()
    • logDetails

      public BaseServer logDetails(boolean l)
    • socketConnectionTimeout

      public int socketConnectionTimeout()
    • socketConnectionTimeout

      public BaseServer socketConnectionTimeout(int timeout)
    • connExpireTime

      public long connExpireTime()
    • connExpireTimeout

      public BaseServer connExpireTimeout(long t)
    • timeService

      public TimeService timeService()
    • timeService

      public BaseServer timeService(TimeService ts)
    • receiveBufferSize

      public int receiveBufferSize()
    • receiveBufferSize

      public BaseServer receiveBufferSize(int recv_buf_size)
    • sendBufferSize

      public int sendBufferSize()
    • sendBufferSize

      public BaseServer sendBufferSize(int send_buf_size)
    • getMaxLength

      public int getMaxLength()
    • setMaxLength

      public BaseServer setMaxLength(int len)
    • linger

      public int linger()
    • linger

      public BaseServer linger(int linger)
    • tcpNodelay

      public boolean tcpNodelay()
    • tcpNodelay

      public BaseServer tcpNodelay(boolean tcp_nodelay)
    • running

      public boolean running()
    • getNumConnections

      public int getNumConnections()
    • getNumOpenConnections

      public int getNumOpenConnections()
    • start

      public void start() throws Exception
      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

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • flush

      public void flush(Address dest)
    • flushAll

      public void flushAll()
    • receive

      public void receive(Address sender, byte[] data, int offset, int length)
      Called by a 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)
    • receive

      public void receive(Address sender, ByteBuffer buf)
      Called by a Connection implementation when a message has been received
    • receive

      public void receive(Address sender, DataInput in, int len) throws Exception
      Throws:
      Exception
    • send

      public void send(Address dest, byte[] data, int offset, int length) throws Exception
      Throws:
      Exception
    • send

      public void send(Address dest, ByteBuffer data) throws Exception
      Throws:
      Exception
    • connectionClosed

      public void connectionClosed(Connection conn)
      Specified by:
      connectionClosed in interface ConnectionListener
    • connectionEstablished

      public void connectionEstablished(Connection conn)
      Specified by:
      connectionEstablished in interface ConnectionListener
    • createConnection

      protected abstract Connection createConnection(Address dest) throws Exception
      Creates a new connection object to target dest, but doesn't yet connect it
      Throws:
      Exception
    • hasConnection

      public boolean hasConnection(Address address)
    • connectionEstablishedTo

      public boolean connectionEstablishedTo(Address address)
    • getConnection

      public Connection getConnection(Address dest, boolean retry) throws Exception
      Throws:
      Exception
    • getConnection

      public Connection getConnection(Address dest) throws Exception
      Creates a new connection to dest, or returns an existing one
      Throws:
      Exception
    • replaceConnection

      public void replaceConnection(Address address, Connection conn)
    • closeConnection

      public void closeConnection(Connection conn)
    • closeConnection

      public void closeConnection(Connection conn, boolean notify)
    • closeConnection

      public boolean closeConnection(Address addr)
    • closeConnection

      public boolean closeConnection(Address addr, boolean notify)
    • addConnection

      public void addConnection(Address peer_addr, Connection conn) throws Exception
      Throws:
      Exception
    • addConnectionListener

      public BaseServer addConnectionListener(ConnectionListener cl)
    • removeConnectionListener

      public BaseServer removeConnectionListener(ConnectionListener cl)
    • printConnections

      public String printConnections()
    • removeConnectionIfPresent

      public void removeConnectionIfPresent(Address address, Connection conn)
      Only removes the connection if conns.get(address) == conn
    • clearConnections

      public void clearConnections()
      Used only for testing !
    • forAllConnections

      public void forAllConnections(BiConsumer<Address,Connection> c)
    • retainAll

      public void retainAll(Collection<Address> current_mbrs)
      Removes all connections which are not in current_mbrs
    • notifyConnectionClosed

      public void notifyConnectionClosed(Connection conn)
    • notifyConnectionEstablished

      public void notifyConnectionEstablished(Connection conn)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(boolean details)
    • sendToAll

      public void sendToAll(byte[] data, int offset, int length)
    • sendToAll

      public void sendToAll(ByteBuffer data)
    • connected

      protected static boolean connected(Connection c)
    • localAddress

      protected static Address localAddress(InetAddress bind_addr, int local_port, InetAddress external_addr, int external_port)
    • validateArgs

      protected <T> boolean validateArgs(Address dest, T buffer)
    • explanation

      protected static String explanation(boolean connection_existed, boolean replace)