Syncbase Discovery: Expose the invites API via JNI / Java.
MultiPart: 3/3
Change-Id: Ie500bc679c5bf22ef18db7f43d8556505487c441
diff --git a/lib/src/main/java/io/v/v23/syncbase/Database.java b/lib/src/main/java/io/v/v23/syncbase/Database.java
index aa5e850..45fdf93 100644
--- a/lib/src/main/java/io/v/v23/syncbase/Database.java
+++ b/lib/src/main/java/io/v/v23/syncbase/Database.java
@@ -147,6 +147,18 @@
InputChannel<WatchChange> watch(VContext context, List<CollectionRowPattern> patterns);
/**
+ * Allows a client to listen for invitations to new syncgroups.
+ *
+ * @param context Vanadium context
+ * @param handler The invitation handler called when an invitation is received.
+ */
+ void listenForInvites(VContext context, Database.InviteHandler handler) throws VException;
+
+ public interface InviteHandler {
+ void handleInvite(Invite invite);
+ }
+
+ /**
* Returns a handle to a database {@link Syncgroup} with the given Id.
*
* @param sgId Id of the synchronization group
diff --git a/lib/src/main/java/io/v/v23/syncbase/DatabaseImpl.java b/lib/src/main/java/io/v/v23/syncbase/DatabaseImpl.java
index 0d3e4eb..b0bf6bb 100644
--- a/lib/src/main/java/io/v/v23/syncbase/DatabaseImpl.java
+++ b/lib/src/main/java/io/v/v23/syncbase/DatabaseImpl.java
@@ -50,6 +50,8 @@
import java.util.Map;
class DatabaseImpl implements Database, BatchDatabase {
+ private native void nativeListenForInvites(VContext ctx, Database.InviteHandler handler)
+ throws VException;
private final String parentFullName;
private final String fullName;
@@ -213,6 +215,11 @@
}
@Override
+ public void listenForInvites(VContext context, Database.InviteHandler handler) throws VException {
+ nativeListenForInvites(context, handler);
+ }
+
+ @Override
public Syncgroup getSyncgroup(Id sgId) {
return new SyncgroupImpl(fullName, sgId);
}
@@ -336,4 +343,5 @@
return columnNames;
}
}
+
}
diff --git a/lib/src/main/java/io/v/v23/syncbase/Invite.java b/lib/src/main/java/io/v/v23/syncbase/Invite.java
new file mode 100644
index 0000000..1012be3
--- /dev/null
+++ b/lib/src/main/java/io/v/v23/syncbase/Invite.java
@@ -0,0 +1,22 @@
+// Copyright 2016 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package io.v.v23.syncbase;
+
+import io.v.v23.services.syncbase.Id;
+
+/**
+ * Represents a new value for an entity watched using {@link Database#watch}.
+ */
+public class Invite {
+ private final Id syncgroup;
+
+ public Invite(String blessing, String name) {
+ this.syncgroup = new Id(blessing, name);
+ }
+
+ public Id getSyncgroupId() {
+ return syncgroup;
+ }
+}