Permalink
Browse files

pubsub handling

  • Loading branch information...
1 parent 56860aa commit a94d48540b92d69e5b7d28feeee101ee482a5671 @oberstet oberstet committed Sep 25, 2011
View
46 Autobahn/src/de/tavendo/autobahn/AutobahnConnection.java
@@ -32,6 +32,8 @@
protected AutobahnWriter mWriterHandler;
+ private final PrefixMap mOutgoingPrefixes = new PrefixMap();
+
private final Random mRng = new Random();
private static final char[] mBase64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
@@ -60,16 +62,16 @@
public static class SubMeta {
- SubMeta(OnEventHandler eventHandler, Class<?> eventType) {
- this.mEventHandler = eventHandler;
- this.mEventClass = eventType;
+ SubMeta(OnEventHandler handler, Class<?> resultClass) {
+ this.mEventHandler = handler;
+ this.mEventClass = resultClass;
this.mEventTypeRef = null;
}
- SubMeta(OnEventHandler eventListener, TypeReference<?> eventType) {
- this.mEventHandler = eventListener;
+ SubMeta(OnEventHandler handler, TypeReference<?> resultTypeReference) {
+ this.mEventHandler = handler;
this.mEventClass = null;
- this.mEventTypeRef = eventType;
+ this.mEventTypeRef = resultTypeReference;
}
public OnEventHandler mEventHandler;
@@ -193,6 +195,16 @@ protected void processAppMessage(Object message) {
}
mCalls.remove(callerror.mCallId);
}
+ } else if (message instanceof AutobahnMessage.Event) {
+
+ AutobahnMessage.Event event = (AutobahnMessage.Event) message;
+
+ if (mSubs.containsKey(event.mTopicUri)) {
+ SubMeta meta = mSubs.get(event.mTopicUri);
+ if (meta != null && meta.mEventHandler != null) {
+ meta.mEventHandler.onEvent(event.mTopicUri, event.mEvent);
+ }
+ }
} else {
Log.d(TAG, "unknown message in AutobahnConnection.processAppMessage");
@@ -225,12 +237,14 @@ public void call(String procUri, TypeReference<?> resultType, OnCallResult resul
private void subscribe(String topicUri, SubMeta meta) {
- if (!mSubs.containsKey(topicUri)) {
+ String uri = mOutgoingPrefixes.resolveOrPass(topicUri);
+
+ if (!mSubs.containsKey(uri)) {
- AutobahnMessage.Subscribe msg = new AutobahnMessage.Subscribe(topicUri);
+ AutobahnMessage.Subscribe msg = new AutobahnMessage.Subscribe(mOutgoingPrefixes.shrink(topicUri));
mWriter.forward(msg);
}
- mSubs.put(topicUri, meta);
+ mSubs.put(uri, meta);
}
@@ -268,15 +282,21 @@ public void unsubscribe() {
public void prefix(String prefix, String uri) {
- // FIXME: add mapping to PrefixMap
- AutobahnMessage.Prefix msg = new AutobahnMessage.Prefix(prefix, uri);
- mWriter.forward(msg);
+ String currUri = mOutgoingPrefixes.get(prefix);
+
+ if (currUri == null || !currUri.equals(uri)) {
+
+ mOutgoingPrefixes.set(prefix, uri);
+
+ AutobahnMessage.Prefix msg = new AutobahnMessage.Prefix(prefix, uri);
+ mWriter.forward(msg);
+ }
}
public void publish(String topicUri, Object event) {
- AutobahnMessage.Publish msg = new AutobahnMessage.Publish(topicUri, event);
+ AutobahnMessage.Publish msg = new AutobahnMessage.Publish(mOutgoingPrefixes.shrink(topicUri), event);
mWriter.forward(msg);
}
View
1 Autobahn/src/de/tavendo/autobahn/AutobahnMessage.java
@@ -141,6 +141,7 @@ public Unsubscribe(String topicUri) {
public Object mEvent;
public Event(String topicUri, Object event) {
+ mTopicUri = topicUri;
mEvent = event;
}
}
View
1 Autobahn/src/de/tavendo/autobahn/AutobahnReader.java
@@ -149,6 +149,7 @@ protected void onRawTextMessage(byte[] payload) {
} else {
}
notify(new AutobahnMessage.Event(topicUri, event));
+ } else {
}
} else if (msgType == AutobahnMessage.MESSAGE_TYPE_PREFIX) {
View
18 README
@@ -4,11 +4,23 @@ Autobahn WebSockets for Android
Autobahn WebSockets for Android provides a client library implementation
of the WebSockets protocol:
- * supports protocol draft version 10-14
- * easy to use API
- * very good standards conformance
+ * very good standards conformance [1]
+ * easy to use API [2]
+ * designed to work with Android UI applications [3]
* Open-source (Apache 2 license)
+[1] The implementation suuports the WebSockets protocol draft version 10-14 and
+ passes all tests from the Autobahn WebSockets test suite.
+
+[2] The basic API is modeled after the WebSockets JavaScript API for
+ ease of use and familarity.
+
+[3] The API enables the use of common Android idioms for event handling (using
+ anonymous inner classes) and integrates with Android UI applications (by
+ communicating via messages and message loops between the UI thread and back-
+ ground reader/writer threads).
+
+
RPC/PubSub
----------
View
4 TODO
@@ -0,0 +1,4 @@
+
+- check out Maven Android Plugin (http://code.google.com/p/maven-android-plugin/wiki/GettingStarted)
+
+- maybe allow command line maven driven builds

0 comments on commit a94d485

Please sign in to comment.