import lava.net.common.*; import lava.net.mmp.MMPMessageCenter; import lava.net.psyc.*; import java.util.*; import java.net.*; /** * **/ public class PSYCTest implements PSYCPacketManager { /** * **/ PSYCMessageCenter m = null; /** * **/ public void manage(PSYCPacket p) { System.out.print("Got Packet from " + p.getSource()); String[] names = m.getVars(p.getSource()); if(names.length <= 0) System.out.print(" (no variables)"); if(p.getMethod() == null || p.getMethod().length() <= 0) System.out.print(" (no method)"); if(p.getStringBody() == null || p.getStringBody().length() <= 0) System.out.print(" (empty body)"); System.out.println(); if(names.length > 0) { System.out.print(" Vars: "); int i = 0; for(;i < names.length - 1;++i) System.out.print(names[i] + ", "); System.out.println(names.length == 0 ? "" : names[i]); } if(p.getMethod() != null && p.getMethod().length() > 0) System.out.println(" Meth: " + p.getMethod()); if(p.getStringBody() != null && p.getStringBody().length() > 0) System.out.println(" Body: " + p.getStringBody()); //m.send(p.getSource(), null, p); } /** * **/ public void error(PSYCException e, UNL destination) { System.out.println("Got Error: " + e + ", from " + // (destination != null ? destination.toString() : "(null)")); } /** * **/ public void reset(UNL destination) { System.out.println("Got connection reset from " + // (destination != null ? destination.toString() : "(null)")); } /** * **/ public static void main(String[] args) { PSYCTest t = new PSYCTest(); if(args.length > 0) if(args.length == 1 && // (args[0].equals("-n") || args[0].equals("--nolisten"))) t.m = new PSYCMessageCenter(t,false); else { UNA[] listen = new UNA[args.length]; for(int i = 0;i < args.length;++i) listen[i] = new UNA(args[i]); t.m = new PSYCMessageCenter(t,listen); } else t.m = new PSYCMessageCenter(t); ((MMPMessageCenter)t.m.getMMPCenter()).answerCounterWithCounter(true); System.out.print("PSYC Message Center "); UNA[] listen = t.m.getMMPCenter().getListenLocations(); if(listen.length <= 0) System.out.println("does not listen!"); else System.out.println("is listening on:"); for(int i = 0;i < listen.length;++i) System.out.println(" " + listen[i].toString()); } }