summaryrefslogtreecommitdiff
path: root/java/src/Ice/ObjectAdapterI.java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2001-11-14 23:57:45 +0000
committerMark Spruiell <mes@zeroc.com>2001-11-14 23:57:45 +0000
commit1a35604c2b8b09ee505f890cb5bc61e8c51956b3 (patch)
treea3704b1b8bbe26c59afb0e9b86b13ce411a47295 /java/src/Ice/ObjectAdapterI.java
parentprefix fix (diff)
downloadice-1a35604c2b8b09ee505f890cb5bc61e8c51956b3.tar.bz2
ice-1a35604c2b8b09ee505f890cb5bc61e8c51956b3.tar.xz
ice-1a35604c2b8b09ee505f890cb5bc61e8c51956b3.zip
completing initial port
Diffstat (limited to 'java/src/Ice/ObjectAdapterI.java')
-rw-r--r--java/src/Ice/ObjectAdapterI.java198
1 files changed, 177 insertions, 21 deletions
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index 5bdb83d6f7b..c9ee6db355f 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -32,11 +32,11 @@ public class ObjectAdapterI implements ObjectAdapter
throw new ObjectAdapterDeactivatedException();
}
- final int sz = _collectorFactories.size();
- for (int i = 0; i < sz; i++)
+ java.util.ListIterator i = _collectorFactories.listIterator();
+ while (i.hasNext())
{
IceInternal.CollectorFactory factory =
- (IceInternal.CollectorFactory)_collectorFactories.elementAt(i);
+ (IceInternal.CollectorFactory)i.next();
factory.activate();
}
}
@@ -49,11 +49,11 @@ public class ObjectAdapterI implements ObjectAdapter
throw new ObjectAdapterDeactivatedException();
}
- final int sz = _collectorFactories.size();
- for (int i = 0; i < sz; i++)
+ java.util.ListIterator i = _collectorFactories.listIterator();
+ while (i.hasNext())
{
IceInternal.CollectorFactory factory =
- (IceInternal.CollectorFactory)_collectorFactories.elementAt(i);
+ (IceInternal.CollectorFactory)i.next();
factory.hold();
}
}
@@ -70,11 +70,11 @@ public class ObjectAdapterI implements ObjectAdapter
return;
}
- int sz = _collectorFactories.size();
- for (int i = 0; i < sz; i++)
+ java.util.ListIterator i = _collectorFactories.listIterator();
+ while (i.hasNext())
{
IceInternal.CollectorFactory factory =
- (IceInternal.CollectorFactory)_collectorFactories.elementAt(i);
+ (IceInternal.CollectorFactory)i.next();
factory.destroy();
}
_collectorFactories.clear();
@@ -115,7 +115,9 @@ public class ObjectAdapterI implements ObjectAdapter
throw new ObjectAdapterDeactivatedException();
}
- String ident = TODO
+ long now = System.currentTimeMillis();
+ String ident = '.' + (now / 1000) + '.' + (now % 1000) + '.' +
+ _rand.nextInt();
_activeServantMap.put(ident, object);
@@ -123,64 +125,218 @@ public class ObjectAdapterI implements ObjectAdapter
}
public synchronized void
- remove(String identity)
+ remove(String ident)
{
+ if (_collectorFactories.isEmpty())
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ _activeServantMap.remove(ident);
}
public synchronized void
addServantLocator(ServantLocator locator, String prefix)
{
+ if (_collectorFactories.isEmpty())
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ _locatorMap.put(prefix, locator);
}
public synchronized void
removeServantLocator(String prefix)
{
+ if (_collectorFactories.isEmpty())
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ ServantLocator locator = (ServantLocator)_locatorMap.remove(prefix);
+ if (locator != null)
+ {
+ locator.deactivate();
+ }
}
public synchronized ServantLocator
findServantLocator(String prefix)
{
+ if (_collectorFactories.isEmpty())
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ return (ServantLocator)_locatorMap.get(prefix);
}
public synchronized Ice.Object
identityToServant(String identity)
{
+ return (Ice.Object)_activateServantMap.get(ident);
}
public Ice.Object
proxyToServant(ObjectPrx proxy)
{
+ IceInternal.Reference ref = proxy.__reference();
+ return identityToServant(ref.identity);
}
public synchronized ObjectPrx
- createProxy(String identity)
+ createProxy(String ident)
{
+ if (_collectorFactories.isEmpty())
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ return newProxy(ident);
}
//
// Only for use by IceInternal.ObjectAdapterFactory
//
public
- ObjectAdapterI(IceInternal.Instance instance, String, String)
+ ObjectAdapterI(IceInternal.Instance instance, String name, String endpts)
+ {
+ _instance = instance;
+ _name = name;
+
+ String s = endpts.toLowerCase();
+
+ int beg = 0;
+ int end;
+
+ try
+ {
+ while (true)
+ {
+ end = s.indexOf(':', beg);
+ if (end == -1)
+ {
+ end = s.length();
+ }
+
+ if (end == beg)
+ {
+ throw new EndpointParseException();
+ }
+
+ String es = s.substring(beg, end);
+
+ //
+ // Don't store the endpoint in the adapter. The Collector
+ // 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(es);
+ _collectorFactories.add(
+ new IceInternal.CollectorFactory(instance, this, endp));
+
+ if (end == s.length())
+ {
+ break;
+ }
+
+ beg = end + 1;
+ }
+ }
+ catch(LocalException ex)
+ {
+ if (!_collectorFactories.isEmpty())
+ {
+ deactivate();
+ }
+
+ throw ex;
+ }
+
+ if (_collectorFactories.isEmpty())
+ {
+ throw new EndpointParseException();
+ }
+
+ try
+ {
+ String value =
+ _instance.properites().getProperty("Ice.PrintAdapterReady");
+ if (Integer.parseInt(value) >= 1)
+ {
+ System.out.println(_name + " readY");
+ }
+ }
+ catch(NumberFormatException ex)
+ {
+ // TODO: Do anything?
+ }
+ }
+
+ protected void
+ finalize()
+ throws Throwable
{
+ if (!_collectorFactories.isEmpty())
+ {
+ deactivate();
+ }
}
private ObjectPrx
- newProxy(String)
+ newProxy(String ident)
{
+ IceInternal.Endpoint[] endpoints =
+ new IceInternal.Endpoint[_collectorFactories.size()];
+ for (java.util.ListIterator i = _collectorFactories.listIterator(),
+ int n = 0;
+ i.hasNext();
+ n++)
+ {
+ IceInternal.CollectorFactory factory =
+ (IceInternal.CollectorFactory)i.next();
+ endpoints[n] = factory.endpoint();
+ }
+
+ IceInternal.Reference reference = new IceInternal.Reference(_instance,
+ ident, "", IceInternal.Reference.ModeTwoway, false, endpoints,
+ endpoints);
+ return _instance.proxyFactory().referenceToProxy(reference);
}
private boolean
- isLocal(ObjectPrx)
+ isLocal(ObjectPrx proxy)
{
+ // TODO: Optimize?
+ IceInternal.Reference ref = proxy.__reference();
+ IceInternal.Endpoint[] endpoints = ref.endpoints();
+ for (int n = 0; n < endpoints.length; n++)
+ {
+ java.util.ListIterator i = _collectorFactories.listIterator();
+ while (i.hasNext())
+ {
+ IceInternal.CollectorFactory factory =
+ (IceInternal.CollectorFactory)i.next();
+ if (factory.equivalent(endpoints[n]))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
}
- IceInternal.Instance _instance;
- String _name;
- // TODO: Better collection type?
- java.util.Vector _collectorFactories = new java.util.Vector();
- java.util.HashMap _activeServantMap = new java.util.HashMap();
+ private IceInternal.Instance _instance;
+ private String _name;
+ private java.util.LinkedList _collectorFactories =
+ new java.util.LinkedList();
+ private java.util.HashMap _activeServantMap = new java.util.HashMap();
// TODO: Hint
- java.util.HashMap _locatorMap = new java.util.HashMap();
+ private java.util.HashMap _locatorMap = new java.util.HashMap();
// TODO: Hint
+ private java.util.Random _rand = new java.util.Random();
+
}