1 3 4 package org.jgroups.tests; 5 6 7 import org.jgroups.Channel; 8 import org.jgroups.JChannel; 9 import org.jgroups.Message; 10 import org.jgroups.MessageListener; 11 import org.jgroups.blocks.PullPushAdapter; 12 13 14 20 public class PullPushTest implements MessageListener { 21 private Channel channel; 22 private PullPushAdapter adapter; 23 24 public void receive(Message msg) { 25 System.out.println("Received msg: " + msg); 26 } 27 28 public byte[] getState() { return null; 30 } 31 32 public void setState(byte[] state) { 33 34 } 35 36 37 public void start() throws Exception { 38 39 channel=new JChannel(); 40 channel.connect("PullPushTest"); 41 adapter=new PullPushAdapter(channel); 42 adapter.setListener(this); 43 44 for(int i=0; i < 10; i++) { 45 System.out.println("Sending msg #" + i); 46 adapter.send(new Message(null, null, "Hello world".getBytes())); 47 Thread.sleep(1000); 48 } 49 50 channel.close(); 51 } 52 53 54 public static void main(String args[]) { 55 PullPushTest t=new PullPushTest(); 56 try { 57 t.start(); 58 } 59 catch(Exception e) { 60 System.err.println(e); 61 } 62 } 63 64 } 65 | Popular Tags |