KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > protocols > PRINTOBJS


1 // $Id: PRINTOBJS.java,v 1.3 2004/03/30 06:47:21 belaban Exp $
2

3 package org.jgroups.protocols;
4
5 import org.jgroups.Event;
6 import org.jgroups.Message;
7 import org.jgroups.stack.Protocol;
8
9
10 public class PRINTOBJS extends Protocol {
11
12     public PRINTOBJS() {
13     }
14
15     public String JavaDoc getName() {
16         return "PRINTOBJS";
17     }
18
19
20     public void up(Event evt) {
21         Object JavaDoc obj=null;
22         byte[] buf;
23         Message msg;
24
25         if(evt.getType() != Event.MSG) {
26             System.out.println("------------ PRINTOBJS (received event) ----------------");
27             System.out.println(evt);
28             System.out.println("--------------------------------------------------------");
29             passUp(evt);
30             return;
31         }
32
33         msg=(Message)evt.getArg();
34         if(msg.getLength() > 0) {
35             try {
36                 obj=msg.getObject();
37             }
38             catch(ClassCastException JavaDoc cast_ex) {
39                 System.out.println("------------ PRINTOBJS (received) ----------------------");
40                 System.out.println(msg);
41                 System.out.println("--------------------------------------------------------");
42                 passUp(evt);
43                 return;
44             }
45             catch(Exception JavaDoc e) {
46                 System.err.println(e);
47             }
48
49             System.out.println("------------ PRINTOBJS (received) ----------------------");
50             System.out.println(obj);
51             System.out.println("--------------------------------------------------------");
52         }
53         else
54             System.out.println("------- PRINTOBJS (received null msg from " + msg.getSrc() + ", headers are " +
55                     msg.printObjectHeaders() + ") --------");
56
57         passUp(evt);
58     }
59
60
61     public void down(Event evt) {
62         Object JavaDoc obj=null;
63         byte[] buf;
64         Message msg;
65
66         if(evt.getType() != Event.MSG) {
67             System.out.println("------------ PRINTOBJS (sent event) --------------------");
68             System.out.println(evt);
69             System.out.println("--------------------------------------------------------");
70             passDown(evt);
71             return;
72         }
73
74         msg=(Message)evt.getArg();
75         if(msg.getLength() > 0) {
76             try {
77                 obj=msg.getObject();
78             }
79             catch(ClassCastException JavaDoc cast_ex) {
80                 System.out.println("------------ PRINTOBJS (sent) --------------------------");
81                 System.out.println(msg);
82                 System.out.println("--------------------------------------------------------");
83                 passDown(evt);
84                 return;
85             }
86             catch(Exception JavaDoc e) {
87                 System.err.println(e);
88             }
89
90             System.out.println("------------ PRINTOBJS (sent) --------------------------");
91             System.out.println(obj);
92             System.out.println("--------------------------------------------------------");
93         }
94         else
95             System.out.println("------- PRINTOBJS (sent null msg to " + msg.getDest() + ", headers are " +
96                     msg.printObjectHeaders() + " ) -------------");
97
98         passDown(evt);
99     }
100
101
102     public void reset() {
103         System.out.println("PRINTOBJS protocol is reset");
104     }
105
106     public String JavaDoc toString() {
107         return "Protocol PRINTOBJS";
108     }
109
110
111 }
112
Popular Tags