01: package org.jgroups.tests;
02:
03: import org.jgroups.*;
04: import org.jgroups.util.Util;
05:
06: /**
07: * @author Bela Ban
08: * @version $Id: ChannelCallbackTest.java,v 1.1 2005/12/09 14:15:14 belaban Exp $
09: */
10: public class ChannelCallbackTest extends ReceiverAdapter implements
11: ChannelListener {
12: JChannel channel;
13:
14: public static void main(String[] args) {
15: try {
16: new ChannelCallbackTest().start();
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: } catch (Exception e) {
39: e.printStackTrace();
40: }
41: }
42:
43: public void viewAccepted(View new_view) {
44: System.out.println("-- VIEW: " + new_view);
45: }
46:
47: public void channelConnected(Channel channel) {
48: System.out.println("-- channel connected: " + channel);
49: }
50:
51: public void channelDisconnected(Channel channel) {
52: System.out.println("-- channel disconnected: " + channel);
53: }
54:
55: public void channelClosed(Channel channel) {
56: System.out.println("-- channel closed: " + channel);
57: }
58:
59: public void channelShunned() {
60: System.out.println("-- channel shunned");
61: }
62:
63: public void channelReconnected(Address addr) {
64: System.out.println("-- channel reconnected: " + addr);
65: }
66:
67: }
|