reference_modules_java - NibiruOS/mobile GitHub Wiki
Java
The ar.com.oxen.nibiru.mobile.java
project contains common classes that are shared among platforms that are Java-based. This includes Android, even when it is not Java-based, strictly speaking. Currently, the only platform that does not use classes from this project is GWT.
Generic cross components
Asynchronous callbacks
When making an async server call, Java code needs to spawn a new thread (diferently from GWT, where this is done automatically. However, due to UI rendering lifecycle, Vaadin platform needs to make server calls synchronous (because Vaadin UI protcol is already asynchrnous). Since Vaadin code executes on the server, the response for an async call to other server would not be notified to the browser.
A potential solution would be implementing a push approach. However, this is quite complex and requires extra network usage. A simpler solution is abstracting thread creation to allow both, synchronous and asynchronous calls.
AsyncManager interface was created with this goal in mind. It has 2 implementations:
- SequentialAsyncManager: Helpful for Vaadin platform.
- ThreadAsyncManager: For all the other Java platforms.
Inversion of control
The ar.com.oxen.nibiru.mobile.java.ioc
package provides default Guice-based configuration modules. Currently, the only one is DefaultJavaModule.
Unified API components
Event handling
The ar.com.oxen.nibiru.mobile.java.event.guava
package provides a Guava-based EventBus implementation.
Classes implementing this are GuavaEvent and GuavaEventBus.
HTTP requests
The ar.com.oxen.nibiru.mobile.java.http.httpclient
package provides an Apache HTTP Components implementation for HttpManager. Apache HTTP Client is provided natively by Android, so using this library we can take advantage of this.
The class implementing this functionality is HttpClientHttpManager
Object serialization
JSON serialization is provided using Jackson processor. The ar.com.oxen.nibiru.mobile.java.serializer.jackson
package contains this implementation (JacksonSerializer). JSON serialization is configured using an org.codehaus.jackson.map.ObjectMapper
instance. If you need yo customize serialization, you can write a javax.inject.Provider<ObjectMapper>
for this class.
User interface
i18n
The ar.com.oxen.nibiru.mobile.java.ui.i18n
contains classes used for internationalization.
The MessageInvocationHandler class is used, in conjuntion with a Java proxy, in order to read messages from a resource bundle according to method name. This way, interfaces for i18n messages can be used on both, GWT and Java. This approach unifies both models.
MessageProvider is responsible for creating such proxy.