1 22 package org.jboss.javagroups.protocols; 23 24 import org.jgroups.Event; 25 import org.jgroups.Message; 26 import org.jgroups.stack.Protocol; 27 import org.jboss.logging.Logger; 28 29 import java.util.Properties ; 30 import java.util.Map ; 31 import java.util.Iterator ; 32 33 72 public class EVENT_TRACE extends Protocol 73 { 74 private String name = "EVENT_TRACE"; 75 private Logger log; 76 77 public String getName() 78 { 79 return name; 80 } 81 82 86 public boolean setProperties(Properties props) 87 { 88 super.setProperties(props); 89 name = props.getProperty("name", name); 90 log = Logger.getLogger("org.jboss.jgroups."+name); 91 return true; 92 } 93 94 public void up(Event event) 95 { 96 if( log.isTraceEnabled() ) 97 { 98 log.trace("up, event="+event); 99 if( event.getType() == Event.MSG ) 100 { 101 Message msg = (Message) event.getArg(); 102 msg.getHeaders(); 103 log.trace("up, MsgHeader: "+printEventMsg(msg)); 104 } 105 } 106 passUp(event); 108 } 109 110 public void down(Event event) 111 { 112 if( log.isTraceEnabled() ) 113 { 114 log.trace("down, event="+event); 115 if( event.getType() == Event.MSG ) 116 { 117 Message msg = (Message) event.getArg(); 118 log.trace("down, MsgHeader: "+printEventMsg(msg)); 119 } 120 } 121 passDown(event); 123 } 124 125 public String printEventMsg(Message msg) 126 { 127 StringBuffer sb = new StringBuffer (); 128 Map.Entry entry; 129 Map headers = msg.getHeaders(); 130 if (headers != null) 131 { 132 Iterator iter = headers.entrySet().iterator(); 133 while( iter.hasNext() ) 134 { 135 entry = (Map.Entry ) iter.next(); 136 Object key = entry.getKey(); 137 Object value = entry.getValue(); 138 sb.append(key); 139 sb.append(", value("); 140 sb.append(value.getClass()); 141 sb.append("): "); 142 sb.append(value.toString()); 143 sb.append("\n"); 144 } 145 } 146 return sb.toString(); 147 } 148 149 } | Popular Tags |