org.cougaar.pizza.servlet
Class HistoryServlet

java.lang.Object
  extended byorg.cougaar.util.GenericStateModelAdapter
      extended byorg.cougaar.core.blackboard.BlackboardClientComponent
          extended byorg.cougaar.core.plugin.ComponentPlugin
              extended byorg.cougaar.pizza.servlet.HistoryServlet
All Implemented Interfaces:
org.cougaar.core.blackboard.BlackboardClient, org.cougaar.core.component.Component, org.cougaar.util.GenericStateModel, org.cougaar.core.plugin.PluginBase

public class HistoryServlet
extends org.cougaar.core.plugin.ComponentPlugin

Generic debugging servlet/plugin that displays all Adds/Changes/Removes on Blackboard objects, accessed at "/history".

Specifically tracks changes on Relays, Tasks, PlanElements, Assets, UniqueObjects, and implementations of HistoryServletFriendly. For every event, attempts to explain the event. For instance, when a Relay is first published, it shows which Agent the Relay is being sent to.

The Servlet lets the user sort events by time, then by uid, or by uid only. Sorting by uid shows the complete lifecycle of a Blackboard object; especially useful for transient objects that live on the Blackboard only a short time. When sorting by time, each group of changes that happens in the same execute cycle is drawn with the same background color. When sorting by uid, each distinct object is drawn with the same background color.

The servlet has a "show details" link which will show the toString for the blackboard object at that time. This is a spot where developers can tune how this servlet displays their objects.

The "Meaning" column uses the HistoryServletFriendly's toHTML() method to fill in content when available.

Also shows which plugin initially published an object to the Blackboard if that information is available (for Claimables).

Try it in any Cougaar Application! Simply add this as a Plugin in any Agent!

Has a default limit of 1000 events, but this can be set by the MAX_EVENTS_REMEMBERED component argument to the servlet. E.g. : <argument>MAX_EVENTS_REMEMBERED=5000</argument>

Another limit: 5 RoleSchedule elements displayed by default, set with MAX_ROLE_SCHEDULE_ELEMENTS argument. And a default of 5 child Tasks shown per Expansion, changed with the MAX_CHILD_TASKS argument.

Note that this Servlet is actually a Plugin, so that it can subscribe to all the blackboard changes, and keeps a SortedSet of these Events, ready for display. It then provides an inner Servlet to the ServletService, so a user can view the pre-collected Events Set.

Note that this Servlet has heavy Planning dependencies. It has minor Community dependencies, to allow printing details in the Meaning column. By commenting out those items, this dependency could be removed.


Nested Class Summary
protected  class HistoryServlet.HistoryFormatter
          The inner class used by the servlet to format the request results.
protected  class HistoryServlet.HistoryWorker
          Inner-class that's registered as the servlet.
 
Nested classes inherited from class org.cougaar.core.blackboard.BlackboardClient
org.cougaar.core.blackboard.BlackboardClient.Local
 
Field Summary
static int ADDED
           
static int ASSET
           
static int CHANGED
           
static int DIRECT_OBJECT
           
protected  java.lang.String encAgentName
           
protected  java.util.SortedSet events
          The actual Blackboard history we collect
protected static java.text.SimpleDateFormat format
           
protected  int INITIAL_MAX_CHILD_TASKS
           
protected  int INITIAL_MAX_ENTRIES
           
protected  int INITIAL_MAX_ROLE_SCHEDULE_ELEMENTS
           
protected  org.cougaar.core.mts.MessageAddress localAgent
           
protected  org.cougaar.core.service.LoggingService logger
           
static int PLAN_ELEMENT
           
static int REMOVED
           
static int TASK
           
static int UNIQUE_OBJECT
           
 
Fields inherited from class org.cougaar.core.blackboard.BlackboardClientComponent
agentId, agentIdentificationService, alarmService, blackboard, blackboardClientName
 
Fields inherited from interface org.cougaar.core.plugin.PluginBase
INSERTION_POINT
 
Fields inherited from interface org.cougaar.util.GenericStateModel
ACTIVE, IDLE, LOADED, UNINITIALIZED, UNLOADED
 
Fields inherited from interface org.cougaar.core.blackboard.BlackboardClient
current
 
Constructor Summary
HistoryServlet()
           
 
Method Summary
protected  void addEvent(org.cougaar.pizza.servlet.HistoryServlet.EventInfo newEvent)
          Add a new event to the list
protected  void checkAssets(long now)
          Add any Asset events to the Set
