Event bus client over WebSocket for java and andorid
Visit Google groups for discussions and announcements.
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.goodow.realtime</groupId>
<artifactId>realtime-android</artifactId>
<version>0.5.5-SNAPSHOT</version>
</dependency>
</dependencies>
AndroidPlatform.register(); // or JavaPlatform.register();
Bus bus = new ReconnectBus("ws://localhost:1986/channel/websocket", null);
bus.subscribe("some/topic", new MessageHandler<JsonObject>() {
@Override
public void handle(Message<JsonObject> message) {
JsonObject payload = message.payload();
System.out.println("Name: " + payload.get("name"));
}
});
bus.publish("some/topic", Json.createObject().set("name", "Larry Tin"));
AndroidPlatform.register(); // or JavaPlatform.register();
Store store = new StoreImpl("ws://localhost:1986/channel/websocket", null);
Bus bus = store.getBus();
Handler<Document> onLoaded = new Handler<Document>() {
@Override
public void handle(Document document) {
Model model = document.getModel();
CollaborativeMap root = model.getRoot();
CollaborativeString name = root.get("name");
System.out.println("Name: " + name.getText());
}
};
Handler<Model> opt_initializer = new Handler<Model>() {
@Override
public void handle(Model model) {
CollaborativeString name = model.createString("Larry Tin");
CollaborativeMap root = mod.getRoot();
root.set("name", name);
}
};
store.load("docType/docId", onLoaded, opt_initializer, null);
See WebSocketBusTest and ServerStoreTest for more usage.
NOTE: You must register a platform first by invoke JavaPlatform.register() or AndroidPlatform.register()