Author: david.lloyd(a)jboss.com
Date: 2010-02-28 17:05:37 -0500 (Sun, 28 Feb 2010)
New Revision: 5773
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteTestCase.java
remoting3/trunk/jboss-remoting/src/test/resources/logging.properties
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java
Log:
Clean up close path a little bit
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -43,6 +43,18 @@
void close() throws IOException;
/**
+ * Wait for a resource close to complete.
+ *
+ * @throws InterruptedException if the operation is interrupted
+ */
+ void awaitClosed() throws InterruptedException;
+
+ /**
+ * Wait for a resource close to complete.
+ */
+ void awaitClosedUninterruptibly();
+
+ /**
* Add a handler that will be called upon close. If the resource is already closed,
the handler will be called
* immediately.
*
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -75,6 +75,7 @@
try {
res = channel.write(buffer);
} catch (IOException e1) {
+ RemoteConnectionHandler.log.trace(e1, "Failed to send
client greeting message");
IoUtils.safeClose(connection);
connection.free(buffer);
return;
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -100,6 +100,7 @@
try {
res = channel.write(buffer);
} catch (IOException e1) {
+ RemoteConnectionHandler.log.trace(e1, "Failed to send
server greeting message");
IoUtils.safeClose(connection);
connection.free(buffer);
return;
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -120,21 +120,7 @@
this.closeHandlers = null;
break;
}
- case CLOSING: {
- if (Thread.currentThread() != closingThread) {
- while (state != State.CLOSED) {
- try {
- closeLock.wait();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new InterruptedIOException("Close
interrupted");
- }
- }
- } else {
- // reentrant close always goes through unblocked
- }
- return;
- }
+ case CLOSING:
case CLOSED: return;
default: throw new IllegalStateException();
}
@@ -158,6 +144,33 @@
}
}
+ /** {@inheritDoc} */
+ public void awaitClosed() throws InterruptedException {
+ synchronized (closeLock) {
+ while (state != State.CLOSED) {
+ closeLock.wait();
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void awaitClosedUninterruptibly() {
+ boolean intr = false;
+ try {
+ synchronized (closeLock) {
+ while (state != State.CLOSED) {
+ try {
+ closeLock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ }
+ } finally {
+ if (intr) Thread.currentThread().interrupt();
+ }
+ }
+
/**
* {@inheritDoc}
*/
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -106,12 +106,15 @@
assertEquals(replyObj, client.invoke(requestObj));
} finally {
IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
}
} finally {
IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
}
} finally {
IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
}
} finally {
exit();
@@ -151,12 +154,15 @@
assertEquals(replyObj, client.send(requestObj).get());
} finally {
IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
}
} finally {
IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
}
} finally {
IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
}
} finally {
exit();
@@ -208,12 +214,15 @@
}, InvocationTestObject.class, InvocationTestObject.class));
} finally {
IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
}
} finally {
IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
}
} finally {
IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
}
} catch (UnsupportedOperationException e) {
throw new SkipException("Skipping test due to unsupported
createClientConnector");
@@ -244,6 +253,7 @@
enter();
try {
Xnio.getInstance().close();
+ System.runFinalization();
} finally {
exit();
}
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteTestCase.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteTestCase.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteTestCase.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -101,11 +101,11 @@
final ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
listener =
provider.getServerListener(OptionMap.builder().set(RemotingOptions.AUTHENTICATION_PROVIDER,
"test").setSequence(Options.SASL_MECHANISMS, "DIGEST-MD5").getMap());
final Xnio xnio = Xnio.getInstance();
try {
-// final AcceptingServer<InetSocketAddress, ?, ?> server =
xnio.createSslTcpServer(listener, OptionMap.EMPTY);
+// final AcceptingServer<InetSocketAddress, ?, ?> server =
xnio.createSslTcpServer(listener,
OptionMap.builder().setSequence(Options.SSL_ENABLED_CIPHER_SUITES,
"TLS_RSA_WITH_AES_128_CBC_SHA").getMap());
final AcceptingServer<InetSocketAddress, ?, ?> server =
xnio.createTcpServer(listener, OptionMap.EMPTY);
final IoFuture<? extends BoundChannel<InetSocketAddress>> future
= server.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0));
final InetSocketAddress localAddress = future.get().getLocalAddress();
- final Connection connection = endpoint.connect(new URI("remote",
null, localAddress.getAddress().getHostAddress(), localAddress.getPort(), null, null,
null), OptionMap.EMPTY, "user", null,
"password".toCharArray()).get();
+ final Connection connection = endpoint.connect(new URI("remote",
null, localAddress.getAddress().getHostAddress(), localAddress.getPort(), null, null,
null), OptionMap.builder().setSequence(Options.SSL_ENABLED_CIPHER_SUITES,
"TLS_RSA_WITH_AES_128_CBC_SHA").getMap(), "user", null,
"password".toCharArray()).get();
connection.addCloseHandler(new CloseHandler<Connection>() {
public void handleClose(final Connection closed) {
IoUtils.safeClose(server);
Modified: remoting3/trunk/jboss-remoting/src/test/resources/logging.properties
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/resources/logging.properties 2010-02-28
21:14:06 UTC (rev 5772)
+++ remoting3/trunk/jboss-remoting/src/test/resources/logging.properties 2010-02-28
22:05:37 UTC (rev 5773)
@@ -21,26 +21,24 @@
#
# Additional logger names to configure (root logger is always configured)
-#loggers=org.foo.bar, org.foo.baz
+loggers=javax.security.sasl
-# Root logger level
-logger.level=TRACE
-
-# Declare handlers for the root logger
+# Root logger configuration
+logger.level=DEBUG
logger.handlers=CONSOLE
-# Declare handlers for additional loggers
-#logger.org.foo.bar.handlers=XXX, YYY
+# Configure javax.security.sasl to be less verbose by default
+logger.javax.security.sasl.level=INFO
# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.target=SYSTEM_ERR
handler.CONSOLE.properties=autoFlush
-handler.CONSOLE.level=TRACE
+handler.CONSOLE.level=DEBUG
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN
-# The log format pattern for both logs
+# The log format pattern
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p (%t) [%c] %m%n
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java
===================================================================
---
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java 2010-02-28
21:14:06 UTC (rev 5772)
+++
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/server/SocketServerRequestHandler.java 2010-02-28
22:05:37 UTC (rev 5773)
@@ -157,7 +157,15 @@
return null;
}
- public String toString() {
+ public void awaitClosed() throws InterruptedException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void awaitClosedUninterruptibly() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String toString() {
return "SocketServerRequestHandler[" + super.toString() + "]";
}