diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/CommunicatorI.java | 15 | ||||
-rw-r--r-- | java/src/Ice/ObjectPrx.java | 4 | ||||
-rw-r--r-- | java/src/Ice/ObjectPrxHelper.java | 4 | ||||
-rw-r--r-- | java/src/Ice/PropertiesI.java | 39 | ||||
-rw-r--r-- | java/src/Ice/Util.java | 37 | ||||
-rw-r--r-- | java/src/Ice/_ObjectDelM.java | 8 | ||||
-rw-r--r-- | java/src/IceInternal/BasicStream.java | 6 | ||||
-rw-r--r-- | java/src/IceInternal/Emitter.java | 8 | ||||
-rw-r--r-- | java/src/IceInternal/EmitterFactory.java | 5 | ||||
-rw-r--r-- | java/src/IceInternal/Endpoint.java | 32 | ||||
-rw-r--r-- | java/src/IceInternal/Instance.java | 26 | ||||
-rw-r--r-- | java/src/IceInternal/Outgoing.java | 24 | ||||
-rw-r--r-- | java/src/IceInternal/ProxyFactory.java | 14 | ||||
-rw-r--r-- | java/src/IceInternal/Reference.java | 31 | ||||
-rw-r--r-- | java/src/IceInternal/TcpEndpoint.java | 47 | ||||
-rw-r--r-- | java/src/IceInternal/ThreadPool.java | 251 | ||||
-rw-r--r-- | java/src/IceInternal/TraceUtil.java | 7 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpoint.java | 38 | ||||
-rw-r--r-- | java/src/IceInternal/UnknownEndpoint.java | 10 |
19 files changed, 312 insertions, 294 deletions
diff --git a/java/src/Ice/CommunicatorI.java b/java/src/Ice/CommunicatorI.java index 3e14888acab..e49b9421ed3 100644 --- a/java/src/Ice/CommunicatorI.java +++ b/java/src/Ice/CommunicatorI.java @@ -61,16 +61,25 @@ class CommunicatorI implements Communicator return _instance.proxyFactory().proxyToString(proxy); } - public synchronized ObjectAdapter + public ObjectAdapter createObjectAdapter(String name) { + return createObjectAdapterFromProperty(name, "Ice.Adapter." + name + + ".Endpoints"); + } + + public synchronized ObjectAdapter + createObjectAdapterFromProperty(String name, String property) + { if (_instance == null) { throw new CommunicatorDestroyedException(); } - String endpts = _instance.properties().getProperty( - "Ice.Adapter." + name + ".Endpoints"); + /* TODO: Server + String endpts = _instance.properties().getProperty(property); return createObjectAdapterWithEndpoints(name, endpts); + */ + return null; } public synchronized ObjectAdapter diff --git a/java/src/Ice/ObjectPrx.java b/java/src/Ice/ObjectPrx.java index 37426e757f0..771b0c5225d 100644 --- a/java/src/Ice/ObjectPrx.java +++ b/java/src/Ice/ObjectPrx.java @@ -25,9 +25,9 @@ public interface ObjectPrx public byte[] ice_invoke(String operation, boolean nonmutating, byte[] inParams, java.util.HashMap __context); - public String ice_getIdentity(); + public Identity ice_getIdentity(); - public ObjectPrx ice_newIdentity(String newIdentity); + public ObjectPrx ice_newIdentity(Identity newIdentity); public String ice_getFacet(); diff --git a/java/src/Ice/ObjectPrxHelper.java b/java/src/Ice/ObjectPrxHelper.java index 560e5c1b76c..60cc18562e3 100644 --- a/java/src/Ice/ObjectPrxHelper.java +++ b/java/src/Ice/ObjectPrxHelper.java @@ -130,14 +130,14 @@ public class ObjectPrxHelper implements ObjectPrx } } - public final String + public final Identity ice_getIdentity() { return _reference.identity; } public final ObjectPrx - ice_newIdentity(String newIdentity) + ice_newIdentity(Identity newIdentity) { if (newIdentity.equals(_reference.identity)) { diff --git a/java/src/Ice/PropertiesI.java b/java/src/Ice/PropertiesI.java index a2e58892aa7..f0f91aff54e 100644 --- a/java/src/Ice/PropertiesI.java +++ b/java/src/Ice/PropertiesI.java @@ -37,6 +37,12 @@ class PropertiesI implements Properties return p; } + static void + addArgumentPrefix(String prefix) + { + _argumentPrefixes.add(prefix); + } + PropertiesI(String[] args) { for (int i = 0; i < args.length; i++) @@ -90,17 +96,34 @@ class PropertiesI implements Properties int idx = 0; while (idx < args.length) { - if (args[idx].startsWith("--Ice.")) + boolean match = false; + String arg = args[idx]; + int beg = arg.indexOf("--"); + if (beg == 0) { - String line = args[idx]; - if (line.indexOf('=') == -1) + int end = arg.indexOf('.'); + if (end != -1) { - line += "=1"; + String prefix = arg.substring(2, end); + if (prefix.equals("Ice") || + _argumentPrefixes.contains(prefix)) + { + match = true; + } + + if (match) + { + if (arg.indexOf('=') == -1) + { + arg += "=1"; + } + + parseLine(arg.substring(2)); + } } - - parseLine(line.substring(2)); } - else + + if (!match) { idx++; } @@ -181,4 +204,6 @@ class PropertiesI implements Properties } private java.util.HashMap _properties = new java.util.HashMap(); + private static java.util.HashSet _argumentPrefixes = + new java.util.HashSet(); } diff --git a/java/src/Ice/Util.java b/java/src/Ice/Util.java index d9e8abfe5fa..58c970bd331 100644 --- a/java/src/Ice/Util.java +++ b/java/src/Ice/Util.java @@ -46,5 +46,42 @@ public final class Util return new CommunicatorI(properties); } + public static void + addArgumentPrefix(String prefix) + { + PropertiesI.addArgumentPrefix(prefix); + } + + public static Identity + stringToIdentity(String s) + { + Identity ident = new Identity(); + int pos = s.indexOf('#'); + if (pos != -1) + { + ident.category = s.substring(0, pos); + ident.name = s.substring(pos + 1); + } + else + { + ident.category = ""; + ident.name = s; + } + return ident; + } + + public static String + identityToString(Identity ident) + { + if (ident.category.length() == 0) + { + return ident.name; + } + else + { + return ident.category + '#' + ident.name; + } + } + private static Properties _defaultProperties = null; } diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java index 2a8bb93da0c..f1c2501fc2b 100644 --- a/java/src/Ice/_ObjectDelM.java +++ b/java/src/Ice/_ObjectDelM.java @@ -126,6 +126,11 @@ public class _ObjectDelM implements _ObjectDel } } } + // + // We allow secure connections also if they are not explicitly + // required. + // + /* else { java.util.ListIterator i = endpoints.listIterator(); @@ -138,9 +143,10 @@ public class _ObjectDelM implements _ObjectDel } } } + */ final int sz = endpoints.size(); - if (endpoints.isEmpty()) + if (sz == 0) { throw new NoEndpointException(); } diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index cbc42edcc78..7674edeec09 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -32,12 +32,6 @@ public class BasicStream finalize() throws Throwable { - // - // No check for exactly one, because an error might have aborted - // marshalling/unmarshalling - // - assert(_encapsStack.size() > 0); - _bufferManager.reclaim(_buf); super.finalize(); diff --git a/java/src/IceInternal/Emitter.java b/java/src/IceInternal/Emitter.java index ad6f32e6347..10e4d414dc0 100644 --- a/java/src/IceInternal/Emitter.java +++ b/java/src/IceInternal/Emitter.java @@ -222,7 +222,7 @@ public final class Emitter extends EventHandler public boolean server() { - return true; + return false; } public boolean @@ -247,6 +247,7 @@ public final class Emitter extends EventHandler if (_state != StateActive) { + Thread.yield(); return; } @@ -340,6 +341,7 @@ public final class Emitter extends EventHandler _mutex.lock(); try { + assert(_state == StateClosed); _transceiver.close(); } finally @@ -415,14 +417,14 @@ public final class Emitter extends EventHandler { case StateActive: { - return; // Can't switch back to holding state + return; } case StateClosed: { if (_threadPool != null) { - _threadPool.unregister(_transceiver.fd()); + _threadPool.unregister(_transceiver.fd(), true); } else { diff --git a/java/src/IceInternal/EmitterFactory.java b/java/src/IceInternal/EmitterFactory.java index 103eb8ddf49..5f08f7b1cdf 100644 --- a/java/src/IceInternal/EmitterFactory.java +++ b/java/src/IceInternal/EmitterFactory.java @@ -56,11 +56,10 @@ public final class EmitterFactory { try { - Transceiver transceiver = - endpoints[i].clientTransceiver(_instance); + Transceiver transceiver = endpoints[i].clientTransceiver(); if (transceiver == null) { - Connector connector = endpoints[i].connector(_instance); + Connector connector = endpoints[i].connector(); assert(connector != null); transceiver = connector.connect(endpoints[i].timeout()); assert(transceiver != null); diff --git a/java/src/IceInternal/Endpoint.java b/java/src/IceInternal/Endpoint.java index e4ee5bb6d45..18e4cd02743 100644 --- a/java/src/IceInternal/Endpoint.java +++ b/java/src/IceInternal/Endpoint.java @@ -26,7 +26,7 @@ public abstract class Endpoint // Create an endpoint from a string // public static Endpoint - endpointFromString(String str) + endpointFromString(Instance instance, String str) { String s = str.trim(); if (s.length() == 0) @@ -40,21 +40,27 @@ public abstract class Endpoint boolean b = m.find(); assert(b); - String type = s.substring(0, m.start()); - if (type.equals("tcp")) + String protocol = s.substring(0, m.start()); + + if (protocol.equals("default")) + { + protocol = instance.defaultProtocol(); + } + + if (protocol.equals("tcp")) { - return new TcpEndpoint(s.substring(m.end())); + return new TcpEndpoint(instance, s.substring(m.end())); } - if (type.equals("ssl")) + if (protocol.equals("ssl")) { // TODO: SSL - //return new SslEndpoint(s.substring(m.end())); + //return new SslEndpoint(instance, s.substring(m.end())); } - if (type.equals("udp")) + if (protocol.equals("udp")) { - return new UdpEndpoint(s.substring(m.end())); + return new UdpEndpoint(instance, s.substring(m.end())); } throw new Ice.EndpointParseException(); @@ -148,7 +154,7 @@ public abstract class Endpoint // Return a client side transceiver for this endpoint, or null if a // transceiver can only be created by a connector. // - public abstract Transceiver clientTransceiver(Instance instance); + public abstract Transceiver clientTransceiver(); // // Return a server side transceiver for this endpoint, or null if a @@ -157,14 +163,13 @@ public abstract class Endpoint // "effective" endpoint, which might differ from this endpoint, // for example, if a dynamic port number is assigned. // - public abstract Transceiver serverTransceiver(Instance instance, - EndpointHolder endpoint); + public abstract Transceiver serverTransceiver(EndpointHolder endpoint); // // Return a connector for this endpoint, or null if no connector // is available. // - public abstract Connector connector(Instance instance); + public abstract Connector connector(); // // Return an acceptor for this endpoint, or null if no acceptors @@ -173,8 +178,7 @@ public abstract class Endpoint // from this endpoint, for example, if a dynamic port number is // assigned. // - public abstract Acceptor acceptor(Instance instance, - EndpointHolder endpoint); + public abstract Acceptor acceptor(EndpointHolder endpoint); // // Check whether the endpoint is equivalent to a specific diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index e9c54160442..8fe67b55c71 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -80,6 +80,20 @@ public class Instance return _threadPool; } + public String + defaultProtocol() + { + // No synchronization necessary + return _defaultProtocol; + } + + public String + defaultHost() + { + // No synchronization necessary + return _defaultHost; + } + public synchronized BufferManager bufferManager() { @@ -107,6 +121,16 @@ public class Instance _objectAdapterFactory = new ObjectAdapterFactory(this); */ _threadPool = new ThreadPool(this); + _defaultProtocol = _properties.getProperty("Ice.DefaultProtocol"); + if (_defaultProtocol == null) + { + _defaultProtocol = "tcp"; + } + _defaultHost = _properties.getProperty("Ice.DefaultHost"); + if (_defaultHost == null) + { + _defaultHost = Network.getLocalHost(true); + } _bufferManager = new BufferManager(); } catch (Ice.LocalException ex) @@ -235,5 +259,7 @@ public class Instance private ObjectAdapterFactory _objectAdapterFactory; */ private ThreadPool _threadPool; + private String _defaultProtocol; + private String _defaultHost; private BufferManager _bufferManager; } diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java index 9fb47f07e54..2f373e46323 100644 --- a/java/src/IceInternal/Outgoing.java +++ b/java/src/IceInternal/Outgoing.java @@ -49,7 +49,7 @@ public final class Outgoing } else { - _os.writeString(_reference.identity); + _reference.identity.__write(_os); _os.writeString(_reference.facet); } _os.writeString(operation); @@ -123,9 +123,9 @@ public final class Outgoing wait(timeout); if (_state == StateInProgress) { + timedOut = true; _state = StateLocalException; _exception = new Ice.TimeoutException(); - timedOut = true; } } else @@ -139,17 +139,17 @@ public final class Outgoing } } - if (_exception != null) + if (timedOut) { - if (timedOut) - { - // - // Must be called outside the synchronization of - // this object - // - _emitter.exception(_exception); - } + // + // Must be called outside the synchronization of + // this object + // + _emitter.exception(_exception); + } + if (_exception != null) + { // // A CloseConnectionException indicates graceful // server shutdown, and is therefore always repeatable @@ -217,7 +217,6 @@ public final class Outgoing public synchronized void finished(BasicStream is) { - assert(_state != StateUnsent); if (_state == StateInProgress) { _is.swap(is); @@ -310,7 +309,6 @@ public final class Outgoing public synchronized void finished(Ice.LocalException ex) { - assert(_state != StateUnsent); if (_state == StateInProgress) { _state = StateLocalException; diff --git a/java/src/IceInternal/ProxyFactory.java b/java/src/IceInternal/ProxyFactory.java index 341491b58f8..cf718960e66 100644 --- a/java/src/IceInternal/ProxyFactory.java +++ b/java/src/IceInternal/ProxyFactory.java @@ -29,15 +29,16 @@ public final class ProxyFactory public Ice.ObjectPrx streamToProxy(BasicStream s) { - String identity = s.readString(); + Ice.Identity ident = new Ice.Identity(); + ident.__read(s); - if (identity.length() == 0) + if (ident.name.length() == 0) { return null; } else { - Reference reference = new Reference(identity, s); + Reference reference = new Reference(ident, s); return referenceToProxy(reference); } } @@ -57,12 +58,15 @@ public final class ProxyFactory { Ice.ObjectPrxHelper h = (Ice.ObjectPrxHelper)proxy; Reference ref = h.__reference(); - s.writeString(ref.identity); + ref.identity.__write(s); ref.streamWrite(s); } else { - s.writeString(""); + Ice.Identity ident = new Ice.Identity(); + ident.name = ""; + ident.category = ""; + ident.__write(s); } } diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java index dd347107b35..7b5918234c0 100644 --- a/java/src/IceInternal/Reference.java +++ b/java/src/IceInternal/Reference.java @@ -20,8 +20,8 @@ public final class Reference public final static int ModeBatchLast = ModeBatchDatagram; public - Reference(Instance inst, String ident, String fac, int md, boolean sec, - Endpoint[] origEndpts, Endpoint[] endpts) + Reference(Instance inst, Ice.Identity ident, String fac, int md, + boolean sec, Endpoint[] origEndpts, Endpoint[] endpts) { instance = inst; identity = ident; @@ -62,7 +62,7 @@ public final class Reference } String[] arr = init.split("[ \t\n\r]+"); - identity = arr[0]; + identity = Ice.Util.stringToIdentity(arr[0]); int i = 1; while (i < arr.length) @@ -197,7 +197,7 @@ public final class Reference } String es = s.substring(beg, end); - Endpoint endp = Endpoint.endpointFromString(es); + Endpoint endp = Endpoint.endpointFromString(instance, es); if (orig) { @@ -231,7 +231,7 @@ public final class Reference } public - Reference(String ident, BasicStream s) + Reference(Ice.Identity ident, BasicStream s) { instance = s.instance(); identity = ident; @@ -289,7 +289,12 @@ public final class Reference return true; } - if (!identity.equals(r.identity)) + if (!identity.category.equals(r.identity.category)) + { + return false; + } + + if (!identity.name.equals(r.identity.name)) { return false; } @@ -392,7 +397,7 @@ public final class Reference // All members are treated as const, because References are immutable. // public Instance instance; - public String identity; + public Ice.Identity identity; public String facet; public int mode; public boolean secure; @@ -405,7 +410,7 @@ public final class Reference // certain values. // public Reference - changeIdentity(String newIdentity) + changeIdentity(Ice.Identity newIdentity) { if (newIdentity.equals(identity)) { @@ -505,10 +510,16 @@ public final class Reference { int h = 0; - int sz = identity.length(); + int sz = identity.name.length(); + for (int i = 0; i < sz; i++) + { + h = 5 * h + (int)identity.name.charAt(i); + } + + sz = identity.category.length(); for (int i = 0; i < sz; i++) { - h = 5 * h + (int)identity.charAt(i); + h = 5 * h + (int)identity.category.charAt(i); } sz = facet.length(); diff --git a/java/src/IceInternal/TcpEndpoint.java b/java/src/IceInternal/TcpEndpoint.java index 7e67a2f915d..4cd2bb72bec 100644 --- a/java/src/IceInternal/TcpEndpoint.java +++ b/java/src/IceInternal/TcpEndpoint.java @@ -13,16 +13,18 @@ package IceInternal; public final class TcpEndpoint extends Endpoint { public - TcpEndpoint(String ho, int po, int ti) + TcpEndpoint(Instance instance, String ho, int po, int ti) { + _instance = instance; _host = ho; _port = po; _timeout = ti; } public - TcpEndpoint(String str) + TcpEndpoint(Instance instance, String str) { + _instance = instance; _host = null; _port = 0; _timeout = -1; @@ -104,14 +106,14 @@ public final class TcpEndpoint extends Endpoint if (_host == null) { - // TODO: Whether numeric or not should be configurable - _host = Network.getLocalHost(true); + _host = _instance.defaultHost(); } } public TcpEndpoint(BasicStream s) { + _instance = s.instance(); s.startReadEncaps(); _host = s.readString(); _port = s.readInt(); @@ -139,22 +141,7 @@ public final class TcpEndpoint extends Endpoint public String toString() { - StringBuffer s = new StringBuffer(); - s.append("tcp"); - // TODO: Whether numeric or not should be configurable - if (!_host.equals(Network.getLocalHost(true))) - { - s.append(" -h " + _host); - } - if (_port != 0) - { - s.append(" -p " + _port); - } - if (_timeout != -1) - { - s.append(" -t " + _timeout); - } - return s.toString(); + return "tcp -h " + _host + " -p " + _port + " -t " + _timeout; } // @@ -199,7 +186,7 @@ public final class TcpEndpoint extends Endpoint } else { - return new TcpEndpoint(_host, _port, timeout); + return new TcpEndpoint(_instance, _host, _port, timeout); } } @@ -226,7 +213,7 @@ public final class TcpEndpoint extends Endpoint // transceiver can only be created by a connector. // public Transceiver - clientTransceiver(Instance instance) + clientTransceiver() { return null; } @@ -239,9 +226,9 @@ public final class TcpEndpoint extends Endpoint // for example, if a dynamic port number is assigned. // public Transceiver - serverTransceiver(Instance instance, EndpointHolder endpoint) + serverTransceiver(EndpointHolder endpoint) { - endpoint.value = null; + endpoint.value = this; return null; } @@ -250,9 +237,9 @@ public final class TcpEndpoint extends Endpoint // is available. // public Connector - connector(Instance instance) + connector() { - return new TcpConnector(instance, _host, _port); + return new TcpConnector(_instance, _host, _port); } // @@ -263,11 +250,12 @@ public final class TcpEndpoint extends Endpoint // assigned. // public Acceptor - acceptor(Instance instance, EndpointHolder endpoint) + acceptor(EndpointHolder endpoint) { /* TODO - implement - TcpAcceptor p = new TcpAcceptor(instance, _port); - endpoint.value = new TcpEndpoint(_host, p.effectivePort(), _timeout); + TcpAcceptor p = new TcpAcceptor(_instance, _port); + endpoint.value = new TcpEndpoint(_instance, _host, p.effectivePort(), + _timeout); return p; */ return null; @@ -355,6 +343,7 @@ public final class TcpEndpoint extends Endpoint return true; } + private Instance _instance; private String _host; private int _port; private int _timeout; diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index 4f94f9ee2cf..e575d92ca71 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -19,15 +19,21 @@ public final class ThreadPool { ++_servers; } - _adds.add(new HandlerInfo(fd, handler)); + HandlerInfo info = new HandlerInfo(fd, handler); + info.next = _adds; + _adds = info; setInterrupt(); } public synchronized void - unregister(java.nio.channels.SelectableChannel fd) + unregister(java.nio.channels.SelectableChannel fd, boolean callFinished) { java.nio.channels.SelectionKey key = fd.keyFor(_selector); - _removes.add(key); + HandlerInfo info = (HandlerInfo)key.attachment(); + assert(info != null); + info.callFinished = callFinished; + info.next = _removes; + _removes = info; setInterrupt(); } @@ -42,13 +48,13 @@ public final class ThreadPool { assert(!_shutdown); _shutdown = true; - setInterrupt(); + setInterrupt(); // TODO: just use wakeup? } public synchronized void waitUntilServerFinished() { - while (_servers > 0 && _threadNum > 0) + while (_servers != 0 && _threadNum != 0) { try { @@ -59,7 +65,7 @@ public final class ThreadPool } } - if (_servers > 0) + if (_servers != 0) { _instance.logger().error("can't wait for graceful server " + "termination in thread pool\n" + @@ -70,7 +76,7 @@ public final class ThreadPool public synchronized void waitUntilFinished() { - while (_handlers > 0 && _threadNum > 0) + while (_handlers != 0 && _threadNum != 0) { try { @@ -81,7 +87,7 @@ public final class ThreadPool } } - if (_handlers > 0) + if (_handlers != 0) { _instance.logger().error("can't wait for graceful application " + "termination in thread pool\n" + @@ -142,6 +148,8 @@ public final class ThreadPool _destroyed = false; _interrupted = false; _shutdown = false; + _adds = null; + _removes = null; _handlers = 0; _servers = 0; _timeout = 0; @@ -278,9 +286,6 @@ public final class ThreadPool { _threadMutex.lock(); - EventHandler handler = null; - boolean reap = false; - repeatSelect: while (true) @@ -318,6 +323,8 @@ public final class ThreadPool continue repeatSelect; } + EventHandler handler = null; + synchronized(this) { if (_destroyed) @@ -330,26 +337,18 @@ public final class ThreadPool return; } - boolean interrupt = _interrupted; - if (interrupt) - { - shutdown = clearInterrupt(); - } - - if (!_adds.isEmpty()) + if (_adds != null) { // // New handlers have been added. // - java.util.ListIterator p = _adds.listIterator(); - while (p.hasNext()) + HandlerInfo info = _adds; + while (info != null) { - HandlerInfo info = (HandlerInfo)p.next(); - addHandler(info); _handlers++; try { - info.fd.register( + info.key = info.fd.register( _selector, java.nio.channels.SelectionKey.OP_READ, info); @@ -358,152 +357,106 @@ public final class ThreadPool { assert(false); } + HandlerInfo next = info.next; + info.next = null; + info = next; } - _adds.clear(); + _adds = null; } - if (!_removes.isEmpty()) + if (_removes != null) { // // Handlers are permanently removed. // - java.util.ListIterator p = _removes.listIterator(); - while (p.hasNext()) + HandlerInfo info = _removes; + while (info != null) { - java.nio.channels.SelectionKey key = - (java.nio.channels.SelectionKey)p.next(); - key.cancel(); - HandlerInfo info = (HandlerInfo)key.attachment(); - assert(info != null); - info.handler.finished(); + info.key.cancel(); + if (info.callFinished) + { + info.handler.finished(); + } if (info.handler.server()) { --_servers; } - _handlers--; - removeHandler(info); + info = info.next; } - _removes.clear(); + _removes = null; if (_handlers == 0 || _servers == 0) { notifyAll(); // For waitUntil...Finished() methods. } + + // + // Selected filedescriptors may have changed, I + // therefore need to repeat the select(). + // + shutdown = clearInterrupt(); + continue repeatSelect; } - if (interrupt) + java.util.Set keys = _selector.selectedKeys(); + if (keys.size() == 0) { + shutdown = clearInterrupt(); continue repeatSelect; } - // - // Check if there are connections to reap. - // - reap = false; - if (_maxConnections > 0 && _handlers > _maxConnections) + java.util.Iterator i = keys.iterator(); + while (i.hasNext()) { - HandlerInfo info = _reapListEnd; - while (info != null) + java.nio.channels.SelectionKey key = + (java.nio.channels.SelectionKey)i.next(); + // + // Ignore selection keys that have been + // cancelled + // + if (key.isValid()) { - if (!info.reaped) - { - info.reaped = true; - handler = info.handler; - reap = true; - break; - } - info = info.prev; + HandlerInfo info = + (HandlerInfo)key.attachment(); + assert(info != null); + handler = info.handler; + break; } } - if (!reap) + if (handler == null) { - java.util.Set keys = _selector.selectedKeys(); - java.util.Iterator i = keys.iterator(); - while (i.hasNext()) - { - java.nio.channels.SelectionKey key = - (java.nio.channels.SelectionKey)i.next(); - // - // Ignore selection keys that have been - // cancelled - // - if (key.isValid()) - { - HandlerInfo info = - (HandlerInfo)key.attachment(); - assert(info != null); - - // - // Make the fd for the handler the most - // recently used one by moving it to the - // beginning of the the reap list. - // - if (info != _reapList) - { - removeHandler(info); - addHandler(info); - } - - handler = info.handler; - break; - } - } - - if (handler == null) - { - continue repeatSelect; - } + continue repeatSelect; } } - if (reap) + // + // If the handler is "readable", try to read a message. + // + BasicStream stream = new BasicStream(_instance); + if (handler.readable()) { - // - // Reap the handler. - // try { - if (!handler.tryDestroy()) - { - continue repeatSelect; - } + read(handler); } - catch (Ice.LocalException ex) + catch (Ice.TimeoutException ex) // Expected { - // Ignore exceptions. + continue repeatSelect; } - } - else - { - // - // If the handler is "readable", try to read a message. - // - BasicStream stream = new BasicStream(_instance); - if (handler.readable()) + catch (Ice.LocalException ex) { - try - { - read(handler); - } - catch (Ice.TimeoutException ex) // Expected - { - continue repeatSelect; - } - catch (Ice.LocalException ex) - { - handler.exception(ex); - continue repeatSelect; - } - - stream.swap(handler._stream); - assert(stream.pos() == stream.size()); + handler.exception(ex); + continue repeatSelect; } - handler.message(stream); + stream.swap(handler._stream); + assert(stream.pos() == stream.size()); } + handler.message(stream); + break; } } @@ -545,6 +498,10 @@ public final class ThreadPool } byte messageType = stream.readByte(); int size = stream.readInt(); + if (size < Protocol.headerSize) + { + throw new Ice.IllegalMessageSizeException(); + } if (size > 1024 * 1024) // TODO: Configurable { throw new Ice.MemoryLimitException(); @@ -560,42 +517,6 @@ public final class ThreadPool } } - private void - addHandler(HandlerInfo info) - { - info.next = _reapList; - info.prev = null; - if (_reapList != null) - { - _reapList.prev = info; - } - else - { - _reapListEnd = info; - } - _reapList = info; - } - - private void - removeHandler(HandlerInfo info) - { - // - // Remove from _reapList - // - if (info.prev == null) - { - _reapList = info.next; - } - else - { - info.prev.next = info.next; - } - if (info.next == null) - { - _reapListEnd = info.prev; - } - } - private static void dumpBuffer(java.nio.ByteBuffer buf) { @@ -646,9 +567,9 @@ public final class ThreadPool { java.nio.channels.SelectableChannel fd; EventHandler handler; - HandlerInfo prev; + java.nio.channels.SelectionKey key; HandlerInfo next; - boolean reaped; + boolean callFinished; HandlerInfo(java.nio.channels.SelectableChannel fd, EventHandler handler) @@ -663,11 +584,9 @@ public final class ThreadPool private java.nio.channels.Selector _selector; private boolean _interrupted; private boolean _shutdown; - private java.util.LinkedList _adds = new java.util.LinkedList(); - private java.util.LinkedList _removes = new java.util.LinkedList(); + private HandlerInfo _adds; + private HandlerInfo _removes; private int _handlers; - private HandlerInfo _reapList = null; - private HandlerInfo _reapListEnd = null; private int _servers; private int _timeout; private RecursiveMutex _threadMutex = new RecursiveMutex(); diff --git a/java/src/IceInternal/TraceUtil.java b/java/src/IceInternal/TraceUtil.java index 7c7dd191432..2ca8b5402ce 100644 --- a/java/src/IceInternal/TraceUtil.java +++ b/java/src/IceInternal/TraceUtil.java @@ -191,7 +191,7 @@ final class TraceUtil { try { - String identity = null; + Ice.Identity identity = null; String facet = null; boolean gotProxy = stream.readBool(); out.write("\naddressing = " + gotProxy); @@ -205,10 +205,11 @@ final class TraceUtil else { out.write(" (identity)"); - identity = stream.readString(); + identity = new Ice.Identity(); + identity.__read(stream); facet = stream.readString(); } - out.write("\nidentity = " + identity); + out.write("\nidentity = " + Ice.Util.identityToString(identity)); out.write("\nfacet = " + facet); String operation = stream.readString(); out.write("\noperation = " + operation); diff --git a/java/src/IceInternal/UdpEndpoint.java b/java/src/IceInternal/UdpEndpoint.java index c7f2dc65919..615256daa54 100644 --- a/java/src/IceInternal/UdpEndpoint.java +++ b/java/src/IceInternal/UdpEndpoint.java @@ -13,15 +13,17 @@ package IceInternal; public final class UdpEndpoint extends Endpoint { public - UdpEndpoint(String ho, int po) + UdpEndpoint(Instance instance, String ho, int po) { + _instance = instance; _host = ho; _port = po; } public - UdpEndpoint(String str) + UdpEndpoint(Instance instance, String str) { + _instance = instance; _host = null; _port = 0; @@ -83,14 +85,14 @@ public final class UdpEndpoint extends Endpoint if (_host == null) { - // TODO: Whether numeric or not should be configurable - _host = Network.getLocalHost(true); + _host = instance.defaultHost(); } } public UdpEndpoint(BasicStream s) { + _instance = s.instance(); s.startReadEncaps(); _host = s.readString(); _port = s.readInt(); @@ -116,18 +118,7 @@ public final class UdpEndpoint extends Endpoint public String toString() { - StringBuffer s = new StringBuffer(); - s.append("udp"); - // TODO: Whether numeric or not should be configurable - if (!_host.equals(Network.getLocalHost(true))) - { - s.append(" -h " + _host); - } - if (_port != 0) - { - s.append(" -p " + _port); - } - return s.toString(); + return "udp -h " + _host + " -p " + _port; } // @@ -192,9 +183,9 @@ public final class UdpEndpoint extends Endpoint // transceiver can only be created by a connector. // public Transceiver - clientTransceiver(Instance instance) + clientTransceiver() { - return new UdpTransceiver(instance, _host, _port); + return new UdpTransceiver(_instance, _host, _port); } // @@ -205,11 +196,11 @@ public final class UdpEndpoint extends Endpoint // for example, if a dynamic port number is assigned. // public Transceiver - serverTransceiver(Instance instance, EndpointHolder endpoint) + serverTransceiver(EndpointHolder endpoint) { /* TODO: Server - UdpTransceiver p = new UdpTransceiver(instance, _port); - endpoint.value = new UdpEndpoint(_host, p.effectivePort()); + UdpTransceiver p = new UdpTransceiver(_instance, _port); + endpoint.value = new UdpEndpoint(_instance, _host, p.effectivePort()); return p; */ return null; @@ -220,7 +211,7 @@ public final class UdpEndpoint extends Endpoint // is available. // public Connector - connector(Instance instance) + connector() { return null; } @@ -233,7 +224,7 @@ public final class UdpEndpoint extends Endpoint // assigned. // public Acceptor - acceptor(Instance instance, EndpointHolder endpoint) + acceptor(EndpointHolder endpoint) { endpoint.value = this; return null; @@ -313,6 +304,7 @@ public final class UdpEndpoint extends Endpoint return true; } + private Instance _instance; private String _host; private int _port; } diff --git a/java/src/IceInternal/UnknownEndpoint.java b/java/src/IceInternal/UnknownEndpoint.java index c670445895d..ad84c0b63c2 100644 --- a/java/src/IceInternal/UnknownEndpoint.java +++ b/java/src/IceInternal/UnknownEndpoint.java @@ -15,6 +15,7 @@ public final class UnknownEndpoint extends Endpoint public UnknownEndpoint(BasicStream s) { + _instance = s.instance(); _rawBytes = s.readByteSeq(); } @@ -99,7 +100,7 @@ public final class UnknownEndpoint extends Endpoint // transceiver can only be created by a connector. // public Transceiver - clientTransceiver(Instance instance) + clientTransceiver() { return null; } @@ -112,7 +113,7 @@ public final class UnknownEndpoint extends Endpoint // for example, if a dynamic port number is assigned. // public Transceiver - serverTransceiver(Instance instance, EndpointHolder endpoint) + serverTransceiver(EndpointHolder endpoint) { endpoint.value = null; return null; @@ -123,7 +124,7 @@ public final class UnknownEndpoint extends Endpoint // is available. // public Connector - connector(Instance instance) + connector() { return null; } @@ -136,7 +137,7 @@ public final class UnknownEndpoint extends Endpoint // assigned. // public Acceptor - acceptor(Instance instance, EndpointHolder endpoint) + acceptor(EndpointHolder endpoint) { endpoint.value = null; return null; @@ -188,5 +189,6 @@ public final class UnknownEndpoint extends Endpoint return true; } + private Instance _instance; private byte[] _rawBytes; } |