protected  void checkPlanElements(long now)
          Add any PlanElement events to the Set
protected  void checkRelays(long now)
          Add any Relay events
protected  void checkTasks(long now)
          Check the Tasks subscription, adding any new events to the list
protected  void checkUniqueObjects(long now)
          Add any added/changed/removed UniqueObjects
protected  javax.servlet.Servlet createServlet()
          Get a new HistoryServlet.HistoryWorker to be the Servlet
protected  java.lang.String encode(java.lang.String s)
           
 java.lang.String encodeAgentName(java.lang.String name)
           
protected  java.lang.String encodeHTML(java.lang.String s)
          Encodes a string that may contain HTML syntax-significant characters.
 void execute()
          Whenever a BBoard item changes, it adds that event to the list of Events (trimming the set if we reach the MAX size).
protected  java.lang.String getAddedAssetComment(org.cougaar.planning.ldm.asset.Asset asset)
          Get the ChangedAssetComment
protected  java.lang.String getAddedPEComment(org.cougaar.planning.ldm.plan.PlanElement planElement)
          If it's an Allocation, show the Task Verb and the allocated Asset's Type and ItemID, RoleSchedule.
protected  java.lang.String getAddedRelayComment(org.cougaar.core.relay.Relay relay)
          For a Source: show the target addresses, any community content or request, and the relay's Content.
protected  java.lang.String getAddedTaskComment(org.cougaar.planning.ldm.plan.Task task)
          description of an added Task shows the Verb, DirectObject, and Preferences.
protected  java.lang.String getAddedUniqueObjectComment(org.cougaar.core.util.UniqueObject unique)
          For an Added unique object, print it's name, and any HistoryServletFriendly content
protected  java.lang.String getAspectValue(org.cougaar.planning.ldm.plan.AspectValue avi)
          Get a String representation of this AspectValue
