1 18 package org.apache.geronimo.interop.rmi; 19 20 import org.apache.geronimo.interop.util.StringUtil; 21 22 23 public class RmiTrace { 24 public static final boolean ENABLED = true; 25 public static final boolean CONNECT = true; 26 27 public RmiTrace() { 28 } 29 30 public static void receive(String host, byte[] data) { 31 dump(formatReceiveHeader(host), data); 32 } 33 34 public static void send(String host, byte[] data) { 35 dump(formatSendHeader(host), data); 36 } 37 38 public static void dump(String header, byte[] data) { 39 traceRmiHeader(header); 40 StringBuffer dataBuffer = new StringBuffer (44); 41 StringBuffer textBuffer = new StringBuffer (20); 42 for (int i = 0; i < data.length; i++) { 43 int d = (data[i] + 0x100) & 0xff; 44 String h = StringUtil.padLeft(Integer.toHexString(d).toUpperCase(), '0', 2); 45 dataBuffer.append(h); 46 if (i % 4 == 3 && i % 20 != 19) { 47 dataBuffer.append(' '); 48 } 49 char c = (char) d; 50 if (c < 32 || c > 127) { 51 c = '.'; 52 } 53 textBuffer.append(c); 54 if (i % 20 == 19) { 55 traceRmi(StringUtil.padRight(dataBuffer.toString(), ' ', 44), textBuffer.toString()); 56 dataBuffer.setLength(0); 57 textBuffer.setLength(0); 58 } 59 } 60 if (dataBuffer.length() != 0) { 61 traceRmi(StringUtil.padRight(dataBuffer.toString(), ' ', 44), textBuffer.toString()); 62 } 63 } 64 65 67 protected static String formatReceiveHeader(String host) { 68 String msg; 69 msg = "RmiTrace.formatReceiveHeader(): host: " + host; 70 return msg; 71 } 72 73 protected static String formatSendHeader(String host) { 74 String msg; 75 msg = "RmiTrace.formatSendHeader(): host: " + host; 76 return msg; 77 } 78 79 80 82 public static void traceConnect(String endpoint) { 83 System.out.println("RmiTrace.traceConnect(): endpoint: " + endpoint); 84 } 85 86 public static void traceDisconnect(String endpoint) { 87 System.out.println("RmiTrace.traceDisconnect(): endpoint: " + endpoint); 88 } 89 90 protected static void traceRmiHeader(String header) { 91 System.out.println("RmiTrace.traceRmiHeader(): header: " + header); 92 } 93 94 protected static void traceRmi(String data, String text) { 95 System.out.println("RmiTrace.traceRmi(): data: " + data + ", text: " + text); 96 } 97 98 } 99 | Popular Tags |