diff options
author | Mark Spruiell <mes@zeroc.com> | 2014-05-29 11:06:44 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2014-05-29 11:06:44 -0700 |
commit | 3cfd324cdcc65d2acbc7536f1652d44f66a0e896 (patch) | |
tree | 44613394c5b9c6c6eb0ec8b41e110002a58d60ea /java/test/Ice | |
parent | Fixed Python throughput demo config (diff) | |
download | ice-3cfd324cdcc65d2acbc7536f1652d44f66a0e896.tar.bz2 ice-3cfd324cdcc65d2acbc7536f1652d44f66a0e896.tar.xz ice-3cfd324cdcc65d2acbc7536f1652d44f66a0e896.zip |
porting C++ transport changes to Java
Diffstat (limited to 'java/test/Ice')
-rw-r--r-- | java/test/Ice/background/Acceptor.java | 6 | ||||
-rw-r--r-- | java/test/Ice/background/Configuration.java | 13 | ||||
-rw-r--r-- | java/test/Ice/background/EndpointFactory.java | 19 | ||||
-rw-r--r-- | java/test/Ice/background/EndpointI.java | 81 | ||||
-rw-r--r-- | java/test/Ice/background/Transceiver.java | 89 | ||||
-rw-r--r-- | java/test/Ice/hold/HoldI.java | 2 |
6 files changed, 127 insertions, 83 deletions
diff --git a/java/test/Ice/background/Acceptor.java b/java/test/Ice/background/Acceptor.java index 5833012a313..02a33c49506 100644 --- a/java/test/Ice/background/Acceptor.java +++ b/java/test/Ice/background/Acceptor.java @@ -36,6 +36,12 @@ class Acceptor implements IceInternal.Acceptor } public String + protocol() + { + return _acceptor.protocol(); + } + + public String toString() { return _acceptor.toString(); diff --git a/java/test/Ice/background/Configuration.java b/java/test/Ice/background/Configuration.java index 15e7b37e58c..befe01738fc 100644 --- a/java/test/Ice/background/Configuration.java +++ b/java/test/Ice/background/Configuration.java @@ -143,6 +143,18 @@ public final class Configuration } } + public synchronized void + buffered(boolean b) + { + _buffered = b; + } + + public synchronized boolean + buffered() + { + return _buffered; + } + private Ice.LocalException _connectorsException; private Ice.LocalException _connectException; private int _initializeSocketStatus; @@ -152,4 +164,5 @@ public final class Configuration private Ice.LocalException _readException; private int _writeReadyCount; private Ice.LocalException _writeException; + private boolean _buffered; } diff --git a/java/test/Ice/background/EndpointFactory.java b/java/test/Ice/background/EndpointFactory.java index b611e5bf911..55aba553082 100644 --- a/java/test/Ice/background/EndpointFactory.java +++ b/java/test/Ice/background/EndpointFactory.java @@ -29,16 +29,21 @@ final class EndpointFactory implements IceInternal.EndpointFactory } public IceInternal.EndpointI - create(String str, boolean server) + create(java.util.ArrayList<String> args, boolean server) { - return new EndpointI(_configuration, _factory.create(str, server)); + return new EndpointI(_configuration, _factory.create(args, server)); } public IceInternal.EndpointI read(IceInternal.BasicStream s) { - s.readShort(); - return new EndpointI(_configuration, _factory.read(s)); + short type = s.readShort(); + assert(type == _factory.type()); + + s.startReadEncaps(); + IceInternal.EndpointI endpoint = new EndpointI(_configuration, _factory.read(s)); + s.endReadEncaps(); + return endpoint; } public void @@ -46,6 +51,12 @@ final class EndpointFactory implements IceInternal.EndpointFactory { } + public IceInternal.EndpointFactory + clone(IceInternal.ProtocolInstance instance) + { + return this; + } + private Configuration _configuration; private IceInternal.EndpointFactory _factory; } diff --git a/java/test/Ice/background/EndpointI.java b/java/test/Ice/background/EndpointI.java index 575123e4978..d364e0b32a8 100644 --- a/java/test/Ice/background/EndpointI.java +++ b/java/test/Ice/background/EndpointI.java @@ -19,67 +19,45 @@ final class EndpointI extends IceInternal.EndpointI _configuration = configuration; } - // - // Marshal the endpoint - // - public void - streamWrite(IceInternal.BasicStream s) - { - s.writeShort(type()); - _endpoint.streamWrite(s); - } - - // - // Convert the endpoint to its string form - // public String _toString() { return "test-" + _endpoint.toString(); } - // - // Return the endpoint information/ - // public Ice.EndpointInfo getInfo() { return _endpoint.getInfo(); } - // - // Return the endpoint type - // + public void + streamWrite(IceInternal.BasicStream s) + { + s.startWriteEncaps(); + s.writeShort(_endpoint.type()); + _endpoint.streamWrite(s); + s.endWriteEncaps(); + } + public short type() { return (short)(TYPE_BASE + _endpoint.type()); } - // - // Return the protocol name - // public String protocol() { return _endpoint.protocol(); } - // - // Return the timeout for the endpoint in milliseconds. 0 means - // non-blocking, -1 means no timeout. - // public int timeout() { return _endpoint.timeout(); } - // - // Return a new endpoint with a different timeout value, provided - // that timeouts are supported by the endpoint. Otherwise the same - // endpoint is returned. - // public IceInternal.EndpointI timeout(int timeout) { @@ -94,9 +72,12 @@ final class EndpointI extends IceInternal.EndpointI } } - // - // Return a new endpoint with a different connection id. - // + public String + connectionId() + { + return _endpoint.connectionId(); + } + public IceInternal.EndpointI connectionId(String connectionId) { @@ -111,21 +92,12 @@ final class EndpointI extends IceInternal.EndpointI } } - // - // Return true if the endpoints support bzip2 compress, or false - // otherwise. - // public boolean compress() { return _endpoint.compress(); } - // - // Return a new endpoint with a different compression value, - // provided that compression is supported by the - // endpoint. Otherwise the same endpoint is returned. - // public IceInternal.EndpointI compress(boolean compress) { @@ -140,31 +112,18 @@ final class EndpointI extends IceInternal.EndpointI } } - // - // Return true if the endpoint is datagram-based. - // public boolean datagram() { return _endpoint.datagram(); } - // - // Return true if the endpoint is secure. - // public boolean secure() { return _endpoint.secure(); } - // - // Return a server side transceiver for this endpoint, or null if a - // transceiver can only be created by an acceptor. In case a - // transceiver is created, this operation also returns a new - // "effective" endpoint, which might differ from this endpoint, - // for example, if a dynamic port number is assigned. - // public IceInternal.Transceiver transceiver(IceInternal.EndpointIHolder endpoint) { @@ -188,10 +147,6 @@ final class EndpointI extends IceInternal.EndpointI } } - // - // Return connectors for this endpoint, or empty list if no connector - // is available. - // public java.util.List<IceInternal.Connector> connectors(Ice.EndpointSelectionType selType) { @@ -272,6 +227,12 @@ final class EndpointI extends IceInternal.EndpointI return testEndpoint._endpoint.equivalent(_endpoint); } + public String + options() + { + return _endpoint.options(); + } + public int hashCode() { diff --git a/java/test/Ice/background/Transceiver.java b/java/test/Ice/background/Transceiver.java index 8209e90a600..36a0b85a6d2 100644 --- a/java/test/Ice/background/Transceiver.java +++ b/java/test/Ice/background/Transceiver.java @@ -18,14 +18,18 @@ final class Transceiver implements IceInternal.Transceiver } public int - initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer) + initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer, Ice.BooleanHolder moreData) { int status = _configuration.initializeSocketStatus(); - if(status == IceInternal.SocketOperation.Connect || status == IceInternal.SocketOperation.Write) + if(status == IceInternal.SocketOperation.Connect) + { + return status; + } + else if(status == IceInternal.SocketOperation.Write) { if(!_initialized) { - status = _transceiver.initialize(readBuffer, writeBuffer); + status = _transceiver.initialize(readBuffer, writeBuffer, moreData); if(status != IceInternal.SocketOperation.None) { return status; @@ -42,7 +46,7 @@ final class Transceiver implements IceInternal.Transceiver _configuration.checkInitializeException(); if(!_initialized) { - status = _transceiver.initialize(readBuffer, writeBuffer); + status = _transceiver.initialize(readBuffer, writeBuffer, moreData); if(status != IceInternal.SocketOperation.None) { return status; @@ -52,41 +56,82 @@ final class Transceiver implements IceInternal.Transceiver return IceInternal.SocketOperation.None; } + public int + closing(boolean initiator, Ice.LocalException ex) + { + return _transceiver.closing(initiator, ex); + } + public void close() { _transceiver.close(); } - public boolean + public int write(IceInternal.Buffer buf) { - if(!_configuration.writeReady()) + if(!_configuration.writeReady() && buf.b.hasRemaining()) { - return false; + return IceInternal.SocketOperation.Write; } + _configuration.checkWriteException(); return _transceiver.write(buf); } - public boolean + public int read(IceInternal.Buffer buf, Ice.BooleanHolder moreData) { - if(!moreData.value) + if(!_configuration.readReady() && buf.b.hasRemaining()) + { + return IceInternal.SocketOperation.Read; + } + + _configuration.checkReadException(); + + if(_buffered) { - if(!_configuration.readReady()) + while(buf.b.hasRemaining()) { - return false; + if(_readBufferPos == _readBuffer.b.position()) + { + _readBufferPos = 0; + _readBuffer.b.position(0); + _transceiver.read(_readBuffer, moreData); + if(_readBufferPos == _readBuffer.b.position()) + { + moreData.value = false; + return IceInternal.SocketOperation.Read; + } + } + assert(_readBuffer.b.position() > _readBufferPos); + int requested = buf.b.remaining(); + int available = _readBuffer.b.position() - _readBufferPos; + assert(available > 0); + if(available >= requested) + { + available = requested; + } + + byte[] arr = new byte[available]; + _readBuffer.b.get(arr); + buf.b.put(arr); + _readBufferPos += available; } + moreData.value = _readBufferPos < _readBuffer.b.position(); + return IceInternal.SocketOperation.None; + } + else + { + return _transceiver.read(buf, moreData); } - _configuration.checkReadException(); - return _transceiver.read(buf, moreData); } public String - type() + protocol() { - return "test-" + _transceiver.type(); + return "test-" + _transceiver.protocol(); } public String @@ -114,9 +159,17 @@ final class Transceiver implements IceInternal.Transceiver { _transceiver = transceiver; _configuration = configuration; + _initialized = false; + _buffered = _configuration.buffered(); + _readBuffer = new IceInternal.Buffer(100 * 1024, false); + _readBuffer.resize(1024 * 8, true); // 8KB buffer + _readBufferPos = 0; } - final private IceInternal.Transceiver _transceiver; - final private Configuration _configuration; - private boolean _initialized = false; + private final IceInternal.Transceiver _transceiver; + private final Configuration _configuration; + private boolean _initialized; + private final boolean _buffered; + private IceInternal.Buffer _readBuffer; + private int _readBufferPos; } diff --git a/java/test/Ice/hold/HoldI.java b/java/test/Ice/hold/HoldI.java index 2a2cddfc726..00a80469bbc 100644 --- a/java/test/Ice/hold/HoldI.java +++ b/java/test/Ice/hold/HoldI.java @@ -111,7 +111,7 @@ public final class HoldI extends _HoldDisp { if(_last != expected) { - System.err.println("_last = " + _last + " expected = " + expected); + System.err.println("_last = " + _last + " expected = " + expected + " value = " + value); _adapter.getCommunicator().shutdown(); test(false); } |