Package org.jgroups.demos
Class PubClient
- java.lang.Object
-
- org.jgroups.blocks.cs.ReceiverAdapter
-
- org.jgroups.demos.PubClient
-
- All Implemented Interfaces:
ConnectionListener,Receiver
public class PubClient extends ReceiverAdapter implements 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
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected BaseServerclientprotected java.io.InputStreaminprotected java.lang.Stringnameprotected booleanrunning
-
Constructor Summary
Constructors Constructor Description PubClient(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconnectionClosed(Connection conn)voidconnectionEstablished(Connection conn)protected voideventLoop()protected static voidhelp()static voidmain(java.lang.String[] args)voidreceive(Address sender, byte[] buf, int offset, int length)Delivers a message from a given sender to the applicationvoidreceive(Address sender, java.io.DataInput in)voidreceive(Address sender, java.nio.ByteBuffer buf)The default implementation assumes thatByteBuffer.flip()orByteBuffer.rewind()was called on buf before invoking this callbackprotected voidsend(java.lang.String str)protected voidstart(java.net.InetAddress srv_addr, int srv_port, boolean nio)
-
-
-
Field Detail
-
client
protected BaseServer client
-
name
protected final java.lang.String name
-
running
protected volatile boolean running
-
in
protected java.io.InputStream in
-
-
Method Detail
-
receive
public void receive(Address sender, java.nio.ByteBuffer buf)
Description copied from class:ReceiverAdapterThe default implementation assumes thatByteBuffer.flip()orByteBuffer.rewind()was called on buf before invoking this callback- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Parameters:
sender- The sender of the messagebuf- 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:ReceiverDelivers a message from a given sender to the application- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Parameters:
sender- The sender of the messagebuf- 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 startslength- The length of the received data
-
receive
public void receive(Address sender, java.io.DataInput in) throws java.lang.Exception
- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Throws:
java.lang.Exception
-
connectionClosed
public void connectionClosed(Connection conn)
- Specified by:
connectionClosedin interfaceConnectionListener
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablishedin interfaceConnectionListener
-
start
protected void start(java.net.InetAddress srv_addr, int srv_port, boolean nio) throws java.lang.Exception- Throws:
java.lang.Exception
-
eventLoop
protected void eventLoop()
-
send
protected void send(java.lang.String str) throws java.lang.Exception- Throws:
java.lang.Exception
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
help
protected static void help()
-
-