jadex.rules.state.IProfiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-rules Show documentation
Show all versions of jadex-rules Show documentation
Jadex Rules is a small lightweight rule engine, which currently
employs the well-known Rete algorithm for highly efficient rule
matching. Jadex rules is therefore similar to other rule engines
like JESS and Drools. Despite the similarities there are also
important differences between these systems:
* Jadex Rules is very small and
intended to be used as component
of other software. Even though rules can be specified in a Java
dialect as well as (a small variation of) the CLIPS language
its primary usage is on the API level. Jadex Rules is currently
the core component of the Jadex BDI reasoning engine.
* Jadex Rules cleanly separates between state and rule representation.
This allows the state implementation as well as the matcher to be
flexibly exchanged. Some experiments have e.g. been conducted with
a Jena representation. Regarding the matcher, it is planned to
support also the Treat algorithm, which has a lower memory footprint
than Rete.
* Jadex Rules pays close attention to rule debugging. The state as
well as the rete engine can be observed at runtime. The rule debugger
provides functionalities to execute a rule program stepwise and also
use rule breakpoints to stop the execution at those points.
package jadex.rules.state;
import jadex.commons.SUtil;
import java.io.ObjectStreamException;
import java.io.Serializable;
/**
* A profiler stores execution information, such as
* time and memory consumption. The application has
* to call the start()/stop() for information
* on specific items being collected.
*/
public interface IProfiler
{
//-------- constants --------
/** The dummy root type (not used for ordering). */
public static final String TYPE_ROOT = "root";
/** The rule type. */
public static final String TYPE_RULE = "rule";
/** The object-type type. */
public static final String TYPE_OBJECT = "object";
/** The object event type (see objectevent_xxx for possible items). */
public static final String TYPE_OBJECTEVENT = "objectevent";
/** The rete-node type. */
public static final String TYPE_NODE = "node";
/** The rete-node event type (see nodeevent_xxx for possible items). */
public static final String TYPE_NODEEVENT = "nodeevent";
/** The object added event item. */
public static final String OBJECTEVENT_ADDED = "StateObjectAdded";
/** The object removed event item. */
public static final String OBJECTEVENT_REMOVED = "StateObjectRemoved";
/** The object modified event item. */
public static final String OBJECTEVENT_MODIFIED = "StateObjectModified";
/** The node object added event item. */
public static final String NODEEVENT_OBJECTADDED = "NodeObjectAdded";
/** The node object removed event item. */
public static final String NODEEVENT_OBJECTREMOVED = "NodeObjectRemoved";
/** The node object modified event item. */
public static final String NODEEVENT_OBJECTMODIFIED = "NodeObjectModified";
/** The node tuple added event item. */
public static final String NODEEVENT_TUPLEADDED = "NodeTupleAdded";
/** The node tuple removed event item. */
public static final String NODEEVENT_TUPLEREMOVED = "NodeTupleRemoved";
/** The node tuple modified event item. */
public static final String NODEEVENT_TUPLEMODIFIED = "NodeTupleModified";
//-------- methods --------
/**
* Start profiling an item. Nesting (i.e. calling start() several times before
* calling corresponding stops) is allowed.
* @param type A constant representing the event or activity type being profiled (e.g. object added).
* @param item The element corresponding to the activity (e.g. the object type).
*/
public void start(String type, Object item);
/**
* Stop profiling the current item.
* Calls to stop() have match the last unstopped call to start(), with respect to the supplied types and items.
* @param type A constant representing the event or activity type being profiled (e.g. object added).
* @param item The element corresponding to the activity (e.g. the object type).
*/
public void stop(String type, Object item);
/**
* Get the current profiling infos from the given start index.
* @param start The start index (use 0 for all profiling infos).
*/
public ProfilingInfo[] getProfilingInfos(int start);
/**
* Struct for profiling information.
*/
public static class ProfilingInfo implements Serializable
{
//-------- attributes --------
/** The profiling event type. */
public String type;
/** The profiling item. */
public Object item;
/** The parent profiling info. */
public ProfilingInfo parent;
/** The total time. */
public long time;
/** The inherent total time. */
public long inherent;
//-------- constructors --------
/**
* Create a new profiling info.
*/
public ProfilingInfo(String type, Object item, ProfilingInfo parent, long time, long inherent)
{
this.type = type;
this.item = item;
this.parent = parent;
this.time = time;
this.inherent = inherent;
}
//-------- methods --------
/**
* Create a string representation of the profile.
*/
public String toString()
{
return type+"(item="+item+" time="+time+" inherent="+inherent+")";
}
/**
* Test, if two nodes are equal.
*/
public boolean equals(Object o)
{
boolean ret = o instanceof ProfilingInfo;
if(ret)
{
ProfilingInfo info = (ProfilingInfo)o;
ret = SUtil.equals(type, info.type) && SUtil.equals(item, info.item);
}
return ret;
}
/**
* Test, if two nodes are equal.
*/
public int hashCode()
{
int ret = 1;
ret = ret*31 + (type!=null ? type.hashCode() : 0);
ret = ret*31 + (item!=null ? item.hashCode() : 0);
return ret;
}
//-------- serialization handling --------
/**
* Close frame before serialization.
*/
protected Object writeReplace() throws ObjectStreamException
{
item = item!=null ? item.toString() : null;
return this;
}
}
}