Class PubClient

java.lang.Object
org.jgroups.demos.PubClient
All Implemented Interfaces:
ConnectionListener, Receiver

public class PubClient extends Object implements Receiver, ConnectionListener
Demo of a client which connects to a server (PubServer) and sends it messages which are forwarded to all connected clients
Since:
3.6.5
  • Field Details

    • client

      protected BaseServer client
    • name

      protected final String name
    • running

      protected volatile boolean running
    • in

      protected InputStream in
  • Constructor Details

    • PubClient

      public PubClient(String name)
  • Method Details

    • receive

      public void receive(Address sender, ByteBuffer buf)
      Description copied from interface: Receiver
      Delivers a message from a given sender to the application
      Specified by:
      receive in interface Receiver
      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.

      Note that buf could be a direct ByteBuffer.

    • 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
      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) throws Exception
      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
      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
    • start

      protected void start(InetAddress srv_addr, int srv_port, boolean nio) throws Exception
      Throws:
      Exception
    • eventLoop

      protected void eventLoop()
    • send

      protected void send(String str) throws Exception
      Throws:
      Exception
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception
    • help

      protected static void help()