protected  java.lang.String getAspectValues(org.cougaar.planning.ldm.plan.AspectValue[] values, java.lang.String prefix)
          Get an HTML table of these Aspect Values (id'd by the prefix)
protected  java.lang.String getAspectValues2(org.cougaar.planning.ldm.plan.AspectValue[] values)
          Get String representation of these Aspect Values
protected  java.lang.String getChangedAssetComment(org.cougaar.planning.ldm.asset.Asset asset)
          Show the asset class, typeID, ItemID, if an Entity then any Roles, Relationships, RoleSchedule, and the HistoryServletFriendly content
protected  java.lang.String getChangedPEComment(org.cougaar.planning.ldm.plan.PlanElement planElement)
          Show the results on the PE
protected  java.lang.String getChangedRelayComment(org.cougaar.core.relay.Relay relay)
          For a Source, show any community specific information, the Content.
protected  java.lang.String getChangedUniqueObjectComment(org.cougaar.core.util.UniqueObject unique)
          Changed/Removed unique objects use the same comment as for Add
protected  java.lang.String getClassName(java.lang.Object obj)
          Get the non-Package name of the Class
protected  java.lang.String getCommunityText(java.lang.String prefix, org.cougaar.core.service.community.Community community)
          Describe this Community by name, entities
protected  java.lang.String getPath()
          Load this servlet at "/history"
protected  java.lang.String getRemovedUniqueObjectComment(org.cougaar.core.util.UniqueObject unique)
          Changed/Removed unique objects use the same comment as for Add
protected  java.lang.String getRoleSchedule(org.cougaar.planning.ldm.asset.Asset asset)
          Print the RoleSchedule of the Asset if any, up to the maxRoleScheduleElements
protected  java.lang.String getTaskPreferences(org.cougaar.planning.ldm.plan.Task task)
          Get a String HTML table of the Task's preferences
protected  java.lang.String getTimeString(long time)
          Formats long millis time to Date Format String.
protected  java.lang.String getTypeAndItemInfo(org.cougaar.planning.ldm.asset.Asset asset)
          Get the type & item ID of an Asset -- to ID it in the display
protected  java.lang.String getURL(org.cougaar.core.util.UID uid, int which)
          Generate a link to the PlanView (/tasks) servlet for full details on the objet.
 void load()
           
protected  int nextEventNum()
          Get the next number for a new Event
protected  void setEvents(java.util.SortedSet events)
          Reset the stored event list -- used when we've resorted the list.
 void setParameter(java.lang.Object o)
          Only called if a plugin has parameters.
 void setServletService(org.cougaar.core.service.ServletService servletService)
          Get the ServletService via reflection
protected  void setupSubscriptions()
           
protected  java.lang.String showTargetAddresses(org.cougaar.core.relay.Relay.Source sourceRelay)
          Show the target(s) of a relay, including ABAs
protected  void sortByUIDThenTime()
          Sort the events collection by UID and then time.
 void unload()
           
 
Methods inherited from class org.cougaar.core.plugin.ComponentPlugin
getConfigFinder
 
Methods inherited from class org.cougaar.core.blackboard.BlackboardClientComponent
currentTimeMillis, cycle, getAgentIdentifier, getAlarmService, getBindingSite, getBlackboardClientName, getBlackboardService, getMessageAddress, getParameter, getParameters, getServiceBroker, halt, precycle, requestCycle, resume, setAgentIdentificationService, setAlarmService, setBindingSite, setBlackboardService, setSchedulerService, setServiceBroker, setSuicideService, shouldExecute, start, stop, suspend, toString, wasAwakened
 
Methods inherited from class org.cougaar.util.GenericStateModelAdapter
getModelState, initialize, transitState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.cougaar.util.GenericStateModel
getModelState, halt, initialize, resume, start, stop, suspend
 

Field Detail

INITIAL_MAX_ENTRIES

protected final int INITIAL_MAX_ENTRIES
See Also:
Constant Field Values

INITIAL_MAX_ROLE_SCHEDULE_ELEMENTS

protected final int INITIAL_MAX_ROLE_SCHEDULE_ELEMENTS
See Also:
Constant Field Values

INITIAL_MAX_CHILD_TASKS

protected final int INITIAL_MAX_CHILD_TASKS
See Also:
Constant Field Values

localAgent

protected org.cougaar.core.mts.MessageAddress localAgent

logger

protected org.cougaar.core.service.LoggingService logger

format

protected static java.text.SimpleDateFormat format

encAgentName

protected java.lang.String encAgentName

events

protected java.util.SortedSet events
The actual Blackboard history we collect


TASK

public static final int TASK
See Also:
Constant Field Values

PLAN_ELEMENT

public static final int PLAN_ELEMENT
See Also:
Constant Field Values

ASSET

public static final int ASSET
See Also:
Constant Field Values

UNIQUE_OBJECT

public static final int UNIQUE_OBJECT
See Also:
Constant Field Values

DIRECT_OBJECT

public static final int DIRECT_OBJECT
See Also:
Constant Field Values

ADDED

public static final int ADDED
See Also:
Constant Field Values

CHANGED

public static final int CHANGED
See Also:
Constant Field Values

REMOVED

public static final int REMOVED
See Also:
Constant Field Values
Constructor Detail

HistoryServlet

public HistoryServlet()
Method Detail

setParameter

public void setParameter(java.lang.Object o)
Only called if a plugin has parameters. We over-ride this to use the Arguments utility, since all our arguments are NAME=VALUE format.


setServletService

public void setServletService(org.cougaar.core.service.ServletService servletService)
Get the ServletService via reflection


load

public void load()

unload

public void unload()

setupSubscriptions

protected void setupSubscriptions()

getPath

protected java.lang.String getPath()
Load this servlet at "/history"


createServlet

protected javax.servlet.Servlet createServlet()
Get a new HistoryServlet.HistoryWorker to be the Servlet


execute

public void execute()
Whenever a BBoard item changes, it adds that event to the list of Events (trimming the set if we reach the MAX size). Then when a user invokes the servlet, the set of events is ready for quick display.


encodeAgentName

public java.lang.String encodeAgentName(java.lang.String name)

encode

protected java.lang.String encode(java.lang.String s)

getURL

protected java.lang.String getURL(org.cougaar.core.util.UID uid,
                                  int which)
Generate a link to the PlanView (/tasks) servlet for full details on the objet.


nextEventNum

protected int nextEventNum()
Get the next number for a new Event


checkTasks

protected void checkTasks(long now)
Check the Tasks subscription, adding any new events to the list


getAddedTaskComment

protected java.lang.String getAddedTaskComment(org.cougaar.planning.ldm.plan.Task task)
description of an added Task shows the Verb, DirectObject, and Preferences.


checkPlanElements

protected void checkPlanElements(long now)
Add any PlanElement events to the Set


checkRelays

protected void checkRelays(long now)
Add any Relay events


checkAssets

protected void checkAssets(long now)
Add any Asset events to the Set


getAddedAssetComment

protected java.lang.String getAddedAssetComment(org.cougaar.planning.ldm.asset.Asset asset)
Get the ChangedAssetComment


getChangedAssetComment

protected java.lang.String getChangedAssetComment(org.cougaar.planning.ldm.asset.Asset asset)
Show the asset class, typeID, ItemID, if an Entity then any Roles, Relationships, RoleSchedule, and the HistoryServletFriendly content


getRoleSchedule

protected java.lang.String getRoleSchedule(org.cougaar.planning.ldm.asset.Asset asset)
Print the RoleSchedule of the Asset if any, up to the maxRoleScheduleElements


checkUniqueObjects

protected void checkUniqueObjects(long now)
Add any added/changed/removed UniqueObjects


getAddedUniqueObjectComment

protected java.lang.String getAddedUniqueObjectComment(org.cougaar.core.util.UniqueObject unique)
For an Added unique object, print it's name, and any HistoryServletFriendly content


getChangedUniqueObjectComment

protected java.lang.String getChangedUniqueObjectComment(org.cougaar.core.util.UniqueObject unique)
Changed/Removed unique objects use the same comment as for Add


getRemovedUniqueObjectComment

protected java.lang.String getRemovedUniqueObjectComment(org.cougaar.core.util.UniqueObject unique)
Changed/Removed unique objects use the same comment as for Add


getClassName

protected java.lang.String getClassName(java.lang.Object obj)
Get the non-Package name of the Class


getAddedRelayComment

protected java.lang.String getAddedRelayComment(org.cougaar.core.relay.Relay relay)
For a Source: show the target addresses, any community content or request, and the relay's Content.

For a Target, show any community info, the relay Source, and any HistoryServletFriendly content.


showTargetAddresses

protected java.lang.String showTargetAddresses(org.cougaar.core.relay.Relay.Source sourceRelay)
Show the target(s) of a relay, including ABAs


getChangedRelayComment

protected java.lang.String getChangedRelayComment(org.cougaar.core.relay.Relay relay)
For a Source, show any community specific information, the Content.

For a Target, show any community specific information, and the response, and any HistoryServletFriendly content.


getCommunityText

protected java.lang.String getCommunityText(java.lang.String prefix,
                                            org.cougaar.core.service.community.Community community)
Describe this Community by name, entities


getChangedPEComment

protected java.lang.String getChangedPEComment(org.cougaar.planning.ldm.plan.PlanElement planElement)
Show the results on the PE


getAspectValues

protected java.lang.String getAspectValues(org.cougaar.planning.ldm.plan.AspectValue[] values,
                                           java.lang.String prefix)
Get an HTML table of these Aspect Values (id'd by the prefix)


getAspectValues2

protected java.lang.String getAspectValues2(org.cougaar.planning.ldm.plan.AspectValue[] values)
Get String representation of these Aspect Values


getAspectValue

protected java.lang.String getAspectValue(org.cougaar.planning.ldm.plan.AspectValue avi)
Get a String representation of this AspectValue


getTimeString

protected java.lang.String getTimeString(long time)
Formats long millis time to Date Format String.


getTaskPreferences

protected java.lang.String getTaskPreferences(org.cougaar.planning.ldm.plan.Task task)
Get a String HTML table of the Task's preferences


getAddedPEComment

protected java.lang.String getAddedPEComment(org.cougaar.planning.ldm.plan.PlanElement planElement)
If it's an Allocation, show the Task Verb and the allocated Asset's Type and ItemID, RoleSchedule. For an Expansion, show the child tasks (up to the MAX). For an AssetTransfer, show the moving Asset and destination. For an Aggregation, show just the count of parent tasks. For a Disposition, show whether it succeed or failed. Also show any Annotation, Estimated Result, and Reported Result.


getTypeAndItemInfo

protected java.lang.String getTypeAndItemInfo(org.cougaar.planning.ldm.asset.Asset asset)
Get the type & item ID of an Asset -- to ID it in the display


addEvent

protected void addEvent(org.cougaar.pizza.servlet.HistoryServlet.EventInfo newEvent)
Add a new event to the list


setEvents

protected void setEvents(java.util.SortedSet events)
Reset the stored event list -- used when we've resorted the list.


sortByUIDThenTime

protected void sortByUIDThenTime()
Sort the events collection by UID and then time. Then type, then meaning. Updates the single events collection Set


encodeHTML

protected java.lang.String encodeHTML(java.lang.String s)
Encodes a string that may contain HTML syntax-significant characters.