1 package org.jgroups.tests; 2 3 import org.jgroups.*; 4 import org.jgroups.util.Util; 5 6 10 public class ChannelCallbackTest extends ReceiverAdapter implements ChannelListener { 11 JChannel channel; 12 13 public static void main(String [] args) { 14 try { 15 new ChannelCallbackTest().start(); 16 } 17 catch(ChannelException e) { 18 e.printStackTrace(); 19 } 20 } 21 22 private void start() throws ChannelException { 23 channel=new JChannel(); 24 channel.setReceiver(this); 25 channel.addChannelListener(this); 26 channel.connect("bla"); 27 channel.send(null, null, "hello world"); 28 Util.sleep(3000); 29 channel.close(); 30 } 31 32 public void receive(Message msg) { 33 System.out.println("-- MSG: " + msg); 34 try { 35 Address dst=msg.getDest(); 36 if(dst == null || dst.isMulticastAddress()) 37 channel.send(msg.getSrc(), null, "this is a response"); 38 } 39 catch(Exception e) { 40 e.printStackTrace(); 41 } 42 } 43 44 public void viewAccepted(View new_view) { 45 System.out.println("-- VIEW: " + new_view); 46 } 47 48 public void channelConnected(Channel channel) { 49 System.out.println("-- channel connected: " + channel); 50 } 51 52 public void channelDisconnected(Channel channel) { 53 System.out.println("-- channel disconnected: " + channel); 54 } 55 56 public void channelClosed(Channel channel) { 57 System.out.println("-- channel closed: " + channel); 58 } 59 60 public void channelShunned() { 61 System.out.println("-- channel shunned"); 62 } 63 64 public void channelReconnected(Address addr) { 65 System.out.println("-- channel reconnected: " + addr); 66 } 67 68 } 69 | Popular Tags |