-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename message as result for better consistency with BW terminology, …
…improve README
- Loading branch information
Showing
8 changed files
with
115 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,68 @@ | ||
# bw2Android | ||
Android bindings for Bosswave | ||
# bw2Android - Android Bindings for Bosswave | ||
|
||
## Obtaining a JAR File | ||
This project uses Gradle for compilation and dependency management. After | ||
cloning the project, run the following from the top level directory: | ||
``` | ||
$ ./gradlew shadowJar | ||
``` | ||
|
||
After Gradle has finished, a fat JAR file will be available under `build/libs`. | ||
|
||
## Basic Usage | ||
Here's a rough example of how to initialize the client, publish, and subscribe. | ||
```java | ||
// Many client methods throw IOExceptions | ||
BosswaveClient client; | ||
try { | ||
// Connect to a Bosswave agent running locally | ||
client = new BosswaveClient("localhost", BosswaveClient.DEFAULT_PORT); | ||
|
||
// Set the Bosswave entity to be used for subsequent operations | ||
client.setEntityFromFile("myKey.ent"); | ||
|
||
// Enable auto chain by default | ||
client.overrideAutoChainTo(true); | ||
|
||
// Define a callback to handle Bosswave errors | ||
private class ResponseErrorHandler implements ResponseHandler { | ||
@Override | ||
public void onResponseReceived(BosswaveResponse resp) { | ||
if (!resp.getStatus().equals("okay")) { | ||
throw new RuntimeException(resp.getReason())); | ||
} | ||
} | ||
} | ||
|
||
// Publish a simple text message | ||
PublishRequest.Builder builder = new PublishRequest.Builder(BW_URI); | ||
PayloadObject.Type poType = new PayloadObject.Type(POAllocations.PODFText); | ||
String message = "Hello, World!"; | ||
byte[] poContents = message.getBytes(StandardCharsets.UTF_8); | ||
PayloadObject po = new PayloadObject(poType, poContents); | ||
builder.addPayloadObject(po); | ||
PublishRequest request = builder.build(); | ||
client.publish(request, new ResponseErrorHandler()); | ||
|
||
// Define a callback to handle incoming text messages | ||
private class TextResultHandler implements ResultHandler { | ||
@Override | ||
public void onResultReceived(BosswaveResult rslt) { | ||
byte[] messageContent = rslt.getPayloadObjects().get(0).getContent(); | ||
String msg = new String(messageContent, StandardCharsets.UTF_8); | ||
System.out.println(msg); | ||
} | ||
} | ||
|
||
// Subscribe to a Bosswave URI | ||
SubscribeRequest.Builder builder = new SubscribeRequest.Builder("scratch.ns/foo/bar"); | ||
SubscribeRequest request = builder.build(); | ||
client.subscribe(request, new ResponseErrorHandler(), new TextResultHandler()); | ||
|
||
// Additional application logic... | ||
} finally { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...du/berkeley/cs/sdb/bosswave/Response.java → ...ley/cs/sdb/bosswave/BosswaveResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
src/main/java/edu/berkeley/cs/sdb/bosswave/MessageHandler.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/main/java/edu/berkeley/cs/sdb/bosswave/ResponseHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package edu.berkeley.cs.sdb.bosswave; | ||
|
||
public interface ResponseHandler { | ||
void onResponseReceived(Response result); | ||
void onResponseReceived(BosswaveResponse result); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/edu/berkeley/cs/sdb/bosswave/ResultHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package edu.berkeley.cs.sdb.bosswave; | ||
|
||
public interface ResultHandler { | ||
void onResultReceived(BosswaveResult result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters