summaryrefslogtreecommitdiff
path: root/java/src/Ice/ObjectAdapterI.java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-01-29 06:49:10 +0000
committerMark Spruiell <mes@zeroc.com>2002-01-29 06:49:10 +0000
commit0001dc614d21380fb22a22566a44e6d2eae88542 (patch)
treec2a50cf5bd26da7ce3844146473989ebac902515 /java/src/Ice/ObjectAdapterI.java
parentadding server (diff)
downloadice-0001dc614d21380fb22a22566a44e6d2eae88542.tar.bz2
ice-0001dc614d21380fb22a22566a44e6d2eae88542.tar.xz
ice-0001dc614d21380fb22a22566a44e6d2eae88542.zip
align with stable_31
Diffstat (limited to 'java/src/Ice/ObjectAdapterI.java')
-rw-r--r--java/src/Ice/ObjectAdapterI.java234
1 files changed, 181 insertions, 53 deletions
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index 3ad2648ab86..7abc61f9cf0 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -28,16 +28,16 @@ public class ObjectAdapterI implements ObjectAdapter
activate()
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
- java.util.ListIterator i = _incomingConnectionFactories.listIterator();
- while (i.hasNext())
+ final int sz = _incomingConnectionFactories.size();
+ for (int i = 0; i < sz; i++)
{
IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)i.next();
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
factory.activate();
}
}
@@ -45,16 +45,16 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized void
hold()
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
- java.util.ListIterator i = _incomingConnectionFactories.listIterator();
- while (i.hasNext())
+ final int sz = _incomingConnectionFactories.size();
+ for (int i = 0; i < sz; i++)
{
IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)i.next();
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
factory.hold();
}
}
@@ -62,7 +62,7 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized void
deactivate()
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
//
// Ignore deactivation requests if the Object Adapter has
@@ -71,15 +71,17 @@ public class ObjectAdapterI implements ObjectAdapter
return;
}
- java.util.ListIterator i = _incomingConnectionFactories.listIterator();
- while (i.hasNext())
+ final int sz = _incomingConnectionFactories.size();
+ for (int i = 0; i < sz; i++)
{
IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)i.next();
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
factory.destroy();
}
_incomingConnectionFactories.clear();
+ _instance.outgoingConnectionFactory().removeAdapter(this);
+
_activeServantMap.clear();
java.util.Iterator p = _locatorMap.values().iterator();
@@ -89,12 +91,14 @@ public class ObjectAdapterI implements ObjectAdapter
locator.deactivate();
}
_locatorMap.clear();
+
+ _deactivated = true;
}
public synchronized ObjectPrx
add(Ice.Object servant, Identity ident)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -105,9 +109,9 @@ public class ObjectAdapterI implements ObjectAdapter
}
public synchronized ObjectPrx
- addTemporary(Ice.Object servant)
+ addWithUUID(Ice.Object servant)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -115,9 +119,7 @@ public class ObjectAdapterI implements ObjectAdapter
long now = System.currentTimeMillis();
Identity ident = new Identity();
ident.category = "";
- ident.name = "." + Long.toHexString(now / 1000L) + "." +
- Long.toHexString(now % 1000L) + "." +
- Integer.toHexString(_rand.nextInt());
+ ident.name = Util.generateUUID();
_activeServantMap.put(ident, servant);
@@ -127,7 +129,7 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized void
remove(Identity ident)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -138,7 +140,7 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized void
addServantLocator(ServantLocator locator, String prefix)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -149,7 +151,7 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized void
removeServantLocator(String prefix)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -164,7 +166,7 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized ServantLocator
findServantLocator(String prefix)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -188,7 +190,7 @@ public class ObjectAdapterI implements ObjectAdapter
public synchronized ObjectPrx
createProxy(Identity ident)
{
- if (_incomingConnectionFactories.isEmpty())
+ if (_deactivated)
{
throw new ObjectAdapterDeactivatedException();
}
@@ -196,6 +198,94 @@ public class ObjectAdapterI implements ObjectAdapter
return newProxy(ident);
}
+ public synchronized ObjectPrx
+ createReverseProxy(Identity ident)
+ {
+ if (_deactivated)
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ //
+ // Create a reference and return a reverse proxy for this reference.
+ //
+ IceInternal.Endpoint[] endpoints = new IceInternal.Endpoint[0];
+ IceInternal.Reference ref =
+ _instance.referenceFactory().create(ident, "", IceInternal.Reference.ModeTwoway, false, endpoints,
+ endpoints, null, this);
+
+ return _instance.proxyFactory().referenceToProxy(ref);
+ }
+
+ public synchronized void
+ addRouter(RouterPrx router)
+ {
+ if (_deactivated)
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ IceInternal.RouterInfo routerInfo = _instance.routerManager().get(router);
+ if (routerInfo != null)
+ {
+ //
+ // Add the router's server proxy endpoints to this object
+ // adapter.
+ //
+ ObjectPrxHelper proxy = (ObjectPrxHelper)routerInfo.getServerProxy();
+ IceInternal.Endpoint[] endpoints = proxy.__reference().endpoints;
+ for (int i = 0; i < endpoints.length; i++)
+ {
+ _routerEndpoints.add(endpoints[i]);
+ }
+ java.util.Collections.sort(_routerEndpoints); // Must be sorted.
+ for (int i = 0; i < _routerEndpoints.size() - 1; i++)
+ {
+ java.lang.Object o1 = _routerEndpoints.get(i);
+ java.lang.Object o2 = _routerEndpoints.get(i + 1);
+ if (o1.equals(o2))
+ {
+ _routerEndpoints.remove(i);
+ }
+ }
+
+ //
+ // Associate this object adapter with the router. This way,
+ // new outgoing connections to the router's client proxy will
+ // use this object adapter for callbacks.
+ //
+ routerInfo.setAdapter(this);
+
+ //
+ // Also modify all existing outgoing connections to the
+ // router's client proxy to use this object adapter for
+ // callbacks.
+ //
+ _instance.outgoingConnectionFactory().setRouter(routerInfo.getRouter());
+ }
+ }
+
+ public synchronized IceInternal.Connection[]
+ getIncomingConnections()
+ {
+ java.util.ArrayList connections = new java.util.ArrayList();
+ final int sz = _incomingConnectionFactories.size();
+ for (int i = 0; i < sz; i++)
+ {
+ IceInternal.IncomingConnectionFactory factory =
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
+ IceInternal.Connection[] cons = factory.connections();
+ for (int j = 0; j < cons.length; j++)
+ {
+ connections.add(cons[j]);
+ }
+ }
+
+ IceInternal.Connection[] arr = new IceInternal.Connection[connections.size()];
+ connections.toArray(arr);
+ return arr;
+ }
+
//
// Only for use by IceInternal.ObjectAdapterFactory
//
@@ -203,6 +293,7 @@ public class ObjectAdapterI implements ObjectAdapter
ObjectAdapterI(IceInternal.Instance instance, String name, String endpts)
{
_instance = instance;
+ _deactivated = false;
_name = name;
String s = endpts.toLowerCase();
@@ -222,7 +313,7 @@ public class ObjectAdapterI implements ObjectAdapter
if (end == beg)
{
- throw new EndpointParseException();
+ break;
}
String es = s.substring(beg, end);
@@ -232,11 +323,8 @@ public class ObjectAdapterI implements ObjectAdapter
// might change it, for example, to fill in the real port
// number if a zero port number is given.
//
- IceInternal.Endpoint endp =
- IceInternal.Endpoint.endpointFromString(instance, es);
- _incomingConnectionFactories.add(
- new IceInternal.IncomingConnectionFactory(instance, endp,
- this));
+ IceInternal.Endpoint endp = IceInternal.Endpoint.endpointFromString(instance, es);
+ _incomingConnectionFactories.add(new IceInternal.IncomingConnectionFactory(instance, endp, this));
if (end == s.length())
{
@@ -248,18 +336,24 @@ public class ObjectAdapterI implements ObjectAdapter
}
catch (LocalException ex)
{
- if (!_incomingConnectionFactories.isEmpty())
+ if (!_deactivated)
{
deactivate();
}
-
throw ex;
}
+//
+// Object Adapters without incoming connection factories are
+// permissible, as such Object Adapters can still be used with a
+// router. (See addRouter.)
+//
+/*
if (_incomingConnectionFactories.isEmpty())
{
throw new EndpointParseException();
}
+*/
try
{
@@ -280,7 +374,7 @@ public class ObjectAdapterI implements ObjectAdapter
finalize()
throws Throwable
{
- if (!_incomingConnectionFactories.isEmpty())
+ if (!_deactivated)
{
deactivate();
}
@@ -292,52 +386,86 @@ public class ObjectAdapterI implements ObjectAdapter
newProxy(Identity ident)
{
IceInternal.Endpoint[] endpoints =
- new IceInternal.Endpoint[_incomingConnectionFactories.size()];
- int n = 0;
- java.util.ListIterator i = _incomingConnectionFactories.listIterator();
- while (i.hasNext())
+ new IceInternal.Endpoint[_incomingConnectionFactories.size() + _routerEndpoints.size()];
+
+ //
+ // First we add all endpoints from all incoming connection
+ // factories.
+ //
+ int sz = _incomingConnectionFactories.size();
+ for (int i = 0; i < sz; i++)
{
IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)i.next();
- endpoints[n++] = factory.endpoint();
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
+ endpoints[i] = factory.endpoint();
+ }
+
+ //
+ // Now we also add the endpoints of the router's server proxy, if
+ // any. This way, object references created by this object adapter
+ // will also point to the router's server proxy endpoints.
+ //
+ sz = _routerEndpoints.size();
+ for (int i = 0; i < sz; i++)
+ {
+ endpoints[i] = (IceInternal.Endpoint)_routerEndpoints.get(i);
}
- IceInternal.Reference reference = new IceInternal.Reference(_instance,
- ident, "", IceInternal.Reference.ModeTwoway, false, endpoints,
- endpoints);
+ //
+ // Create a reference and return a proxy for this reference.
+ //
+ IceInternal.Reference reference = _instance.referenceFactory().create(ident, "", IceInternal.Reference.ModeTwoway, false,
+ endpoints, endpoints, null, null);
return _instance.proxyFactory().referenceToProxy(reference);
}
public boolean
isLocal(ObjectPrx proxy)
{
- // TODO: Optimize?
IceInternal.Reference ref = ((ObjectPrxHelper)proxy).__reference();
- IceInternal.Endpoint[] endpoints = ref.endpoints;
- for (int n = 0; n < endpoints.length; n++)
+ final IceInternal.Endpoint[] endpoints = ref.endpoints;
+
+ //
+ // Proxies which have at least one endpoint in common with the
+ // endpoints used by this object adapter's incoming connection
+ // factories are considered local.
+ //
+ for (int i = 0; i < endpoints.length; i++)
{
- java.util.ListIterator i =
- _incomingConnectionFactories.listIterator();
- while (i.hasNext())
+ final int sz = _incomingConnectionFactories.size();
+ for (int j = 0; j < sz; j++)
{
IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)i.next();
- if (factory.equivalent(endpoints[n]))
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(j);
+ if (factory.equivalent(endpoints[i]))
{
return true;
}
}
}
+ //
+ // Proxies which have at least one endpoint in common with the
+ // router's server proxy endpoints (if any), are also considered
+ // local.
+ //
+ for (int i = 0; i < endpoints.length; i++)
+ {
+ if (java.util.Collections.binarySearch(_routerEndpoints, endpoints[i]) >= 0) // _routerEndpoints is sorted.
+ {
+ return true;
+ }
+ }
+
return false;
}
private IceInternal.Instance _instance;
+ private boolean _deactivated;
private String _name;
- private java.util.LinkedList _incomingConnectionFactories =
- new java.util.LinkedList();
private java.util.HashMap _activeServantMap = new java.util.HashMap();
private java.util.HashMap _locatorMap = new java.util.HashMap();
- private java.util.Random _rand = new java.util.Random();
-
+ private java.util.ArrayList _incomingConnectionFactories =
+ new java.util.ArrayList();
+ private java.util.ArrayList _routerEndpoints = new java.util.ArrayList();
}