Code Review
/
vpp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Rebalance checkConnected()
[vpp.git]
/
vpp-japi
/
japi
/
org
/
openvpp
/
vppjapi
/
vppConn.java
diff --git
a/vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
b/vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
index
8de806d
..
3e8c12a
100644
(file)
--- a/
vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
+++ b/
vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
@@
-23,7
+23,6
@@
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.openvpp.vppjapi.vppVersion;
import org.openvpp.vppjapi.vppInterfaceDetails;
import org.openvpp.vppjapi.vppVersion;
import org.openvpp.vppjapi.vppInterfaceDetails;
@@
-39,8
+38,8
@@
public class vppConn implements AutoCloseable {
static {
try {
loadLibrary();
static {
try {
loadLibrary();
- } catch (
IOException | Runtime
Exception e) {
- System.out.printf
("Can't find vpp jni library: %s\n", LIBNAME);
+ } catch (Exception e) {
+ System.out.printf("Can't find vpp jni library: %s\n", LIBNAME);
throw new ExceptionInInitializerError(e);
}
}
throw new ExceptionInInitializerError(e);
}
}
@@
-67,7
+66,7
@@
public class vppConn implements AutoCloseable {
private static void loadLibrary() throws IOException {
try (final InputStream is = vppConn.class.getResourceAsStream('/' + LIBNAME)) {
if (is == null) {
private static void loadLibrary() throws IOException {
try (final InputStream is = vppConn.class.getResourceAsStream('/' + LIBNAME)) {
if (is == null) {
- throw new IOException(String.format("Failed to open library resource %s",
+
throw new IOException(String.format("Failed to open library resource %s",
LIBNAME));
}
loadStream(is);
LIBNAME));
}
loadStream(is);
@@
-75,8
+74,8
@@
public class vppConn implements AutoCloseable {
}
private static vppConn currentConnection = null;
}
private static vppConn currentConnection = null;
- private final AtomicBoolean disconnected = new AtomicBoolean(false);
private final String clientName;
private final String clientName;
+ private volatile boolean disconnected = false;
// Hidden on purpose to prevent external instantiation
vppConn(final String clientName) throws IOException {
// Hidden on purpose to prevent external instantiation
vppConn(final String clientName) throws IOException {
@@
-97,8
+96,10
@@
public class vppConn implements AutoCloseable {
}
@Override
}
@Override
- public final void close() {
- if (disconnected.compareAndSet(false, true)) {
+ public synchronized final void close() {
+ if (!disconnected) {
+ disconnected = true;
+
synchronized (vppConn.class) {
clientDisconnect();
currentConnection = null;
synchronized (vppConn.class) {
clientDisconnect();
currentConnection = null;
@@
-112,7
+113,7
@@
public class vppConn implements AutoCloseable {
* @throws IllegalStateException if this instance was disconnected.
*/
protected final void checkConnected() {
* @throws IllegalStateException if this instance was disconnected.
*/
protected final void checkConnected() {
- if (disconnected
.get()
) {
+ if (disconnected) {
throw new IllegalStateException("Disconnected client " + clientName);
}
}
throw new IllegalStateException("Disconnected client " + clientName);
}
}