com.sun.midp.events

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.events 
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

  1. 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
  2. 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.
  3. Implement an EventListener.
  4. 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 ...
        }
    }
    
  5. 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 NameTypeComment
Event.javaClass All events handled by this package must extend this class.
EventCopyStorage.javaClass Storage of native event copies for events being posted to evet queue.
EventListener.javaInterface 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.javaClass Event type IDs, this should match midpEvents.h.
FatalMIDlet.javaClass Register an event listener, send an event to self, and throw a RuntimeException while processing an event.
InstrumentedEventListener.javaClass An implementation of an EventListener that records the events passed to its process() and preprocess() methods.
ListenerTestEventQueue.javaClass Test event queue.
NativeEvent.javaClass This class represents a union of the parameters of all native events.
StubEventQueue.javaClass This is a stubbed-out version of EventQueue, for testing purposes.
TestEventQueue.javaClass Unit tests for the EventQueue class.
TestHandleFatalError.javaClass Test that the if an event listener in an application isolate throws a runtime exception, that the isolate is killed.
TestNativeEventPool.javaClass Unit tests for the NativeEventPool class.
UnitTestEvent.javaClass A NativeEvent for test purposes.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.