summaryrefslogtreecommitdiffstats
path: root/jrt
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-02-24 13:39:34 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2022-02-24 13:39:34 +0100
commit3698abcfaf3402ec1031cedf0f44cc85af9a9ecf (patch)
tree76108bb57f32439b1e1c2f2f1f58e218c0961bf6 /jrt
parentbaeeee73dc453a803376ac1bbc9e1c81813f7dcb (diff)
Add a synchronized isConnected() method on the Connection.
Diffstat (limited to 'jrt')
-rw-r--r--jrt/src/com/yahoo/jrt/Connection.java4
-rw-r--r--jrt/tests/com/yahoo/jrt/ConnectTest.java13
2 files changed, 12 insertions, 5 deletions
diff --git a/jrt/src/com/yahoo/jrt/Connection.java b/jrt/src/com/yahoo/jrt/Connection.java
index b599579213a..00aceb7e352 100644
--- a/jrt/src/com/yahoo/jrt/Connection.java
+++ b/jrt/src/com/yahoo/jrt/Connection.java
@@ -385,6 +385,10 @@ class Connection extends Target {
return (state == CLOSED);
}
+ public synchronized boolean isConnected() {
+ return (state == CONNECTED);
+ }
+
public boolean hasSocket() {
return ((socket != null) && (socket.channel() != null));
}
diff --git a/jrt/tests/com/yahoo/jrt/ConnectTest.java b/jrt/tests/com/yahoo/jrt/ConnectTest.java
index ae3c07eef69..6ad7198f310 100644
--- a/jrt/tests/com/yahoo/jrt/ConnectTest.java
+++ b/jrt/tests/com/yahoo/jrt/ConnectTest.java
@@ -12,23 +12,26 @@ public class ConnectTest {
Test.Orb client = new Test.Orb(new Transport());
Acceptor acceptor = server.listen(new Spec(0));
- Target target = client.connect(new Spec("localhost", acceptor.port()));
+ Connection target = (Connection) client.connect(new Spec("localhost", acceptor.port()));
for (int i = 0; i < 100; i++) {
- if (target.isValid()) {
+ if (target.isConnected()) {
break;
}
try { Thread.sleep(100); } catch (InterruptedException e) {}
}
- assertTrue(target.isValid());
+ assertTrue(target.isConnected());
+
target.close();
+
for (int i = 0; i < 100; i++) {
- if (!target.isValid()) {
+ if (!target.isClosed()) {
break;
}
try { Thread.sleep(100); } catch (InterruptedException e) {}
}
- assertFalse(target.isValid());
+ assertFalse(target.isClosed());
+
acceptor.shutdown().join();
client.transport().shutdown().join();
server.transport().shutdown().join();