summaryrefslogtreecommitdiffstats
path: root/vpp-api
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-11-03 10:52:43 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2016-11-03 16:42:41 +0000
commitbdb1f8193736c0c63429d049397d4783959c1148 (patch)
tree48df00eab6d0315a91b67cd81286ae5536f1f81f /vpp-api
parente7637e701717f24172cdbdbf89ba71bdef5125de (diff)
Fail to register Java API for plugin that was not loaded (VPP-522)
Change-Id: Idb95888ae6fc7a9df197a919e3d3283f915f4a4c Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-api')
-rw-r--r--vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java b/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java
index fb2ef1c047f..01578ce0326 100644
--- a/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java
+++ b/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java
@@ -18,14 +18,16 @@ package io.fd.vpp.jvpp;
import static java.util.Objects.requireNonNull;
+import io.fd.vpp.jvpp.callback.ControlPingCallback;
+import io.fd.vpp.jvpp.callback.JVppCallback;
+import io.fd.vpp.jvpp.dto.ControlPingReply;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import io.fd.vpp.jvpp.callback.ControlPingCallback;
-import io.fd.vpp.jvpp.callback.JVppCallback;
-import io.fd.vpp.jvpp.dto.ControlPingReply;
/**
* Default implementation of JVppRegistry.
@@ -35,13 +37,13 @@ public final class JVppRegistryImpl implements JVppRegistry, ControlPingCallback
private static final Logger LOG = Logger.getLogger(JVppRegistryImpl.class.getName());
private final VppJNIConnection connection;
- private final ConcurrentMap<String, JVppCallback> pluginRegistry;
+ private final Map<String, JVppCallback> pluginRegistry;
private final ConcurrentMap<Integer, ControlPingCallback> pingCalls;
public JVppRegistryImpl(final String clientName) throws IOException {
connection = new VppJNIConnection(clientName);
connection.connect();
- pluginRegistry = new ConcurrentHashMap<>();
+ pluginRegistry = new HashMap<>();
pingCalls = new ConcurrentHashMap<>();
}
@@ -51,26 +53,28 @@ public final class JVppRegistryImpl implements JVppRegistry, ControlPingCallback
}
@Override
- public void register(final JVpp jvpp, final JVppCallback callback) {
+ public synchronized void register(final JVpp jvpp, final JVppCallback callback) {
requireNonNull(jvpp, "jvpp should not be null");
requireNonNull(callback, "Callback should not be null");
final String name = jvpp.getClass().getName();
- if (pluginRegistry.putIfAbsent(name, callback) != null) {
- throw new IllegalArgumentException(String.format("Callback for plugin %s was already registered", name));
+ if (pluginRegistry.containsKey(name)) {
+ throw new IllegalArgumentException(
+ String.format("Callback for plugin %s was already registered", name));
}
jvpp.init(this, callback, connection.getConnectionInfo().queueAddress,
connection.getConnectionInfo().clientIndex);
+ pluginRegistry.put(name, callback);
}
@Override
- public void unregister(final String name) {
+ public synchronized void unregister(final String name) {
requireNonNull(name, "Plugin name should not be null");
final JVppCallback previous = pluginRegistry.remove(name);
assertPluginWasRegistered(name, previous);
}
@Override
- public JVppCallback get(final String name) {
+ public synchronized JVppCallback get(final String name) {
requireNonNull(name, "Plugin name should not be null");
JVppCallback value = pluginRegistry.get(name);
assertPluginWasRegistered(name, value);
@@ -80,7 +84,7 @@ public final class JVppRegistryImpl implements JVppRegistry, ControlPingCallback
private native int controlPing0() throws VppInvocationException;
@Override
- public int controlPing(final Class<? extends JVpp> clazz) throws VppInvocationException {
+ public synchronized int controlPing(final Class<? extends JVpp> clazz) throws VppInvocationException {
connection.checkActive();
final String name = clazz.getName();
@@ -96,7 +100,6 @@ public final class JVppRegistryImpl implements JVppRegistry, ControlPingCallback
return context;
}
-
@Override
public void onControlPingReply(final ControlPingReply reply) {
final ControlPingCallback callback = pingCalls.get(reply.context);