IAppEvent interface (deprecated)
IAppEvent is deprecated and is provided for backward compatibility only. New applications should use the NAS API's two replacement interfaces: IAppEventMgr and IAppEventObj.
The IAppEvent interface represents the defined events an application supports. An AppLogic can define events that are triggered at a specified time or times or when triggered explicitly.
Currently, an AppLogic can execute two actions when an event is triggered:
Events are stored persistently in the Netscape Application Server, and are removed only when your application explicitly deletes them. They are typically used to schedule routine administrative tasks, such as making back-ups or getting statistics.
The IAppEvent interface defines methods for registering, triggering, enabling, disabling and deleting events. To create an instance of the IAppEvent interface, use the getAppEvent( ) method in the AppLogic class.
Package
com.kivasoft
Methods
Example
The following example shows AppLogic code that registers two application events:
package GXApp.appevent;
import java.lang.*;
import java.util.*;
import java.io.*;
import com.kivasoft.*;
import com.kivasoft.applogic.*;
import com.kivasoft.util.*;
import com.kivasoft.types.*;
import com.kivasoft.appevent.*;
public class ReportAgent extends AppLogic
{
static final java.lang.String eventName1 = "RepGenEvent";
static final java.lang.String eventName2 = "ReportEvent";
public int execute()
{
// Create IValLists to pass information
// for appevent registration of the events
IValList eventOutput;
IValList eventInput1 = GX.CreateValList();
IValList eventInput2 = GX.CreateValList();
if ((eventInput1 == null) || (eventInput2 == null))
return streamResult("Cannot create ValList<br>");
// Get the appevent manager
IAppEvent appEvent = getAppEvent();
if (appEvent == null)
return streamResult("Cannot get AppEvent<br>");
// Add the RepGenAgent appevent name to the vallist
eventInput1.setValString(GX_AE_RE_KEY_NAME.GX_AE_RE_KEY_NAME,
eventName1);
// Set the appevent state to be enabled
eventInput1.setValInt(GX_AE_RE_KEY_STATE.GX_AE_RE_KEY_STATE,
GX_AE_RE_ES_FLAG.GX_AE_RE_EVENT_ENABLED);
// Set the appevent time to be 05:00:00 hrs everyday
eventInput1.setValString(GX_AE_RE_KEY_TIME.GX_AE_RE_KEY_TIME,
"5:0:0 */*/*");
// Set the appevent action to run
// the RepGenAgent applogic
eventInput1.setValString(GX_AE_RE_KEY_NREQ.GX_AE_RE_KEY_NREQ,
"GUIDGX-{620CB09B-1A1D-1315-AD23-0800207B918B}");
// Register the event
if (appEvent.registerEvent(eventName1, eventInput1) !=
GXE.SUCCESS)
return streamResult("Cannot register RepGenEvent<br>");
// Add the ReportAgent appevent name to the vallist
eventInput2.setValString(GX_AE_RE_KEY_NAME.GX_AE_RE_KEY_NAME,
eventName2);
// Set the appevent state to be enabled
eventInput2.setValInt(GX_AE_RE_KEY_STATE.GX_AE_RE_KEY_STATE,
GX_AE_RE_ES_FLAG.GX_AE_RE_EVENT_ENABLED);
// Set the appevent time to be 06:00:00 hrs everyday
eventInput2.setValString(GX_AE_RE_KEY_TIME.GX_AE_RE_KEY_TIME,
"6:0:0 */*/*");
// Set the appevent action to send e-mail
eventInput2.setValString(GX_AE_RE_KEY_MTO.GX_AE_RE_KEY_MTO,
"report@acme.com");
// The content of the e-mail is in /tmp/report-file
eventInput2.setValString(GX_AE_RE_KEY_MFILE.GX_AE_RE_KEY_
MFILE, "/tmp/report-file");
// The e-mail host running the SMTP server is mailsvr
eventInput2.setValString(GX_AE_RE_KEY_MHOST.GX_AE_RE_KEY_
MHOST, "mailsvr.acme.com");
// The sender's e-mail address is admin@acme.com
eventInput2.setValString(GX_AE_RE_KEY_SADDR.GX_AE_RE_KEY_
SADDR, "admin@acme.com");
// Register the event
if (appEvent.registerEvent(eventName2, eventInput2) !=
GXE.SUCCESS)
return streamResult("Can not register ReportEvent<br>");
return streamResult("Successfully Registered RepGenEvent and
ReportEvent<br>");
}
}
Related Topics
getAppEvent( ) method in the AppLogic class
IAppEventMgr interface
IAppEventObj interface
IValList interface
deleteEvent( )
Removes a registered event from the 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. To temporarily stop a 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 remove an event from the Netscape Application Server permanently, 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 prepare a specified event for activation. Call enableEvent( ) after you register an event with registerEvent( ), or to enable a trigger that was disabled with disableEvent( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
disableEvent( )
registerEvent( )
enumEvents( )
Returns the list of registered events.
Syntax
public IEnumObject enumEvent()
Usage
Use enumEvents( ) to get information on all the registered events. The IEnumObject object returned by enumEvents( ) contains a set of IValList objects, one per event. Each IValList contains the properties 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
IAppEvent appEvent = getAppEvent();
// Get the Enumeration object for all registered appevents
IEnumObject enumObj = appEvent.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);
while (count > 0) {
IObject vListObj = enumObj.enumNext();
if (vListObj instanceof IValList) {
IValList vList = (IValList)vListObj;
String name =
vList.getValString(GX_AE_RE_KEY_NAME.GX_AE_RE_KEY_NAME);
try {
p.writeObject("\nDefinitions for AppEvent: ");
p.writeObject(name);
p.writeObject("\n");
} catch (IOException e) {
return streamResult("Failed to write to report file<br>");
}
// Reset the next GXVAL to retrieve
// from ValList to be the first one
vList.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
getAppEvent( ) method in the AppLogic class
IValList interface
queryEvent( )
Returns the properties of a registered event.
Syntax
public IValList queryEvent(
String pEventName)
pEventName.
The name of the registered event to enable.
Usage
When an AppLogic calls registerEvent( ), it can specify any of the following:
Use queryEvent( ) to get the properties that were specified for a specific event.
Return Value
IValList object that contains information about the event.
Related Topics
registerEvent( )
registerEvent( )
Registers a named event for use in applications.
Syntax
public int registerEvent(
String pEventName,
IValList pValList)
pEventName.
The name of the event to register.
pValList.
The IValList object that specifies the properties of the event. The following table lists the keys and values you can specify:
* You must specify all of these items if sending email when the event is triggered.
Usage
Use registerEvent( ) to define each event your application will use. You can specify that a triggered event sends an email, or runs an AppLogic, or both.
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
IAppEvent appEvent = getAppEvent();
// Create IValList to pass information for
// registration of an event
IValList eventInput1 = GX.CreateValList();
// Add the RepGenAgent appevent name to the vallist
eventInput1.setValString(GX_AE_RE_KEY_NAME.GX_AE_RE_KEY_NAME,
eventName1);
// Set the appevent state to be enabled
eventInput1.setValInt(GX_AE_RE_KEY_STATE.GX_AE_RE_KEY_STATE,
GX_AE_RE_ES_FLAG.GX_AE_RE_EVENT_ENABLED);
// Set the appevent time to be 05:00:00 hrs everyday
eventInput1.setValString(GX_AE_RE_KEY_TIME.GX_AE_RE_KEY_TIME,
"5:0:0 */*/*");
// Set the appevent action to run an AppLogic
eventInput1.setValString(GX_AE_RE_KEY_NREQ.GX_AE_RE_KEY_NREQ,
"GUIDGX-{620CB09B-1A1D-1315-AD23-0800207B918B}");
// Register the event
if (appEvent.registerEvent(eventName1, eventInput1) != GXE.SUCCESS)
return streamResult("Cannot register RepGenEvent<br>");
Related Topics
enableEvent( )
setEvent( )
getAppEvent( ) method in the AppLogic class
IValList interface
setEvent( )
Triggers a registered event.
Syntax
public int setEvent(
String pEventName,
int dwOverrideFlag,
IValList pValList)
pEventName.
The name of the event to trigger.
dwOverrideFlag.
Specify 0 (zero) to trigger the event with the previously specified actions. To override the defined actions, you can specify the following:
pValList.
The IValList object that specifies the event properties you want to override. Specify null to use the properties already defined for the event. The following table lists the keys and values you can specify:
* You must specify all of these items if sending email when the event is triggered.
Usage
Use setEvent( ) to trigger a registered event immediately. This is useful for testing purposes.
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
registerEvent( )
getAppEvent( ) method in the AppLogic class
IValList interface
|