Name: bw2android
Owner: Software Defined Buildings
Description: Android bindings for Bosswave
Created: 2016-03-30 17:52:09.0
Updated: 2016-11-04 07:18:45.0
Pushed: 2016-12-11 19:04:05.0
Homepage: null
Size: 115
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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
.
Here's a rough example of how to initialize the client, publish, and subscribe.
any client methods throw IOExceptions
waveClient client;
{
// 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...
nally {
f (client != null) {
client.close();