IAppEventMgr interface
Application components can define events that are either triggered at a specified time or triggered explicitly. Events are stored persistently in the Netscape Application Server, and are removed only when your application explicitly deletes them. Events are typically used to schedule routine administrative tasks, such as making back-ups or getting statistics.
NAS uses two new interfaces to support events:
IAppEventMgr and IAppEventObj should be used in new or migrated applications. Existing NAS applications can continue using the deprecated IAppEvent interface, which supports the previous model for application events.
Attributes and Actions
For each event, you define associated attributes and actions. Attributes determine the following characteristics:
When an event is triggered, it performs one or more of the following types of actions:
Features of Application Event Support
Support for application events includes the following:
Accessing and Creating Application Events
To access an IAppEventMgr object, use the GetAppEventMgr( ) method in the GXContext class:
IAppEventMgr com.kivasoft.dlm.GXContext.GetAppEventMgr(
IContext context);
The context parameter is an IContext object, which provides access to Netscape Application Server services. For information about obtaining this IContext object, see the GXContext class or the IContext interface.
After creating the IAppEventMgr object, you can create an application event (an instance of IAppEventObj) by calling createEvent( ) on the IAppEventMgr object.
Registering Events
After creating an application event, you can set its attributes and add actions using methods on the IAppEventObj. Then, register the application event by calling registerEvent( ) on the manager object.
Package
com.kivasoft
Methods
Related Topics
GetAppEventMgr( ) in the GXContext class, IValList interface (deprecated), IAppEventObj interface
Taking Advantage of NAS Features
createEvent( )
Creates an empty application event object.
Syntax
public IAppEventObj createEvent(
String pEventName)
pEventName.
The name of the event to create.
Usage
Use createEvent( ) to create an empty IAppEventObj object. You can use methods of the IAppEventObj interface to set attributes and actions on the returned object.
Changes to the event object do not take effect until it is registered with the manager object, through a call to registerEvent( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
getEvent( )
registerEvent( )
deleteEvent( )
Removes a registered event from Netscape Application Server.
Syntax
public int deleteEvent(
String pEventName)
pEventName.
The name of the registered event to delete.
Usage
Use deleteEvent( ) to remove an event that is no longer required. The specified event is removed from NAS.
To temporarily stop an event from being triggered, use disableEvent( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
disableEvent( )
registerEvent( )
disableEvent( )
Disables a registered event.
Syntax
public int disableEvent(
String pEventName)
pEventName.
The name of the registered event to disable.
Usage
Use disableEvent( ) to temporarily stop an event from being triggered. The event is disabled until it is enabled with enableEvent( ). To permanently remove an event from the registry, use deleteEvent( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
deleteEvent( )
enableEvent( )
registerEvent( )
enableEvent( )
Enables a registered event.
Syntax
public int enableEvent(
String pEventName)
pEventName.
The name of the registered event to enable.
Usage
Use enableEvent( ) to enable an event. A given event could have been disabled in either of two ways: by a previous call to disableEvent( ) or by initially registering the event using a disabled state attribute.
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
disableEvent( )
registerEvent( )
enumEvents( )
Enumerates through the list of registered events.
Syntax
public IEnumObject enumEvents()
Usage
Use enumEvents( ) to get information on all the registered events. The IEnumObject object returned by enumEvents( ) contains a set of IAppEventObj objects, one per event. Each IAppEventObj contains the attributes and actions that were assigned to the event when it was registered with registerEvent( ).
Tip
Use the methods in the IEnumObject interface to iterate through the contents of the returned IEnumObject object.
Example
The following AppLogic code shows how to use enumEvents( ) to get information on all the registered events and save it to a report:
// Open /tmp/report-file for writing the report
FileOutputStream outFile = null;
try {
outFile = new FileOutputStream("/tmp/report-file");
} catch (IOException e) {
}
if (outFile == null)
return streamResult("Can not open /tmp/report-file<br>");
ObjectOutputStream p = null;
try {
p = new ObjectOutputStream(outFile);
} catch (IOException e) {
}
if (p == null)
return streamResult("Cannot create ObjectOutputStream<br>");
// get appevent manager
IAppEventMgr appEventMgr = GetAppEventMgr();
// Get the Enumeration object for all registered appevents
IEnumObject enumObj = appEventMgr.enumEvents();
// Retrieve the count of registered appevents
int count = enumObj.enumCount();
try {
p.writeObject("Number of Registered Events: ");
p.writeInt(count);
} catch (IOException e) {
return streamResult("Failed to write to report file<br>");
}
enumObj.enumReset(0);
IObject eventObj = enumObj.enumNext();
while ((eventObj = enumObj.enumNext()) != null) {
if (eventObj instanceof IAppEventObj) {
IAppEventObj appEventObj = (IAppEventObj)eventObj;
// print each appEvent
// get the name of the appevent
String name = appEventObj.getName();
try {
p.writeObject("\nDefinitions for AppEvent: ");
p.writeObject(name);
p.writeObject("\n");
} catch (IOException e) {
return streamResult("Failed to write to report file<br>");
}
// print the attributes..
IValList attrs = appEventObj.getAttributes();
attrs.resetPosition();
// Iterate through all the GXVALs in the attr s valllist
// and print them
...
...
...
// enumerate through the actions
enumActions = appEventObj.enumActions();
// Retrieve the count of registered actions for this event
count = enumActions.enumCount();
try {
p.writeObject("Number of Actions: ");
p.writeInt(count);
} catch (IOException e) {
return streamResult("Failed to write ActionCount to report file");
}
enumActions.enumReset(0);
IObject obj ;
while ((obj = enumActions.enumNext()) != null) {
// print each action
if (obj instanceof IValList) {
IValList action = (IValList)obj;
action.resetPosition();
// Iterate through all the GXVALs in the vallist
// and print them
...
...
...
}
}
}
}
Return Value
IEnumObject that contains the list of events, or null for failure.
Related Topics
IEnumObject interface
getEvent( )
Retrieves the IAppEventObj for a registered event.
Syntax
public IAppEventObj getEvent(
String pEventName)
pEventName.
The name of the registered event.
Usage
After calling getEvent( ), you can call methods on the returned IAppEventObj. For example, you can query the object by calling getAttributes( ) or enumActions( ), or you can modify the object by calling setAttributes( ).
Return Value
IAppEventObj for the specified event.
Related Topics
registerEvent( )
registerEvent( )
Registers a named event for use in applications.
Syntax
public int registerEvent(
IAppEventObj appEventObj)
appEventObj.
The event object whose attributes and actions have been set.
Usage
After an application event object is created with createEvent( ), you define its attributes and actions using methods of the IAppEventObj interface. Then you use registerEvent( ) to register the specified event object. Registration commits the changed attributes and actions to the server and to the registry. If an event object already exists for the given name, the existing object is deleted and replaced with the specified object.
Return Value
GXE.SUCCESS if the method succeeds.
Example
The following example shows how to define and register an application event:
static final java.lang.String eventName1 = "RepGenEvent";
// get the appevent manager
IAppEventMgr appEventMgr = GXContext.GetAppEventMgr(context);
// create a appevent object
IAppEventObj appEventObj = appEventMgr.createEvent(eventName1);
// create ValList for attributes.
IValList attrs = GX.CreateValList();
// set the Action Mode to Serial for serial-execution of actions.
attrs.setValInt(GXConstants.GX_AE2_RE_KEY_ACTION_MODE,
GX_AE2_RE_SA_FLAG.GX_AE2_RE_ACTION_SERIAL);
// set the appevent time to be 05:00:00 hrs everyday
attrs.setValString(GXConstants.GX_AE2_RE_KEY_TIME, "5:0:0 */*/*");
// set the attributes
appEventObj.setAttributes(attrs);
// create ValLists for actions (2 applogic newrequest and 2 servlet).
IValList action1 = GX.CreateValList();
IValList action2 = GX.CreateValList();
IValList action3 = GX.CreateValList();
IValList action4 = GX.CreateValList();
// set action1 to run an appLogic
action1.setValString(GXConstants.GX_AE2_RE_KEY_NREQ,
"GUIDGX-{620CB09B-1A1D-1315-AD23-0800207B918B}");
// set action1 to run another appLogic
action2.setValString(GXConstants.GX_AE2_RE_KEY_NREQ,
"GUIDGX-{60A36CC0-9F69-11D2-9907-0060973797BF}");
// set action2 to run a servlet
action3.setValString(GXConstants.GX_AE2_RE_KEY_SERVLET,
"TxReportServlet");
// set action3 to run another servlet
action4.setValString(GXConstants.GX_AE2_RE_KEY_SERVLET,
"SummaryReportServlet");
// add actions in the order we want them to be executed
appEventObj.addAction(action1);
appEventObj.addAction(action2);
appEventObj.addAction(action3);
appEventObj.addAction(action4);
// Register the event
if (appEventMgr.registerEvent(eventName1, appEventObj) != GXE.SUCCESS)
return streamResult("Cannot register RepGenEvent<br>");
Related Topics
enableEvent( )
triggerEvent( )
triggerEvent( )
Triggers a registered event.
Syntax
public int triggerEvent(
String pEventName,
IValList pValList,
boolean syncFlag)
pEventName.
The name of the event to trigger.
pValList.
The IValList object that specifies the input that is passed to the triggered event and its actions.
syncFlag.
The boolean flag that indicates whether the event is to be triggered synchronously (value is true) or asynchronously (value is false).
Usage
Use triggerEvent( ) to trigger a registered event. When you specify the pValList parameter, a copy of this IValList object is passed as input to all actions registered with the application event.
Use the syncFlag parameter to determine synchronous or asynchrous execution. Typical usage is to set syncFlag to false, which provides asynchronous execution and better application performance. When syncFlag is false, the event is triggered, and the method call returns immediately, without waiting for the actions to finish executing.
If syncFlag is true, then the method call does not return immediately. Instead, the call blocks until the event is triggered and all actions have executed. In some cases, it may be desirable for actions to finish executing before returning control to the application.
Actions are triggered in the same order in which they were added to the application event object.
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
registerEvent( )
|