diff options
author | Mark Spruiell <mes@zeroc.com> | 2001-11-14 14:43:03 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2001-11-14 14:43:03 +0000 |
commit | 11d9db0d42f47308804c91d95a9185b5778581a4 (patch) | |
tree | 4b9cf7b2c7a421f4fd8f2dbcee4a2cbc4ee87a28 /java/src | |
parent | fixes (diff) | |
download | ice-11d9db0d42f47308804c91d95a9185b5778581a4.tar.bz2 ice-11d9db0d42f47308804c91d95a9185b5778581a4.tar.xz ice-11d9db0d42f47308804c91d95a9185b5778581a4.zip |
adding more files
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/LoggerI.java | 50 | ||||
-rw-r--r-- | java/src/Ice/ObjectAdapterI.java | 186 | ||||
-rw-r--r-- | java/src/IceInternal/Incoming.java | 120 | ||||
-rw-r--r-- | java/src/IceInternal/NonRepeatable.java | 28 | ||||
-rw-r--r-- | java/src/IceInternal/Outgoing.java | 285 |
5 files changed, 667 insertions, 2 deletions
diff --git a/java/src/Ice/LoggerI.java b/java/src/Ice/LoggerI.java new file mode 100644 index 00000000000..cea212cc45b --- /dev/null +++ b/java/src/Ice/LoggerI.java @@ -0,0 +1,50 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package Ice; + +public class LoggerI implements Logger +{ + public synchronized void + trace(String category, String message) + { + String s = "[ " + category + ": "; + // TODO: Better way to do this? + int start = 0; + int next; + while((next = msg.indexOf('\n', start)) != -1) + { + s += msg.substring(start, next + 1); + s += " "; + start = next + 1; + } + s += msg.substring(start); + s += " ]"; + System.err.println(s); + } + + public synchronized void + warning(String message) + { + System.err.println("warning: " + message); + } + + public synchronized void + error(String message) + { + System.err.println("error: " + message); + } + + public void + destroy() + { + // Nothing to do + } +} diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java new file mode 100644 index 00000000000..5bdb83d6f7b --- /dev/null +++ b/java/src/Ice/ObjectAdapterI.java @@ -0,0 +1,186 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package Ice; + +public class ObjectAdapterI implements ObjectAdapter +{ + public String + getName() + { + return _name; // _name is immutable + } + + public Communicator + getCommunicator() + { + return _instance.communicator(); // _instance is immutable + } + + public synchronized void + activate() + { + if (_collectorFactories.isEmpty()) + { + throw new ObjectAdapterDeactivatedException(); + } + + final int sz = _collectorFactories.size(); + for (int i = 0; i < sz; i++) + { + IceInternal.CollectorFactory factory = + (IceInternal.CollectorFactory)_collectorFactories.elementAt(i); + factory.activate(); + } + } + + public synchronized void + hold() + { + if (_collectorFactories.isEmpty()) + { + throw new ObjectAdapterDeactivatedException(); + } + + final int sz = _collectorFactories.size(); + for (int i = 0; i < sz; i++) + { + IceInternal.CollectorFactory factory = + (IceInternal.CollectorFactory)_collectorFactories.elementAt(i); + factory.hold(); + } + } + + public synchronized void + deactivate() + { + if (_collectorFactories.isEmpty()) + { + // + // Ignore deactivation requests if the Object Adapter has + // already been deactivated. + // + return; + } + + int sz = _collectorFactories.size(); + for (int i = 0; i < sz; i++) + { + IceInternal.CollectorFactory factory = + (IceInternal.CollectorFactory)_collectorFactories.elementAt(i); + factory.destroy(); + } + _collectorFactories.clear(); + + _activeServantMap.clear(); + // TODO: Hint + + int sz = _locatorMap.size(); + java.util.Set valueSet = _locatorMap.valueSet(); + ServantLocator[] locators = new ServantLocator[sz]; + valueSet.toArray(locators); + for (int i = 0; i < sz; i++) + { + locators[i].deactivate(); + } + _locatorMap.clear(); + // TODO: Hint + } + + public synchronized ObjectPrx + add(Ice.Object servant, String ident) + { + if (_collectorFactories.isEmpty()) + { + throw new ObjectAdapterDeactivatedException(); + } + + _activeServantMap.put(ident, object); + + return newProxy(ident); + } + + public synchronized ObjectPrx + addTemporary(Ice.Object servant) + { + if (_collectorFactories.isEmpty()) + { + throw new ObjectAdapterDeactivatedException(); + } + + String ident = TODO + + _activeServantMap.put(ident, object); + + return newProxy(ident); + } + + public synchronized void + remove(String identity) + { + } + + public synchronized void + addServantLocator(ServantLocator locator, String prefix) + { + } + + public synchronized void + removeServantLocator(String prefix) + { + } + + public synchronized ServantLocator + findServantLocator(String prefix) + { + } + + public synchronized Ice.Object + identityToServant(String identity) + { + } + + public Ice.Object + proxyToServant(ObjectPrx proxy) + { + } + + public synchronized ObjectPrx + createProxy(String identity) + { + } + + // + // Only for use by IceInternal.ObjectAdapterFactory + // + public + ObjectAdapterI(IceInternal.Instance instance, String, String) + { + } + + private ObjectPrx + newProxy(String) + { + } + + private boolean + isLocal(ObjectPrx) + { + } + + 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(); + // TODO: Hint + java.util.HashMap _locatorMap = new java.util.HashMap(); + // TODO: Hint +} diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java index 2a880ed8b24..4d76162c815 100644 --- a/java/src/IceInternal/Incoming.java +++ b/java/src/IceInternal/Incoming.java @@ -10,7 +10,7 @@ package IceInternal; -public class Incoming +public final class Incoming { public Incoming(Instance instance, Ice.ObjectAdapter adapter) @@ -28,7 +28,123 @@ public class Incoming String facet = _is.readString(); String operation = _is.readString(); - // TODO + int statusPos = ...; // TODO + + Ice.Object servant = null; + Ice.ServantLocator locator = null; + Ice.LocalObjectHolder cookie = new Ice.LocalObjectHolder(); + + try + { + servant = _adapter.identityToServant(identity); + + if (servant == null) + { + int pos = identity.indexOf('#'); + if (pos != -1) + { + locator = _adapter.findServantLocator( + identity.substring(0, pos)); + if (locator != null) + { + servant = locator.locate(_adapter, identity, operation, + cookie); + } + } + } + + if (servant == null) + { + locator = _adapter.findServantLocator(""); + if (locator != null) + { + servant = locator.locate(_adapter, identity, operation, + cookie); + } + } + + if (servant == null) + { + _os.writeByte((byte)DispatchStatus._DispatchObjectNotExist); + } + else + { + if (facet.length() > 0) + { + Ice.Object facetServant = servant._findFacet(facet); + if (facetServant == null) + { + _os.writeByte( + (byte)DispatchStatus._DispatchFacetNotExist); + } + else + { + _os.writeByte((byte)DispatchStatus._DispatchOK); + DispatchStatus status = + facetServant.__dispatch(this, operation); + // TODO: Patch new status back into _os + } + } + else + { + _os.writeByte((byte)DispatchStatus._DispatchOK); + DispatchStatus status = + servant.__dispatch(this, operation); + // TODO: Patch new status back into _os + } + } + + if (locator != null && servant != null) + { + locator.finished(_adapter, identity, operation, servant, + cookie.value); + } + } + catch (Ice.LocationForward ex) + { + if (locator != null && servant != null) + { + locator.finished(_adapter, identity, operation, servant, + cookie.value); + } + _os.writeByte((byte)DispatchStatus._DispatchLocationForward); + // TODO + return; + } + catch (Ice.LocalException ex) + { + if (locator != null && servant != null) + { + locator.finished(_adapter, identity, operation, servant, + cookie.value); + } + // TODO + _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); + throw ex; + } + catch (Ice.UserException ex) + { + if (locator != null && servant != null) + { + locator.finished(_adapter, identity, operation, servant, + cookie.value); + } + // TODO + _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); + // throw ex; + return; + } + catch (Exception ex) + { + if (locator != null && servant != null) + { + locator.finished(_adapter, identity, operation, servant, + cookie.value); + } + // TODO + _os.writeByte((byte)DispatchStatus._DispatchUnknownException); + throw new Ice.UnknownException(); // TODO: Chain? + } } public Stream diff --git a/java/src/IceInternal/NonRepeatable.java b/java/src/IceInternal/NonRepeatable.java new file mode 100644 index 00000000000..b7cc594142d --- /dev/null +++ b/java/src/IceInternal/NonRepeatable.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public class NonRepeatable extends Exception // TODO: Base class? +{ + public + NonRepeatable(Ice.LocalException ex) + { + _ex = ex; + } + + public Ice.LocalException + get() + { + return _ex; + } + + private Ice.LocalException _ex; +} diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java new file mode 100644 index 00000000000..d5f96c7be82 --- /dev/null +++ b/java/src/IceInternal/Outgoing.java @@ -0,0 +1,285 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class Outgoing +{ + public + Outgoing(Emitter emitter, Reference ref) + { + _emitter = emitter; + _reference = ref; + _state = StateUnsent; + _is = new StreamI(ref.instance); + _os = new StreamI(ref.instance); + + switch (_reference.mode) + { + case Reference.ModeTwoway: + case Reference.ModeOneway: + case Reference.ModeDatagram: + { + _emitter.prepareRequest(this); + break; + } + + case Reference.ModeBatchOneway: + case Reference.ModeBatchDatagram: + { + _emitter.prepareBatchRequest(this); + break; + } + } + + _os.writeString(_reference.identity); + _os.writeString(_reference.facet); + } + + protected void + finalize() + throws Throwable + { + if (_state == StateUnsent && + (_reference.mode == Reference.ModeBatchOneway || + _reference.mode == Reference.ModeBatchDatagram)) + { + _emitter.abortBatchRequest(); + } + } + + public boolean + invoke() + { + switch (_reference.mode) + { + case Reference.ModeTwoway: + { + boolean timedOut = false; + + synchronized(this) + { + _emitter.sendRequest(this, false); + _state = StateInProgress; + + int timeout = _emitter.timeout(); + while (_state == StateInProgress) + { + try + { + if (timeout >= 0) + { + wait(timeout); + if (_state == StateInProgress) + { + _state = StateLocalException; + _exception = new Ice.TimeoutException(); + timedOut = true; + } + } + else + { + wait(); + } + } + catch(InterruptedException ex) + { + } + } + } + + if (_exception != null) + { + if (timedOut) + { + // + // Must be called outside the synchronization of + // this object + // + _emitter.exception(_exception); + } + + // + // A CloseConnectionException indicates graceful + // server shutdown, and is therefore always repeatable + // without violating "at-most-once". That's because by + // sending a close connection message, the server + // guarantees that all outstanding requests can safely + // be repeated. + // + if (_exception instanceof Ice.CloseConnectionException) + { + throw _exception; + } + + // + // Throw the exception wrapped in a NonRepeatable, to + // indicate that the request cannot be resent without + // potentially violating the "at-most-once" principle. + // + throw new NonRepeatable(_exception); + } + + if (_state == StateException) + { + return false; + } + + if (_state == StateLocationForward) + { + Ice.ObjectPrx p = _is.readObject(); + throw new Ice.LocationForward(p); + } + + assert _state == StateOK; + break; + } + + case Reference.ModeOneway: + case Reference.ModeDatagram: + { + _emitter.sendRequest(this, true); + _state = StateInProgress; + break; + } + + case Reference.ModeBatchOneway: + case Reference.ModeBatchDatagram: + { + _state = StateInProgress; // Must be set to StateInProgress + // before finishBatchRequest() + _emitter.finishBatchRequest(this); + break; + } + } + + return true; + } + + public synchronized void + finished(Ice.Stream is) + { + assert _state != StateUnsent; + if (_state == StateInProgress) + { + _is.swap(is); + byte status = _is.readByte(); + switch ((int)status) + { + case DispatchStatus._DispatchOK: + { + _state = StateOK; + break; + } + + case DispatchStatus._DispatchUserException: + { + _state = StateException; + break; + } + + case DispatchStatus._DispatchLocationForward: + { + _state = StateLocationForward; + break; + } + + case DispatchStatus._DispatchObjectNotExist: + { + _state = StateLocalException; + _exception = new Ice.ObjectNotExistException(); + break; + } + + case DispatchStatus._DispatchFacetNotExist: + { + _state = StateLocalException; + _exception = new Ice.FacetNotExistException(); + break; + } + + case DispatchStatus._DispatchOperationNotExist: + { + _state = StateLocalException; + _exception = new Ice.OperationNotExistException(); + break; + } + + case DispatchStatus._DispatchUnknownLocalException: + { + _state = StateLocalException; + _exception = new Ice.UnknownLocalException(); + break; + } + + case DispatchStatus._DispatchUnknownUserException: + { + _state = StateLocalException; + _exception = new Ice.UnknownUserException(); + break; + } + + case DispatchStatus._DispatchUnknownException: + { + _state = StateLocalException; + _exception = new Ice.UnknownException(); + break; + } + + default: + { + _state = StateLocalException; + _exception = new Ice.UnknownReplyStatusException(); + break; + } + } + } + notify(); + } + + public synchronized void + finished(Ice.LocalException ex) + { + assert _state != StateUnsent; + if (_state == StateInProgress) + { + _state = StateLocalException; + _exception = ex; + notify(); + } + } + + public Ice.Stream + is() + { + return _is; + } + + public Ice.Stream + os() + { + return _os; + } + + private Emitter _emitter; + private Reference _reference; + private Ice.LocalException _exception; + + private static final int StateUnsent = 0; + private static final int StateInProgress = 1; + private static final int StateOK = 2; + private static final int StateException = 3; + private static final int StateLocationForward = 4; + private static final int StateLocalException = 5; + private int _state; + + private Ice.Stream _is; + private Ice.Stream _os; +} |