All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ocap.system.event.package.html Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version















The org.ocap.system.event package defines various system events.

Following is a Java example demonstrating how an application can register to be the error event handler:

public class EventListenerAppSample implements SystemEventListener

{

    private final static int MAX_EVENT_STORE = 5;

    private static int eventCount = 0;

    private SystemEvent[] imeStore = new SystemEvent[MAX_EVENT_STORE];

 

    /**

     * The zero argument constructor demonstrates a possible application example where

     * the application registers to receive error events.

     */

    public EventListenerAppSample()

    {

        // Get the system event manager.

        SystemEventManager sem = SystemEventManager.getInstance();

 

        // Set this object as the new error event listener.

        sem.setEventListener(SystemEventManager.ERROR_EVENT_LISTENER, this);

    }

 

    /**

     * Receives a message event from the implementation. This method will be used to process

     * all of the error and informational messages sent to this registered error listener.

     *

     * This sample simply places the messages into an array. Additional processing is

     * specific to the application. For example, an application may look at the error code

     * and application identifier of the event and take recovery action for specific errors,

     * in which case it would return null. The application may return non-null indicating that

     * it has changed the event.

     *

     * @param see Event generated by the system or sent by an application.

     */

    public void notifyEvent(SystemEvent me)

    {

        System.out.print("ErrorListenerAppSample.notifyEvent(); event type: ");

        System.out.print(me.getTypeCode());

        System.out.print(";  date: ");

        System.out.println(me.getDate());

 

        eventCount = (eventCount == MAX_EVENT_STORE - 1) ? 0 : eventCount + 1;

 

        imeStore[eventCount] = me;     // Store the event for later retrieval.

    }

}

 

Following is a Java example demonstrating how an application can log an error:

import org.ocap.event.*;

 

public class EventSenderSample

{

/** Our application-specific error code. */

    private static final int ID_FOR_APP_SAMPLE = SystemEvent.BEGIN_APP_REC_ERROR_TYPES + 42;

 

    public static void sendTestErrorEvent() {

        // Create an error event.

        ErrorEvent ee = new ErrorEvent(ID_FOR_APP_SAMPLE, "TestEvent");

 

        // Get the default system event logger.

        SystemEventManager sem = SystemEventManager.getInstance();

 

        // Log an error to the default system error handler.

        sem.log(ee);

    }

}

 





© 2015 - 2024 Weber Informatics LLC | Privacy Policy