/*
*
* Supports an optional Servlet path parameter, which defaults to "/mesh". *
* For simplicity, it's easiest to load a copy of this servlet into every * agent. */ public class MeshServlet extends ComponentServlet { private long loadTime; private BlackboardQueryService blackboard; /** @return a default path if a plugin parameter is not specified */ protected String getPath() { String ret = super.getPath(); return (ret == null ? "/mesh" : ret); } /** This method is called when the agent is created */ public void load() { super.load(); // Record our load time loadTime = System.currentTimeMillis(); // Get our required Cougaar services this.blackboard = (BlackboardQueryService) getServiceBroker().getService( this, BlackboardQueryService.class, null); } /** This method is called whenever the browser loads our URL. */ public void doGet( HttpServletRequest request, HttpServletResponse response) throws IOException { // Begin our HTML page response response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Agent "+getEncodedAgentName(); out.println( ""+ "
");
// Query the blackboard for relays
UnaryPredicate pred = new UnaryPredicate() {
public boolean execute(Object o) {
return (o instanceof SimpleRelay);
}
};
Collection col = blackboard.query(pred);
// We expect multiple "incoming" relays from different remote targets, each
// with possibly different counter values, plus corresponding "outgoing"
// relays with identical counter values.
//
// So, we'll split our relays into pairs based on the targets.
Map"+
"
");
// Create a "reload" button for the user to invoke our servlet again
out.println(
"");
// End our HTML page
out.println("");
}
}
"+
" "+
""+
" Target "+
" Sent "+
" Received "+
""+
" ");
DecimalFormat formatter = new DecimalFormat("0.000");
for (int i = 0; i < targets.size(); i++) {
String target = targets.get(i);
out.print(
" "+
" UID "+
" Bloat (byte[]) "+
" Count "+
" Throughput (relays/second) "+
" "+
" UID "+
" Bloat (byte[]) "+
" Count "+
" Throughput (relays/second) "+
""+
" "+i+" "+
" "+target+" ");
for (int j = 0; j < 2; j++) {
SimpleRelay relay = (j == 0 ? sent.get(target) : recv.get(target));
out.print(" ");
if (relay == null) {
out.print(" null ");
continue;
}
int bloat = -1;
Object o = relay.getQuery();
if (o instanceof Payload) {
Payload p = (Payload) o;
bloat = p.getBloat();
o = p.getData();
}
long count = ((Long) o).longValue();
double throughput = Double.NaN;
if (count > 0 && runTime > 0) {
throughput = 1000.0 * ((double) count / runTime);
}
out.print(
" "+relay.getUID()+" "+
" "+bloat+" "+
" "+count+" "+
" "+formatter.format(throughput)+" ");
}
out.println("");
}
out.println("