diff options
author | Robert Godfrey <rgodfrey@apache.org> | 2009-10-05 14:39:14 +0000 |
---|---|---|
committer | Robert Godfrey <rgodfrey@apache.org> | 2009-10-05 14:39:14 +0000 |
commit | 794ca3067d66964da3b623872bd50594f6dcbb8a (patch) | |
tree | 5302f769ef2bb331d0f25bba2963f24b735c8532 | |
parent | 7d14321fb1a64a98cef69ef00dd1aadea71f81e6 (diff) | |
download | qpid-python-794ca3067d66964da3b623872bd50594f6dcbb8a.tar.gz |
Merged from java-network-refactor up to r821809
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-0-10@821810 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 31 insertions, 20 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java b/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java index be75fc150f..06a1fe2696 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java @@ -564,9 +564,16 @@ public class AMQProtocolHandler implements ProtocolEngine public void writeFrame(AMQDataBlock frame, boolean wait) { - ByteBuffer buf = frame.toNioByteBuffer(); + final ByteBuffer buf = frame.toNioByteBuffer(); _writtenBytes += buf.remaining(); - _networkDriver.send(buf); + Job.fireAsynchEvent(_poolReference.getPool(), _writeJob, new Runnable() + { + @Override + public void run() + { + _networkDriver.send(buf); + } + }); if (PROTOCOL_DEBUG) { _protocolLogger.debug(String.format("SEND: [%s] %s", this, frame)); diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MINANetworkDriver.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MINANetworkDriver.java index 38ea9307b7..b0d1c46572 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MINANetworkDriver.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MINANetworkDriver.java @@ -159,7 +159,7 @@ public class MINANetworkDriver extends IoHandlerAdapter implements NetworkDriver } catch (IOException e) { - throw new BindException(String.format("Could not bind to {0}:{2}", addr, port)); + throw new BindException(String.format("Could not bind to %1s:%2s", addr, port)); } } } @@ -171,7 +171,7 @@ public class MINANetworkDriver extends IoHandlerAdapter implements NetworkDriver } catch (IOException e) { - throw new BindException(String.format("Could not bind to *:{1}", port)); + throw new BindException(String.format("Could not bind to *:%1s", port)); } } _acceptingConnections = true; diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/mina/MINANetworkDriverTest.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/mina/MINANetworkDriverTest.java index 5500ff9d4b..5af07d9735 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/mina/MINANetworkDriverTest.java +++ b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/mina/MINANetworkDriverTest.java @@ -186,14 +186,7 @@ public class MINANetworkDriverTest extends TestCase _client.open(TEST_PORT, InetAddress.getLocalHost(), _countingEngine, null, null); assertFalse("Reader should not have been idle", _countingEngine.getReaderHasBeenIdle()); _client.setMaxReadIdle(1); - try - { - Thread.sleep(1000); - } - catch (InterruptedException e) - { - // Eat it - } + sleepForAtLeast(1500); assertTrue("Reader should have been idle", _countingEngine.getReaderHasBeenIdle()); } @@ -211,14 +204,7 @@ public class MINANetworkDriverTest extends TestCase _client.open(TEST_PORT, InetAddress.getLocalHost(), _countingEngine, null, null); assertFalse("Reader should not have been idle", _countingEngine.getWriterHasBeenIdle()); _client.setMaxWriteIdle(1); - try - { - Thread.sleep(1000); - } - catch (InterruptedException e) - { - // Eat it - } + sleepForAtLeast(1500); assertTrue("Reader should have been idle", _countingEngine.getWriterHasBeenIdle()); } @@ -484,4 +470,22 @@ public class MINANetworkDriverTest extends TestCase _driver.send(msg); } } + + public static void sleepForAtLeast(long period) + { + long start = System.currentTimeMillis(); + long timeLeft = period; + while (timeLeft > 0) + { + try + { + Thread.sleep(timeLeft); + } + catch (InterruptedException e) + { + // Ignore it + } + timeLeft = period - (System.currentTimeMillis() - start); + } + } }
\ No newline at end of file |