package lava.net.psyc.packages; import lava.net.common.UNL; import lava.net.psyc.PSYCDeliveryException; import lava.net.psyc.PSYCMessageCenter; import lava.net.psyc.PSYCPackage; /** * **/ public class Trace extends Skeleton { /** * **/ public final static String PackageName = "Trace"; /** * **/ public final static String requestTraceTag = "_request_trace"; /** * **/ private final static String[] requestTraceAliases = {"request_trace"}; /** * **/ public final static String echoTraceTag = "_echo_trace"; /** * **/ private final static String[] echoTraceAliases = // {"echo_trace"}; class DummyListener implements TraceListener { /** * **/ public void tracePing(UNL source, String body) { try { Trace.this.pong(source,body); } catch(PSYCDeliveryException e) { } } /** * **/ public void tracePong(UNL source, String body) { } } /** * **/ private TraceListener listener = new DummyListener(); /** * **/ public Trace() { this (null); } /** * **/ public Trace(TraceListener listener) { super(); setPackageName(PackageName); addPackageMethod(requestTraceTag,requestTraceAliases,true); addPackageMethod(echoTraceTag,echoTraceAliases,true); if(listener != null) this.listener = listener; } /** * **/ public boolean understands() { return !(listener instanceof DummyListener); } /** * **/ public void received(UNL source, String method, String body) { if(requestTraceTag.equals(method)) listener.tracePing(source,body); else if(echoTraceTag.equals(method)) listener.tracePong(source,body); } /** * **/ public void trace(UNL target, String body) throws PSYCDeliveryException { center.sendChecked(target,PackageName,requestTraceTag,body); } /** * **/ public void trace(UNL target) throws PSYCDeliveryException { trace(target,null); } /** * **/ public void pong(UNL target, String body) throws PSYCDeliveryException { center.sendChecked(target,PackageName,echoTraceTag,body); } /** * **/ public void pong(UNL target) throws PSYCDeliveryException { pong(target,null); } }