Class RouterStub

All Implemented Interfaces:
Comparable<RouterStub>, ConnectionListener, Receiver

public class RouterStub extends ReceiverAdapter implements Comparable<RouterStub>, ConnectionListener
Client stub that talks to a remote GossipRouter via blocking or non-blocking TCP
  • Field Details

    • client

      protected BaseServer client
    • local

      protected IpAddress local
    • remote

      protected IpAddress remote
    • remote_sa

      protected InetSocketAddress remote_sa
    • use_nio

      protected final boolean use_nio
    • receiver

      protected RouterStub.StubReceiver receiver
    • close_listener

      protected RouterStub.CloseListener close_listener
    • socket_factory

      protected SocketFactory socket_factory
    • log

      protected static final Log log
    • sock_conn_timeout

      protected int sock_conn_timeout
    • tcp_nodelay

      protected boolean tcp_nodelay
    • linger

      protected int linger
    • handle_heartbeats

      protected boolean handle_heartbeats
    • last_heartbeat

      protected volatile long last_heartbeat
    • non_blocking_sends

      protected boolean non_blocking_sends
    • max_send_queue

      protected int max_send_queue
    • get_members_map

      protected final Map<String,List<RouterStub.MembersNotification>> get_members_map
  • Constructor Details

  • Method Details

    • local

      public IpAddress local()
    • remote

      public IpAddress remote()
    • receiver

      public RouterStub receiver(RouterStub.StubReceiver r)
    • receiver

      public RouterStub.StubReceiver receiver()
    • tcpNoDelay

      public boolean tcpNoDelay()
    • tcpNoDelay

      public RouterStub tcpNoDelay(boolean tcp_nodelay)
    • connectionListener

      public RouterStub.CloseListener connectionListener()
    • connectionListener

      public RouterStub connectionListener(RouterStub.CloseListener l)
    • socketConnectionTimeout

      public int socketConnectionTimeout()
    • socketConnectionTimeout

      public RouterStub socketConnectionTimeout(int timeout)
    • useNio

      public boolean useNio()
    • gossipRouterAddress

      public IpAddress gossipRouterAddress()
    • isConnected

      public boolean isConnected()
    • handleHeartbeats

      public RouterStub handleHeartbeats(boolean f)
    • handleHeartbeats

      public boolean handleHeartbeats()
    • lastHeartbeat

      public long lastHeartbeat()
    • getLinger

      public int getLinger()
    • setLinger

      public RouterStub setLinger(int l)
    • nonBlockingSends

      public boolean nonBlockingSends()
    • nonBlockingSends

      public RouterStub nonBlockingSends(boolean b)
    • maxSendQueue

      public int maxSendQueue()
    • maxSendQueue

      public RouterStub maxSendQueue(int s)
    • connect

      public void connect(String group, Address addr, String logical_name, PhysicalAddress phys_addr) throws Exception
      Registers mbr with the GossipRouter under the given group, with the given logical name and physical address. Establishes a connection to the GossipRouter and sends a CONNECT message.
      Parameters:
      group - The group cluster name under which to register the member
      addr - The address of the member
      logical_name - The logical name of the member
      phys_addr - The physical address of the member
      Throws:
      Exception - Thrown when the registration failed
    • connect

      public void connect() throws Exception
      Throws:
      Exception
    • _doConnect

      protected void _doConnect() throws Exception
      Throws:
      Exception
    • disconnect

      public void disconnect(String group, Address addr) throws Exception
      Throws:
      Exception
    • destroy

      public void destroy()
    • getMembers

      public void getMembers(String group, RouterStub.MembersNotification callback) throws Exception
      Fetches a list of PingData from the GossipRouter, one for each member in the given group. This call returns immediately and when the results are available, the RouterStub.MembersNotification.members(List) callback will be invoked.
      Parameters:
      group - The group for which we need members information
      callback - The callback to be invoked.
      Throws:
      Exception
    • sendToAllMembers

      public void sendToAllMembers(String group, Address sender, byte[] data, int offset, int length) throws Exception
      Throws:
      Exception
    • sendToMember

      public void sendToMember(String group, Address dest, Address sender, byte[] data, int offset, int length) throws Exception
      Throws:
      Exception
    • receive

      public void receive(Address sender, byte[] buf, int offset, int length)
      Description copied from interface: Receiver
      Delivers a message from a given sender to the application
      Specified by:
      receive in interface Receiver
      Overrides:
      receive in class ReceiverAdapter
      Parameters:
      sender - The sender of the message
      buf - The buffer. An application typically de-serializes data from the buffer into objects used by the application. Note that when receive() returns, it is not safe to use the buffer any longer; if an application needs to use a buffer after this callback returns, it must make a copy.
      offset - The offset at which the received data starts
      length - The length of the received data
    • receive

      public void receive(Address sender, DataInput in, int length)
      Description copied from interface: Receiver
      Receive data from the given sender
      Specified by:
      receive in interface Receiver
      Parameters:
      sender - The sender
      in - The data input from which to read
      length - The number of bytes to read
    • connectionClosed

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

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

      public int compareTo(RouterStub o)
      Specified by:
      compareTo in interface Comparable<RouterStub>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

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

      protected boolean resolveRemoteAddress()
      Creates remote from remote_sa. If the latter is unresolved, tries to resolve it one more time (e.g. via DNS)
    • createClient

      protected BaseServer createClient(SocketFactory sf)
    • writeRequest

      public void writeRequest(GossipData req) throws Exception
      Throws:
      Exception
    • removeResponse

      protected void removeResponse(String group, RouterStub.MembersNotification notif)
    • notifyResponse

      protected void notifyResponse(String group, List<PingData> list)