lookupEvent Method
An Event may be created at the top-level under the Listener object, as a subordinate of a Container object, or subordinate to another Event object (a sub-Event). In the first two cases, the programmer must specify the event class of the Event, while in the latter case, the class must be the same as the parent Event object's class.
This method will create an Event object only when that object does not already exist. If the object already exists, the existing object is returned.
When
using the Listener object or a Container object to create an Event,
the event class must be specified. Java™ does not support the use
of enumerated types, therefore, the event class is expressed as
an instance of the PCHeventClass class. This is a type safe enumeration
in Java™ which is limited
to the pre-created definitions PCHeventClass.RPC and PCHeventClass.USER.
When creating an Event subordinate to another Event (sub-Event), the event class is not specified because sub-Events must have the same class as their parent Event object.
Syntax (Top-level)
Top-level Event objects exist directly under the Listener object (their Container object is null) and may be created using the following constructor:
Event
lookupEvent([PCHeventClass.RPC || PCHeventClass.USER], String
eventName, [optional] boolean includeParent);
Syntax (Subordinate to a Container)
Subordinate Event objects of a Container object must be created using the following constructor:
Event lookupEvent([PCHeventClass.RPC
|| PCHeventClass.USER], String eventName, [optional] boolean
includeParent);
Syntax (sub-Event)
Sub-Events (subordinate Event objects of another Event object) may be created using the following constructor:
Event lookupEvent(String
eventName, [optional] boolean includeParent);
Parameters
- eventClass
- [in] Required instance of the PCHeventClass
class, that specifies the class of the event. This is a type safe
enumeration in Java which
is limited to the pre-created definitions
PCHeventClass.RPCandPCHeventClass.USER. When using the Listener object or a Container object to create an Event, the event class must be specified. When creating an Event subordinate to another Event (sub-Event), the event class is not specified because sub-Events must have the same class as their parent Event object. - eventName
- [in] Required String, which provides the name of the Event object. The string may be passed as Unicode that contains any printable characters, excluding the newline character.
- includeParent
- [in] Optional Boolean value (default is false) that indicates whether the recordEvent method of the parent Event object should also be called, when the counter for the subordinate Event object is incremented.
Example
Listener listener = new Listener("sampleApp", "4.0");
Event creations = listener.lookupEvent(PCHeventClass.RPC, "document creations");
Accumulator numCreations = creations.lookupAccumulator(Listener.DURATION);
...
- or -
Listener listener = new Listener("sampleApp", "4.0");
Container store = listener.lookupContainer("storeName");
Event creations = store.lookupEvent(PCHeventClass.RPC, "document creations", false);
Event subCreations = creations.lookupEvent("document sub-creations");
Meter creationSize = creations.lookupMeter("creation size");
Accumulator numCreations = creations.lookupAccumulator(Listener.DURATION);
...