001: // $Id: PRINTOBJS.java,v 1.4 2005/05/30 14:31:07 belaban Exp $
002:
003: package org.jgroups.protocols;
004:
005: import org.jgroups.Event;
006: import org.jgroups.Message;
007: import org.jgroups.stack.Protocol;
008:
009: public class PRINTOBJS extends Protocol {
010:
011: public PRINTOBJS() {
012: }
013:
014: public String getName() {
015: return "PRINTOBJS";
016: }
017:
018: public void up(Event evt) {
019: Object obj = null;
020: byte[] buf;
021: Message msg;
022:
023: if (evt.getType() != Event.MSG) {
024: System.out
025: .println("------------ PRINTOBJS (received event) ----------------");
026: System.out.println(evt);
027: System.out
028: .println("--------------------------------------------------------");
029: passUp(evt);
030: return;
031: }
032:
033: msg = (Message) evt.getArg();
034: if (msg.getLength() > 0) {
035: try {
036: obj = msg.getObject();
037: } catch (ClassCastException cast_ex) {
038: System.out
039: .println("------------ PRINTOBJS (received) ----------------------");
040: System.out.println(msg);
041: System.out
042: .println("--------------------------------------------------------");
043: passUp(evt);
044: return;
045: } catch (Exception e) {
046: log.error(e);
047: }
048:
049: System.out
050: .println("------------ PRINTOBJS (received) ----------------------");
051: System.out.println(obj);
052: System.out
053: .println("--------------------------------------------------------");
054: } else
055: System.out
056: .println("------- PRINTOBJS (received null msg from "
057: + msg.getSrc()
058: + ", headers are "
059: + msg.printObjectHeaders() + ") --------");
060:
061: passUp(evt);
062: }
063:
064: public void down(Event evt) {
065: Object obj = null;
066: byte[] buf;
067: Message msg;
068:
069: if (evt.getType() != Event.MSG) {
070: System.out
071: .println("------------ PRINTOBJS (sent event) --------------------");
072: System.out.println(evt);
073: System.out
074: .println("--------------------------------------------------------");
075: passDown(evt);
076: return;
077: }
078:
079: msg = (Message) evt.getArg();
080: if (msg.getLength() > 0) {
081: try {
082: obj = msg.getObject();
083: } catch (ClassCastException cast_ex) {
084: System.out
085: .println("------------ PRINTOBJS (sent) --------------------------");
086: System.out.println(msg);
087: System.out
088: .println("--------------------------------------------------------");
089: passDown(evt);
090: return;
091: } catch (Exception e) {
092: log.error(e);
093: }
094:
095: System.out
096: .println("------------ PRINTOBJS (sent) --------------------------");
097: System.out.println(obj);
098: System.out
099: .println("--------------------------------------------------------");
100: } else
101: System.out.println("------- PRINTOBJS (sent null msg to "
102: + msg.getDest() + ", headers are "
103: + msg.printObjectHeaders() + " ) -------------");
104:
105: passDown(evt);
106: }
107:
108: public void reset() {
109: System.out.println("PRINTOBJS protocol is reset");
110: }
111:
112: public String toString() {
113: return "Protocol PRINTOBJS";
114: }
115:
116: }
|