com.sun.midp.events |
Dispatches Java and native events to Java subsystems. See midpEvents.h for
the native interface to the MIDP event system.
Adding a New Event Type to the MIDP Java Event System
-
First select the new event type ID to be next the highest one in midpEvents.h.
Add the new event type ID to midpEvents.h
-
If the event is a native event and there a not enough fields in
NativeEvent, add the required fields to both NativeEvent and MidpEvent
midpEvents.h. Follow the generic naming scheme.
-
Implement an EventListener.
class MyListener implements EventListener {
public boolean preprocess(Event event, Event waitingEvent) {
// only one of these events should be in the queue at a time
if (waitingEvent == null) {
// let the event be put in the queue
return true;
}
... merge the new event into the waiting event ...
// signal that this event should not be put in the queue
return false;
}
public void process(Event genericEvent) {
MyEvent myEvent = (MyEvent)genericEvent;
... process the event ...
}
}
-
Add code to obtain a security token for the class that is going to register
the event listenter or post an Java event. The code depends on if the
class is optional or not. If the class to receive the security token is
optional then the class must implement the
ImplictlyTrustedClass
interface and have a public no argument constructor and so an instance of
the class can be loaded by name in the
initializeInternalSecurity method of the
MIDletSuiteLoader and be given a token. If the class normal
part of MIDP it can just
implement a static method that sets the classes security token if the token
has not already been set and insert a call to this static method in
initializeInternalSecurity .
Previous and Currently Implemented Thread Models
The first MIDP event queue had one thread which blocked until a native
event was available and then processed the event in the same thread and
looped back to the blocking event read. If events were only generated by
native code this would be fine but for Java generated events like repaint,
this means that three native methods had to be called, one to put the
Java event in the native event queue and two to retrieve it from the
native event queue.
To speed up Java to Java events like repaints a Java level queue was
introduced to avoid the any native method calls. Processing was in one
thread and native methods were feed into the Java queue by another thread
to avoid polling the native event queue. This boosted the repaint rate
three fold.
To speed up native event response during continuous event activity,
the thread switch that occurred to process a native event after it
was read was eliminated.
This was done by letting the Java queue processing thread read events in
a non-blocking way after a it had processed the pending Java events.
To avoid polling when the processing thread ran out of events to process
the queue would sleep. Just before sleeping, the Java queue processing
thread wakes up a separate thread that monitors the native event queue in
a blocking fashion, wakes up the Java queue processing thread when a native
event was available to be read and goes to sleep. This model is used by
the real device implementation and will be used for Leap Frog.
|
Java Source File Name | Type | Comment |
Event.java | Class | All events handled by this package must extend this class. |
EventCopyStorage.java | Class | Storage of native event copies for events being posted to evet queue. |
EventListener.java | Interface | A listener interface for preprocessing and receiving MIDP events.
Each system that wants to receive events implements an EventListener and
registers the listener with the EventQueue for each event type to be
received. |
EventTypes.java | Class | Event type IDs, this should match midpEvents.h. |
FatalMIDlet.java | Class | Register an event listener, send an event to self, and throw a
RuntimeException while processing an event. |
InstrumentedEventListener.java | Class | An implementation of an EventListener that records the events passed to its
process() and preprocess() methods. |
ListenerTestEventQueue.java | Class | Test event queue. |
NativeEvent.java | Class | This class represents a union of the parameters of all native events. |
StubEventQueue.java | Class | This is a stubbed-out version of EventQueue, for testing purposes. |
TestEventQueue.java | Class | Unit tests for the EventQueue class. |
TestHandleFatalError.java | Class | Test that the if an event listener in an application isolate throws a
runtime exception, that the isolate is killed. |
TestNativeEventPool.java | Class | Unit tests for the NativeEventPool class. |
UnitTestEvent.java | Class | A NativeEvent for test purposes. |