diff options
author | Mark Spruiell <mes@zeroc.com> | 2001-11-16 20:57:30 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2001-11-16 20:57:30 +0000 |
commit | 2ac5213d0c761977903dd75f39e7960a897281ea (patch) | |
tree | 6296bb8991ef7d4b079fe6365b2c897a1f7f721b /java/src | |
parent | minor fixes (diff) | |
download | ice-2ac5213d0c761977903dd75f39e7960a897281ea.tar.bz2 ice-2ac5213d0c761977903dd75f39e7960a897281ea.tar.xz ice-2ac5213d0c761977903dd75f39e7960a897281ea.zip |
intial check-in
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/IceInternal/Endpoint.java | 190 | ||||
-rw-r--r-- | java/src/IceInternal/EndpointHolder.java | 16 | ||||
-rw-r--r-- | java/src/IceInternal/EventHandler.java | 69 | ||||
-rw-r--r-- | java/src/IceInternal/Instance.java | 215 | ||||
-rw-r--r-- | java/src/IceInternal/Reference.java | 573 | ||||
-rw-r--r-- | java/src/IceInternal/TcpEndpoint.java | 355 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpoint.java | 315 | ||||
-rw-r--r-- | java/src/IceInternal/UnknownEndpoint.java | 192 |
8 files changed, 1925 insertions, 0 deletions
diff --git a/java/src/IceInternal/Endpoint.java b/java/src/IceInternal/Endpoint.java new file mode 100644 index 00000000000..ed2acf81c65 --- /dev/null +++ b/java/src/IceInternal/Endpoint.java @@ -0,0 +1,190 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public abstract class Endpoint +{ + public static final short UnknownEndpointType = 0; + public static final short TcpEndpointType = 1; + public static final short SslEndpointType = 2; + public static final short UdpEndpointType = 3; + + public + Endpoint() + { + } + + // + // Create an endpoint from a string + // + public static Endpoint + endpointFromString(String str) + { + String s = str.trim(); + if (s.length() == 0) + { + throw new Ice.EndpointParseException(); + } + + java.util.regex.Pattern p = + java.util.regex.Pattern.compile("([ \t\n\r]+)|$"); + java.util.regex.Matcher m = p.matcher(s); + boolean b = m.find(); + assert(b); + + String type = s.substring(0, m.start()); + if (type.equals("tcp")) + { + return new TcpEndpoint(s.substring(m.end() + 1)); + } + + if (type.equals("ssl")) + { + // TODO: SSL + //return new SslEndpoint(s.substring(m.end() + 1)); + } + + if (type.equals("udp")) + { + return new UdpEndpoint(s.substring(m.end() + 1)); + } + + throw new Ice.EndpointParseException(); + } + + // + // Unmarshal an endpoint + // + public static Endpoint + streamRead(Ice.Stream s) + { + Endpoint v; + short type = s.readShort(); + + switch (type) + { + case TcpEndpointType: + { + v = new TcpEndpoint(s); + break; + } + + case SslEndpointType: + { + // TODO: SSL + //v = new SslEndpoint(s); + v = null; + break; + } + + case UdpEndpointType: + { + v = new UdpEndpoint(s); + break; + } + + default: + { + v = new UnknownEndpoint(s); + break; + } + } + + return v; + } + + // + // Marshal the endpoint + // + public abstract void streamWrite(Ice.Stream s); + + // + // Convert the endpoint to its string form + // + public abstract String toString(); + + // + // Return the endpoint type + // + public abstract short type(); + + // + // Return true if the endpoint only supports oneway operations. + // + public abstract boolean oneway(); + + // + // Return the timeout for the endpoint in milliseconds. 0 means + // non-blocking, -1 means no timeout. + // + public abstract int 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 abstract Endpoint timeout(int t); + + // + // Return true if the endpoint is datagram-based. + // + public abstract boolean datagram(); + + // + // Return true if the endpoint is secure. + // + public abstract boolean secure(); + + // + // 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); + + // + // 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 abstract Transceiver serverTransceiver(Instance instance, + EndpointHolder endpoint); + + // + // Return a connector for this endpoint, or null if no connector + // is available. + // + public abstract Connector connector(Instance instance); + + // + // Return an acceptor for this endpoint, or null if no acceptors + // is available. In case an acceptor 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 abstract Acceptor acceptor(Instance instance, + EndpointHolder endpoint); + + // + // Check whether the endpoint is equivalent to a specific + // Transceiver or Acceptor + // + public abstract boolean equivalent(Transceiver transceiver); + public abstract boolean equivalent(Acceptor acceptor); + + // + // Compare endpoints for sorting purposes + // + public abstract boolean equals(java.lang.Object obj); +} diff --git a/java/src/IceInternal/EndpointHolder.java b/java/src/IceInternal/EndpointHolder.java new file mode 100644 index 00000000000..8ef52c28a2d --- /dev/null +++ b/java/src/IceInternal/EndpointHolder.java @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class EndpointHolder +{ + public Endpoint value; +} diff --git a/java/src/IceInternal/EventHandler.java b/java/src/IceInternal/EventHandler.java new file mode 100644 index 00000000000..e9c9f3d352c --- /dev/null +++ b/java/src/IceInternal/EventHandler.java @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +abstract class EventHandler +{ + // + // Returns true if the event handler belongs to the server-side of + // an application. Client-side otherwise. + // + abstract boolean server(); + + // + // Return true if read() must be called before calling message(). + // + abstract boolean readable(); + + // + // Read data via the event handler. May only be called if + // readable() returns true. + // + abstract void read(Ice.Stream is); + + // + // A complete message has been received. + // + abstract void message(Ice.Stream stream); + + // + // Signal exception during reading or unmarshaling. + // + abstract void exception(Ice.LocalException ex); + + // + // Will be called if the event handler is finally + // unregistered. (Calling unregister() does not unregister + // immediately.) + // + abstract void finished(); + + // + // Try to destroy the event handler. Returns false if the event + // handler cannot be destroyed because it is in use, or true + // otherwise. + // + abstract boolean tryDestroy(); + + protected + EventHandler(Instance instance) + { + _instance = instance; + _stream = new StreamI(instance); + } + + protected Instance _instance; + + // + // The _stream data member is for use by ThreadPool only + // + Ice.Stream _stream; +} diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java new file mode 100644 index 00000000000..3d91d3fa49d --- /dev/null +++ b/java/src/IceInternal/Instance.java @@ -0,0 +1,215 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public class Instance +{ + public synchronized Ice.Communicator + communicator() + { + return _communicator; + } + + public synchronized Ice.Properties + properties() + { + return _properties; + } + + public synchronized Ice.Logger + logger() + { + return _logger; + } + + public synchronized void + logger(Ice.Logger logger) + { + _logger = logger; + } + + public synchronized TraceLevels + traceLevels() + { + return _traceLevels; + } + + public synchronized ProxyFactory + proxyFactory() + { + return _proxyFactory; + } + + public synchronized EmitterFactory + emitterFactory() + { + return _emitterFactory; + } + + public synchronized ObjectFactoryManager + servantFactoryManager() + { + return _servantFactoryManager; + } + + public synchronized UserExceptionFactoryManager + userExceptionFactoryManager() + { + return _userExceptionFactoryManager; + } + + public synchronized ObjectAdapterFactory + objectAdapterFactory() + { + return _objectAdapterFactory; + } + + public synchronized ThreadPool + threadPool() + { + return _threadPool; + } + + // + // Only for use by Ice.CommunicatorI + // + public + Instance(Ice.Communicator communicator, Ice.Properties properties) + { + _communicator = communicator; + _properties = properties; + + try + { + _logger = new Ice.LoggerI(); + _traceLevels = new TraceLevels(_properties); + _proxyFactory = new ProxyFactory(this); + _emitterFactory = new EmitterFactory(this); + _servantFactoryManager = new ObjectFactoryManager(); + _userExceptionFactoryManager = new UserExceptionFactoryManager(); + _objectAdapterFactory = new ObjectAdapterFactory(this); + _threadPool = new ThreadPool(this); + } + catch (Ice.LocalException ex) + { + destroy(); + throw ex; + } + } + + protected void + finalize() + throws Throwable + { + assert(_communicator == null); + assert(_properties == null); + assert(_logger == null); + assert(_traceLevels == null); + assert(_proxyFactory == null); + assert(_emitterFactory == null); + assert(_servantFactoryManager == null); + assert(_userExceptionFactoryManager == null); + assert(_objectAdapterFactory == null); + assert(_threadPool == null); + + super.finalize(); + } + + // + // Only for use by Ice.CommunicatorI + // + public synchronized void + destroy() + { + // + // Destroy all contained objects. Then set all references to null, + // to avoid cyclic object dependencies. + // + + if (_communicator != null) + { + // Don't destroy the communicator -- the communicator destroys + // this object, not the other way + _communicator = null; + } + + if (_properties != null) + { + // No destroy function defined + // _properties.destroy(); + _properties = null; + } + + if (_logger != null) + { + _logger.destroy(); + _logger = null; + } + + if (_traceLevels != null) + { + // No destroy function defined + // _traceLevels.destroy(); + _traceLevels = null; + } + + if (_proxyFactory != null) + { + // No destroy function defined + // _proxyFactory.destroy(); + _proxyFactory = null; + } + + if (_emitterFactory != null) + { + _emitterFactory.destroy(); + _emitterFactory = null; + } + + if (_servantFactoryManager != null) + { + _servantFactoryManager.destroy(); + _servantFactoryManager = null; + } + + if (_userExceptionFactoryManager != null) + { + _userExceptionFactoryManager.destroy(); + _userExceptionFactoryManager = null; + } + + if (_objectAdapterFactory != null) + { + _objectAdapterFactory.shutdown(); // ObjectAdapterFactory has + // shutdown(), not destroy() + _objectAdapterFactory = null; + } + + if (_threadPool != null) + { + _threadPool.waitUntilFinished(); + _threadPool.destroy(); + _threadPool.joinWithAllThreads(); + _threadPool = null; + } + } + + private Ice.Communicator _communicator; + private Ice.Properties _properties; + private Ice.Logger _logger; + private TraceLevels _traceLevels; + private ProxyFactory _proxyFactory; + private EmitterFactory _emitterFactory; + private ObjectFactoryManager _servantFactoryManager; + private UserExceptionFactoryManager _userExceptionFactoryManager; + private ObjectAdapterFactory _objectAdapterFactory; + private ThreadPool _threadPool; +} diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java new file mode 100644 index 00000000000..8a74cd81c10 --- /dev/null +++ b/java/src/IceInternal/Reference.java @@ -0,0 +1,573 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class Reference +{ + public final static int ModeTwoway = 0; + public final static int ModeOneway = 1; + public final static int ModeBatchOneway = 2; + public final static int ModeDatagram = 3; + public final static int ModeBatchDatagram = 4; + public final static int ModeBatchLast = ModeBatchDatagram; + + public + Reference(Instance inst, String ident, String fac, int md, boolean sec, + Endpoint[] origEndpts, Endpoint[] endpts) + { + instance = inst; + identity = ident; + facet = fac; + mode = md; + secure = sec; + origEndpoints = origEndpts; + endpoints = endpts; + hashValue = 0; + + calcHashValue(); + } + + public + Reference(Instance inst, String str) + { + instance = inst; + mode = ModeTwoway; + secure = false; + hashValue = 0; + + String s = str.trim(); + if (s.length() == 0) + { + throw new Ice.ReferenceParseException(); + } + + int colon = s.indexOf(':'); + String init; + if (colon == -1) + { + init = s; + } + else + { + init = s.substring(0, colon); + } + + String[] arr = init.split("[ \t\n\r]+"); + String identity = arr[0]; + + int i = 1; + while (i < arr.length) + { + String option = arr[i++]; + if (option.length() != 2 || option.charAt(0) != '-') + { + throw new Ice.ReferenceParseException(); + } + + String argument = null; + if (i < arr.length && arr[i].charAt(0) != '-') + { + argument = arr[i++]; + } + + switch (option.charAt(1)) + { + case 'f': + { + if (argument == null) + { + throw new Ice.EndpointParseException(); + } + + facet = argument; + break; + } + + case 't': + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + mode = ModeTwoway; + break; + } + + case 'o': + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + mode = ModeOneway; + break; + } + + case 'O': + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + mode = ModeBatchOneway; + break; + } + + case 'd': + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + mode = ModeDatagram; + break; + } + + case 'D': + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + mode = ModeBatchDatagram; + break; + } + + case 's': + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + secure = true; + break; + } + + default: + { + if (argument != null) + { + throw new Ice.EndpointParseException(); + } + + throw new Ice.ReferenceParseException(); + } + } + } + + java.util.LinkedList origEndpointList = new java.util.LinkedList(); + java.util.LinkedList endpointList = new java.util.LinkedList(); + boolean orig = true; + final int len = s.length(); + int end = colon; + while (end < len && s.charAt(end) == ':') + { + int beg = end + 1; + + end = s.indexOf(':', beg); + if (end == -1) + { + end = len; + } + + if (beg == end) // "::" + { + if (!orig) + { + throw new Ice.ReferenceParseException(); + } + + orig = false; + continue; + } + + String es = s.substring(beg, end); + Endpoint endp = Endpoint.endpointFromString(es); + + if (orig) + { + origEndpointList.add(endp); + } + else + { + endpointList.add(endp); + } + } + + origEndpoints = new Endpoint[origEndpointList.size()]; + origEndpointList.toArray(origEndpoints); + + if (orig) + { + endpoints = origEndpoints; + } + else + { + endpoints = new Endpoint[endpointList.size()]; + endpointList.toArray(endpoints); + } + + if (origEndpoints.length == 0 || endpoints.length == 0) + { + throw new Ice.ReferenceParseException(); + } + + calcHashValue(); + } + + public + Reference(String ident, Ice.Stream s) + { + instance = s.instance(); + identity = ident; + mode = ModeTwoway; + secure = false; + hashValue = 0; + + // + // Don't read the identity here. Operations calling this + // constructor read the identity, and pass it as a parameter. + // + + facet = s.readString(); + + mode = (int)s.readByte(); + if (mode < 0 || mode > ModeBatchLast) + { + throw new Ice.ProxyUnmarshalException(); + } + + secure = s.readBoolean(); + + int sz = s.readInt(); + origEndpoints = new Endpoint[sz]; + for (int i = 0; i < sz; i++) + { + origEndpoints[i] = Endpoint.streamRead(s); + } + + boolean same = s.readBoolean(); + if (same) // origEndpoints == endpoints + { + endpoints = origEndpoints; + } + else + { + sz = s.readInt(); + endpoints = new Endpoint[sz]; + for (int i = 0; i < sz; i++) + { + endpoints[i] = Endpoint.streamRead(s); + } + } + + calcHashValue(); + } + + public boolean + equals(java.lang.Object obj) + { + Reference r = (Reference)obj; + + if (this == r) + { + return true; + } + + if (!identity.equals(r.identity)) + { + return false; + } + + if (facet != null && !facet.equals(r.facet)) + { + return false; + } + + if (mode != r.mode) + { + return false; + } + + if (secure != r.secure) + { + return false; + } + + if (!compare(origEndpoints, r.origEndpoints)) + { + return false; + } + + if (!compare(endpoints, r.endpoints)) + { + return false; + } + + return true; + } + + // + // Marshal the reference + // + public void + streamWrite(Ice.Stream s) + { + // + // Don't write the identity here. Operations calling streamWrite + // write the identity. + // + + s.writeString(facet); + + s.writeByte((byte)mode); + + s.writeBoolean(secure); + + s.writeInt(origEndpoints.length); + for (int i = 0; i < origEndpoints.length; i++) + { + origEndpoints[i].streamWrite(s); + } + + if (endpointsEqual()) + { + s.writeBoolean(true); + } + else + { + s.writeBoolean(false); + s.writeInt(endpoints.length); + for (int i = 0; i < endpoints.length; i++) + { + endpoints[i].streamWrite(s); + } + } + } + + // + // Convert the reference to its string form + // + public String + toString() + { + StringBuffer s = new StringBuffer(); + s.append(identity); + + for (int i = 0; i < origEndpoints.length; i++) + { + s.append(':'); + s.append(origEndpoints[i].toString()); + } + + if (!endpointsEqual()) + { + s.append(':'); + for (int i = 0; i < endpoints.length; i++) + { + s.append(':'); + s.append(endpoints[i].toString()); + } + } + + return s.toString(); + } + + // + // All members are treated as const, because References are immutable. + // + public Instance instance; + public String identity; + public String facet; + public int mode; + public boolean secure; + public Endpoint[] origEndpoints; // Original endpoints + public Endpoint[] endpoints; // Actual endpoints (set by a loc fwd) + public int hashValue; + + // + // Get a new reference, based on the existing one, overwriting + // certain values. + // + public Reference + changeIdentity(String newIdentity) + { + if (newIdentity.equals(identity)) + { + return this; + } + else + { + return new Reference(instance, newIdentity, facet, mode, secure, + origEndpoints, endpoints); + } + } + + public Reference + changeFacet(String newFacet) + { + if (newFacet.equals(facet)) + { + return this; + } + else + { + return new Reference(instance, identity, newFacet, mode, secure, + origEndpoints, endpoints); + } + } + + public Reference + changeTimeout(int timeout) + { + Endpoint[] newOrigEndpoints = new Endpoint[origEndpoints.length]; + for (int i = 0; i < origEndpoints.length; i++) + { + newOrigEndpoints[i] = origEndpoints[i].timeout(timeout); + } + + Endpoint[] newEndpoints = new Endpoint[endpoints.length]; + for (int i = 0; i < endpoints.length; i++) + { + newEndpoints[i] = endpoints[i].timeout(timeout); + } + + Reference ref = new Reference(instance, identity, facet, mode, secure, + newOrigEndpoints, newEndpoints); + + if (ref.equals(this)) + { + return this; + } + + return ref; + } + + public Reference + changeMode(int newMode) + { + if (newMode == mode) + { + return this; + } + else + { + return new Reference(instance, identity, facet, newMode, secure, + origEndpoints, endpoints); + } + } + + public Reference + changeSecure(boolean newSecure) + { + if (newSecure == secure) + { + return this; + } + else + { + return new Reference(instance, identity, facet, mode, newSecure, + origEndpoints, endpoints); + } + } + + public Reference + changeEndpoints(Endpoint[] newEndpoints) + { + if (compare(newEndpoints, endpoints)) + { + return this; + } + else + { + return new Reference(instance, identity, facet, mode, newSecure, + origEndpoints, newEndpoints); + } + } + + private void + calcHashValue() + { + int h = 0; + + int sz = identity.size(); + for (int i = 0; i < sz; i++) + { + h = 5 * h + (int)identity.charAt(i); + } + + sz = facet.size(); + for (int i = 0; i < sz; i++) + { + h = 5 * h + (int)facet.charAt(i); + } + + h = 5 * h + mode; + + h = 5 * h + (secure ? 1 : 0); + + // + // TODO: Should we also take the endpoints into account for hash + // calculation? Perhaps not, the code above should be good enough + // for a good hash value. + // + + hashValue = h; + } + + // + // Check if origEndpoints == endpoints + // + private boolean + endpointsEqual() + { + if (_checkEndpointsEqual) + { + _endpointsEqual = compare(origEndpoints, endpoints); + _checkEndpointEqual = false; + } + + return _endpointEqual; + } + + private boolean + compare(Endpoint[] arr1, Endpoint[] arr2) + { + if (arr1 == arr2) + { + return true; + } + + if (arr1.length == arr2.length) + { + for (int i = 0; i < arr1.length; i++) + { + if (!arr1[i].equals(arr2[i])) + { + return false; + } + } + + return true; + } + + return false; + } + + private boolean _endpointsEqual = false; + private boolean _checkEndpointsEqual = true; +} diff --git a/java/src/IceInternal/TcpEndpoint.java b/java/src/IceInternal/TcpEndpoint.java new file mode 100644 index 00000000000..9ff2c68f1ed --- /dev/null +++ b/java/src/IceInternal/TcpEndpoint.java @@ -0,0 +1,355 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class TcpEndpoint extends Endpoint +{ + public + TcpEndpoint(String ho, int po, int ti) + { + _host = ho; + _port = po; + _timeout = ti; + } + + public + TcpEndpoint(String str) + { + _host = null; + _port = 0; + _timeout = -1; + + String[] arr = init.split("[ \t\n\r]+"); + + int i = 0; + while (i < arr.length) + { + String option = arr[i++]; + if (option.length() != 2 || option.charAt(0) != '-') + { + throw new Ice.EndpointParseException(); + } + + String argument = null; + if (i < arr.length && arr[i].charAt(0) != '-') + { + argument = arr[i++]; + } + + switch (option.charAt(1)) + { + case 'h': + { + if (argument == null) + { + throw new Ice.EndpointParseException(); + } + + host = argument; + break; + } + + case 'p': + { + if (argument == null) + { + throw new Ice.EndpointParseException(); + } + + try + { + _port = Integer.parseInt(argument); + } + catch (NumberFormatException ex) + { + throw new Ice.EndpointParseException(); + } + + break; + } + + case 't': + { + if (argument == null) + { + throw new Ice.EndpointParseException(); + } + + try + { + _timeout = Integer.parseInt(argument); + } + catch (NumberFormatException ex) + { + throw new Ice.EndpointParseException(); + } + + break; + } + + default: + { + throw new Ice.EndpointParseException(); + } + } + } + + if (_host == null) + { + // TODO: Whether numeric or not should be configurable + _host = Network.getLocalHost(true); + } + } + + public + TcpEndpoint(Ice.Stream s) + { + s.startReadEncaps(); + _host = s.readString(); + _port = s.readInt(); + _timeout = s.readInt(); + s.endReadEncaps(); + } + + // + // Marshal the endpoint + // + public void + streamWrite(Ice.Stream s) + { + s.writeShort(TcpEndpointType); + s.startWriteEncaps(); + s.writeString(_host); + s.writeInt(_port); + s.writeInt(_timeout); + s.endWriteEncaps(); + } + + // + // Convert the endpoint to its string form + // + 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 the endpoint type + // + public short + type() + { + return TcpEndpointType; + } + + // + // Return true if the endpoint only supports oneway operations. + // + public boolean + oneway() + { + return false; + } + + // + // Return the timeout for the endpoint in milliseconds. 0 means + // non-blocking, -1 means no timeout. + // + public int + timeout() + { + return _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 Endpoint + timeout(int timeout) + { + if (timeout == _timeout) + { + return this; + } + else + { + return new TcpEndpoint(_host, _port, timeout); + } + } + + // + // Return true if the endpoint is datagram-based. + // + public boolean + datagram() + { + return false; + } + + // + // Return true if the endpoint is secure. + // + public boolean + secure() + { + return false; + } + + // + // Return a client side transceiver for this endpoint, or null if a + // transceiver can only be created by a connector. + // + public Transceiver + clientTransceiver(Instance instance) + { + return null; + } + + // + // 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 Transceiver + serverTransceiver(Instance instance, EndpointHolder endpoint) + { + endpoint.value = null; + return null; + } + + // + // Return a connector for this endpoint, or null if no connector + // is available. + // + public Connector + connector(Instance instance) + { + return new TcpConnector(instance, _host, _port); + } + + // + // Return an acceptor for this endpoint, or null if no acceptors + // is available. In case an acceptor 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 Acceptor + acceptor(Instance instance, EndpointHolder endpoint) + { + TcpAcceptor p = new TcpAcceptor(instance, _port); + endpoint.value = new TcpEndpoint(_host, p.effectivePort(), _timeout); + return p; + } + + // + // Check whether the endpoint is equivalent to a specific + // Transceiver or Acceptor + // + public boolean + equivalent(Transceiver transceiver) + { + return false; + } + + public boolean + equivalent(Acceptor acceptor) + { + TcpAcceptor tcpAcceptor = null; + try + { + tcpAcceptor = (TcpAcceptor)acceptor; + } + catch (ClassCastException ex) + { + return false; + } + return tcpAcceptor.equivalent(_host, _port); + } + + // + // Compare endpoints for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + TcpEndpoint p = null; + + try + { + p = (TcpEndpoint)obj; + } + catch (ClassCastException ex) + { + return false; + } + + if (this == p) + { + return true; + } + + if (_port != p._port) + { + return false; + } + + if (_timeout != p._timeout) + { + return false; + } + + if (!_host.equals(p._host)) + { + try + { + java.net.InetAddress addr1 = + java.net.InetAddress.getByName(_host); + + java.net.InetAddress addr2 = + java.net.InetAddress.getByName(p._host); + + if(!addr1.equals(addr2)) + return false; + } + catch(java.net.UnknownHostException ex) + { + return false; + } + } + + return true; + } + + private String _host; + private int _port; + private int _timeout; +} diff --git a/java/src/IceInternal/UdpEndpoint.java b/java/src/IceInternal/UdpEndpoint.java new file mode 100644 index 00000000000..61366eef6e5 --- /dev/null +++ b/java/src/IceInternal/UdpEndpoint.java @@ -0,0 +1,315 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class UdpEndpoint extends Endpoint +{ + public + UdpEndpoint(String ho, int po) + { + _host = ho; + _port = po; + } + + public + UdpEndpoint(String str) + { + _host = null; + _port = 0; + + String[] arr = init.split("[ \t\n\r]+"); + + int i = 0; + while (i < arr.length) + { + String option = arr[i++]; + if (option.length() != 2 || option.charAt(0) != '-') + { + throw new Ice.EndpointParseException(); + } + + String argument = null; + if (i < arr.length && arr[i].charAt(0) != '-') + { + argument = arr[i++]; + } + + switch (option.charAt(1)) + { + case 'h': + { + if (argument == null) + { + throw new Ice.EndpointParseException(); + } + + host = argument; + break; + } + + case 'p': + { + if (argument == null) + { + throw new Ice.EndpointParseException(); + } + + try + { + _port = Integer.parseInt(argument); + } + catch (NumberFormatException ex) + { + throw new Ice.EndpointParseException(); + } + + break; + } + + default: + { + throw new Ice.EndpointParseException(); + } + } + } + + if (_host == null) + { + // TODO: Whether numeric or not should be configurable + _host = Network.getLocalHost(true); + } + } + + public + UdpEndpoint(Ice.Stream s) + { + s.startReadEncaps(); + _host = s.readString(); + _port = s.readInt(); + s.endReadEncaps(); + } + + // + // Marshal the endpoint + // + public void + streamWrite(Ice.Stream s) + { + s.writeShort(UdpEndpointType); + s.startWriteEncaps(); + s.writeString(_host); + s.writeInt(_port); + s.endWriteEncaps(); + } + + // + // Convert the endpoint to its string form + // + 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 the endpoint type + // + public short + type() + { + return UdpEndpointType; + } + + // + // Return true if the endpoint only supports oneway operations. + // + public boolean + oneway() + { + return true; + } + + // + // Return the timeout for the endpoint in milliseconds. 0 means + // non-blocking, -1 means no timeout. + // + public int + timeout() + { + return -1; + } + + // + // Return a new endpoint with a different timeout value, provided + // that timeouts are supported by the endpoint. Otherwise the same + // endpoint is returned. + // + public Endpoint + timeout(int timeout) + { + return this; + } + + // + // Return true if the endpoint is datagram-based. + // + public boolean + datagram() + { + return true; + } + + // + // Return true if the endpoint is secure. + // + public boolean + secure() + { + return false; + } + + // + // Return a client side transceiver for this endpoint, or null if a + // transceiver can only be created by a connector. + // + public Transceiver + clientTransceiver(Instance instance) + { + return new UdpTransceiver(instance, _host, _port); + } + + // + // 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 Transceiver + serverTransceiver(Instance instance, EndpointHolder endpoint) + { + UdpTransceiver p = new UdpTransceiver(instance, _port); + endpoint.value = new UdpEndpoint(_host, p.effectivePort()); + return p; + } + + // + // Return a connector for this endpoint, or null if no connector + // is available. + // + public Connector + connector(Instance instance) + { + return null; + } + + // + // Return an acceptor for this endpoint, or null if no acceptors + // is available. In case an acceptor 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 Acceptor + acceptor(Instance instance, EndpointHolder endpoint) + { + endpoint.value = null; + return null; + } + + // + // Check whether the endpoint is equivalent to a specific + // Transceiver or Acceptor + // + public boolean + equivalent(Transceiver transceiver) + { + UdpTransceiver udpTransceiver = null; + try + { + udpTransceiver = (UdpTransceiver)transceiver; + } + catch (ClassCastException ex) + { + return false; + } + return udpTransceiver.equivalent(_host, _port); + } + + public boolean + equivalent(Acceptor acceptor) + { + return false; + } + + // + // Compare endpoints for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + UdpEndpoint p = null; + + try + { + p = (UdpEndpoint)obj; + } + catch (ClassCastException ex) + { + return false; + } + + if (this == p) + { + return true; + } + + if (_port != p._port) + { + return false; + } + + if (!_host.equals(p._host)) + { + try + { + java.net.InetAddress addr1 = + java.net.InetAddress.getByName(_host); + + java.net.InetAddress addr2 = + java.net.InetAddress.getByName(p._host); + + if(!addr1.equals(addr2)) + return false; + } + catch(java.net.UnknownHostException ex) + { + return false; + } + } + + return true; + } + + private String _host; + private int _port; +} diff --git a/java/src/IceInternal/UnknownEndpoint.java b/java/src/IceInternal/UnknownEndpoint.java new file mode 100644 index 00000000000..e637fe5c3d3 --- /dev/null +++ b/java/src/IceInternal/UnknownEndpoint.java @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class UnknownEndpoint extends Endpoint +{ + public + UnknownEndpoint(Ice.Stream s) + { + _rawBytes = s.readBytes(); + } + + // + // Marshal the endpoint + // + public void + streamWrite(Ice.Stream s) + { + s.writeShort(UnknownEndpointType); + s.writeBytes(_rawBytes); + } + + // + // Convert the endpoint to its string form + // + public String + toString() + { + return ""; + } + + // + // Return the endpoint type + // + public short + type() + { + return UnknownEndpointType; + } + + // + // Return true if the endpoint only supports oneway operations. + // + public boolean + oneway() + { + return false; + } + + // + // Return the timeout for the endpoint in milliseconds. 0 means + // non-blocking, -1 means no timeout. + // + public int + timeout() + { + return -1; + } + + // + // Return a new endpoint with a different timeout value, provided + // that timeouts are supported by the endpoint. Otherwise the same + // endpoint is returned. + // + public Endpoint + timeout(int t) + { + return this; + } + + // + // Return true if the endpoint is datagram-based. + // + public boolean + datagram() + { + return false; + } + + // + // Return true if the endpoint is secure. + // + public boolean + secure() + { + return false; + } + + // + // Return a client side transceiver for this endpoint, or null if a + // transceiver can only be created by a connector. + // + public Transceiver + clientTransceiver(Instance instance) + { + return null; + } + + // + // 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 Transceiver + serverTransceiver(Instance instance, EndpointHolder endpoint) + { + endpoint.value = null; + return null; + } + + // + // Return a connector for this endpoint, or null if no connector + // is available. + // + public Connector + connector(Instance instance) + { + return null; + } + + // + // Return an acceptor for this endpoint, or null if no acceptors + // is available. In case an acceptor 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 Acceptor + acceptor(Instance instance, EndpointHolder endpoint) + { + endpoint.value = null; + return null; + } + + // + // Check whether the endpoint is equivalent to a specific + // Transceiver or Acceptor + // + public boolean + equivalent(Transceiver transceiver) + { + return false; + } + + public boolean + equivalent(Acceptor acceptor) + { + return false; + } + + // + // Compare endpoints for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + UnknownEndpoint p = null; + + try + { + p = (UnknownEndpoint)obj; + } + catch (ClassCastException ex) + { + return false; + } + + if (this == p) + { + return true; + } + + if (!java.util.Arrays.equals(_rawBytes, p._rawBytes)) + { + return false; + } + + return true; + } + + private byte[] _rawBytes; +} |