aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api
diff options
context:
space:
mode:
authorTibor Sirovatka <tsirovat@cisco.com>2016-05-13 10:17:51 +0200
committerTibor Sirovatka <tsirovat@cisco.com>2016-05-23 06:25:05 +0000
commit071d610dc446f2914c0ca4c709be38719baa041c (patch)
treee97337183e4078ab00557665a02b9e3f0ee57071 /vpp-api
parent6931f59e54c9643196c0edda20840e49e9eb1da1 (diff)
Changed JVPP interface for construction and connectivity
Simplified construction, autoconnected; possible connect/close See updated sample test cases with changed interface usage Change-Id: Ib53e855880bc414868aa2b9bb8f5df086917e375 Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
Diffstat (limited to 'vpp-api')
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py15
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py15
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_impl_gen.py15
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/VppConnection.java11
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java19
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java4
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java3
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java16
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java5
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java10
10 files changed, 77 insertions, 36 deletions
diff --git a/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py b/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
index de239b6d..e8de3fc1 100644
--- a/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
@@ -51,10 +51,19 @@ public final class CallbackJVppFacade implements $base_package.$callback_facade_
private final $base_package.JVpp jvpp;
private final java.util.Map<Integer, $base_package.$callback_package.JVppCallback> callbacks;
- public CallbackJVppFacade(final $base_package.JVpp jvpp,
- java.util.Map<Integer, $base_package.$callback_package.JVppCallback> callbacks) {
+ /**
+ * <p>Create CallbackJVppFacade object for provided JVpp instance.
+ * Constructor internally creates CallbackJVppFacadeCallback class for processing callbacks
+ * and then connects to provided JVpp instance
+ *
+ * @param jvpp provided $base_package.JVpp instance
+ *
+ * @throws java.io.IOException in case instance cannot connect to JVPP
+ */
+ public CallbackJVppFacade(final $base_package.JVpp jvpp) throws java.io.IOException {
this.jvpp = java.util.Objects.requireNonNull(jvpp,"jvpp is null");
- this.callbacks = callbacks;
+ this.callbacks = new java.util.HashMap<>();
+ this.jvpp.connect(new CallbackJVppFacadeCallback(this.callbacks));
}
@Override
diff --git a/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py b/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py
index 4f63f9bc..5574f120 100644
--- a/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py
@@ -250,9 +250,18 @@ package $base_package.$future_package;
*/
public class FutureJVppFacade extends FutureJVppInvokerFacade implements FutureJVpp {
- public FutureJVppFacade(final $base_package.JVpp jvpp,
- final java.util.Map<Integer, java.util.concurrent.CompletableFuture<? extends $base_package.$dto_package.JVppReply<?>>> requestMap) {
- super(jvpp, requestMap);
+ /**
+ * <p>Create FutureJVppFacade object for provided JVpp instance.
+ * Constructor internally creates FutureJVppFacadeCallback class for processing callbacks
+ * and then connects to provided JVpp instance
+ *
+ * @param jvpp provided $base_package.JVpp instance
+ *
+ * @throws java.io.IOException in case instance cannot connect to JVPP
+ */
+ public FutureJVppFacade(final $base_package.JVpp jvpp) throws java.io.IOException {
+ super(jvpp, new java.util.HashMap<>());
+ jvpp.connect(new FutureJVppFacadeCallback(getRequests()));
}
$methods
}
diff --git a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
index 4e262571..4e408c36 100644
--- a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
@@ -28,6 +28,16 @@ package $base_package;
public interface JVpp extends java.lang.AutoCloseable {
/**
+ * Generic connect with $base_package.callback.JVppCallback callback handler
+ * providing connecting to VPP
+ *
+ * @param callback JVppCallback instance providing callback handling
+ *
+ * @throws java.io.IOException if connection cannot be initiated
+ */
+ void connect($base_package.callback.JVppCallback callback) throws java.io.IOException;
+
+ /**
* Generic dispatch method for sending requests to VPP
*/
int send($base_package.$dto_package.JVppRequest request);
@@ -56,6 +66,11 @@ public final class JVppImpl implements $base_package.JVpp {
}
@Override
+ public void connect($base_package.callback.JVppCallback callback) throws java.io.IOException {
+ connection.connect(callback);
+ }
+
+ @Override
public void close() {
connection.close();
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/VppConnection.java b/vpp-api/java/jvpp/org/openvpp/jvpp/VppConnection.java
index 72ff62c9..19733985 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/VppConnection.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/VppConnection.java
@@ -16,6 +16,8 @@
package org.openvpp.jvpp;
+import java.io.IOException;
+
/**
* Representation of a management connection to VPP.
* Connection is initiated when instance is created, closed with close().
@@ -23,6 +25,15 @@ package org.openvpp.jvpp;
public interface VppConnection extends AutoCloseable {
/**
+ * Open VppConnection for communication with VPP
+ *
+ * @param callback instance handling responses
+ *
+ * @throws IOException if connection is not established
+ */
+ void connect(final org.openvpp.jvpp.callback.JVppCallback callback) throws IOException;
+
+ /**
* Check if this instance connection is active.
*
* @throws IllegalStateException if this instance was disconnected.
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java b/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java
index bf18f128..7401bcad 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/VppJNIConnection.java
@@ -77,7 +77,12 @@ public final class VppJNIConnection implements VppConnection {
private final String clientName;
private volatile boolean disconnected = false;
- private VppJNIConnection(final String clientName) {
+ /**
+ * Create VPPJNIConnection instance for client connecting to VPP.
+ *
+ * @param clientName client name instance to be used for communication. Single connection per clientName is allowed.
+ */
+ public VppJNIConnection(final String clientName) {
this.clientName = Objects.requireNonNull(clientName,"Null clientName");
}
@@ -87,32 +92,28 @@ public final class VppJNIConnection implements VppConnection {
private static final Map<String, VppJNIConnection> connections = new HashMap<>();
/**
- * Create a new Vpp connection identified by clientName parameter.
+ * Initiate VPP connection for current instance
*
* Multiple instances are allowed since this class is not a singleton
* (VPP allows multiple management connections).
*
* However only a single connection per clientName is allowed.
*
- * @param clientName identifier of vpp connection
* @param callback global callback to receive response calls from vpp
*
- * @return new Vpp connection
- * @throws IOException in case the connection could not be established, or there already is a connection with the same name
+ * @throws IOException in case the connection could not be established
*/
- public static VppJNIConnection create(final String clientName, final JVppCallback callback) throws IOException {
+ public void connect(final JVppCallback callback) throws IOException {
synchronized (VppJNIConnection.class) {
if(connections.containsKey(clientName)) {
throw new IOException("Client " + clientName + " already connected");
}
- final VppJNIConnection vppJNIConnection = new VppJNIConnection(clientName);
final int ret = clientConnect(clientName, callback);
if (ret != 0) {
throw new IOException("Connection returned error " + ret);
}
- connections.put(clientName, vppJNIConnection);
- return vppJNIConnection;
+ connections.put(clientName, this);
}
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
index 6b63ade2..b005b137 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
@@ -49,6 +49,10 @@ public class FutureJVppInvokerFacade implements FutureJVppInvoker {
this.requests = Objects.requireNonNull(requestMap, "Null requestMap");
}
+ protected final Map<Integer, CompletableFuture<? extends JVppReply<?>>> getRequests() {
+ return this.requests;
+ }
+
// TODO use Optional in Future, java8
@Override
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java
index 5ac4b69a..c3bb2723 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java
@@ -57,7 +57,8 @@ public class CallbackApiTest {
private static void testCallbackApi() throws Exception {
System.out.println("Testing Java callback API");
- JVpp jvpp = new JVppImpl(VppJNIConnection.create("CallbackApiTest", new TestCallback()));
+ JVpp jvpp = new JVppImpl( new VppJNIConnection("CallbackApiTest"));
+ jvpp.connect( new TestCallback());
System.out.println("Successfully connected to VPP");
System.out.println("Sending ShowVersion request...");
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java
index df3b0e70..b5e50574 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java
@@ -16,15 +16,11 @@
package org.openvpp.jvpp.test;
-import java.util.HashMap;
-import java.util.Map;
import org.openvpp.jvpp.JVpp;
import org.openvpp.jvpp.JVppImpl;
import org.openvpp.jvpp.VppJNIConnection;
-import org.openvpp.jvpp.callback.JVppCallback;
import org.openvpp.jvpp.callback.ShowVersionCallback;
import org.openvpp.jvpp.callfacade.CallbackJVppFacade;
-import org.openvpp.jvpp.callfacade.CallbackJVppFacadeCallback;
/**
* CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request.
@@ -45,19 +41,19 @@ public class CallbackJVppFacadeTest {
private static void testCallbackFacade() throws Exception {
System.out.println("Testing CallbackJVppFacade");
- final Map<Integer, JVppCallback> callbackMap = new HashMap<>();
- JVpp impl = new JVppImpl(VppJNIConnection.create("CallbackApiTest", new CallbackJVppFacadeCallback(callbackMap)));
- CallbackJVppFacade jvpp = new CallbackJVppFacade(impl, callbackMap);
+ JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
+
+ CallbackJVppFacade jvppCallbackFacade = new CallbackJVppFacade(jvpp);
System.out.println("Successfully connected to VPP");
- jvpp.showVersion(showVersionCallback1);
- jvpp.showVersion(showVersionCallback2);
+ jvppCallbackFacade.showVersion(showVersionCallback1);
+ jvppCallbackFacade.showVersion(showVersionCallback2);
Thread.sleep(2000);
System.out.println("Disconnecting...");
- impl.close();
+ jvpp.close();
Thread.sleep(1000);
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java
index f1bd41de..bec302b8 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java
@@ -28,13 +28,14 @@ public class ControlPingTest {
private static void testControlPing() throws Exception {
System.out.println("Testing ControlPing using Java callback API");
- JVpp jvpp = new JVppImpl(VppJNIConnection.create("ControlPingTest", new ControlPingCallback() {
+ JVpp jvpp = new JVppImpl( new VppJNIConnection("ControlPingTest"));
+ jvpp.connect( new ControlPingCallback() {
@Override
public void onControlPingReply(final ControlPingReply reply) {
System.out.printf("Received ControlPingReply: context=%d, retval=%d, clientIndex=%d vpePid=%d\n",
reply.context, reply.retval, reply.clientIndex, reply.vpePid);
}
- }));
+ });
System.out.println("Successfully connected to VPP");
Thread.sleep(1000);
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
index fc84c951..745482d1 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
@@ -16,22 +16,17 @@
package org.openvpp.jvpp.test;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.openvpp.jvpp.VppJNIConnection;
import org.openvpp.jvpp.dto.GetNodeIndex;
import org.openvpp.jvpp.dto.GetNodeIndexReply;
-import org.openvpp.jvpp.dto.JVppReply;
import org.openvpp.jvpp.dto.ShowVersion;
import org.openvpp.jvpp.dto.ShowVersionReply;
import org.openvpp.jvpp.dto.SwInterfaceDetails;
import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
import org.openvpp.jvpp.dto.SwInterfaceDump;
import org.openvpp.jvpp.future.FutureJVppFacade;
-import org.openvpp.jvpp.future.FutureJVppFacadeCallback;
public class FutureApiTest {
@@ -104,10 +99,9 @@ public class FutureApiTest {
private static void testFutureApi() throws Exception {
System.out.println("Testing Java future API");
- final Map<Integer, CompletableFuture<? extends JVppReply<?>>> map = new HashMap<>();
final org.openvpp.jvpp.JVppImpl impl =
- new org.openvpp.jvpp.JVppImpl(VppJNIConnection.create("FutureApiTest", new FutureJVppFacadeCallback(map)));
- final FutureJVppFacade jvppFacade = new FutureJVppFacade(impl, map);
+ new org.openvpp.jvpp.JVppImpl(new VppJNIConnection("FutureApiTest"));
+ final FutureJVppFacade jvppFacade = new FutureJVppFacade(impl);
System.out.println("Successfully connected to VPP");
testShowVersion(jvppFacade);