summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Ice/ObjectAdapterI.java154
-rw-r--r--java/src/Ice/_ObjectDelD.java110
-rw-r--r--java/src/Ice/_ObjectDelM.java8
-rw-r--r--java/src/IceInternal/Connection.java84
-rw-r--r--java/src/IceInternal/Direct.java54
-rw-r--r--java/src/IceInternal/Incoming.java265
-rw-r--r--java/src/IceInternal/IncomingConnectionFactory.java28
-rw-r--r--java/src/IceInternal/Outgoing.java67
-rw-r--r--java/src/IceInternal/TraceUtil.java218
9 files changed, 492 insertions, 496 deletions
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index a7ee31930de..533bd4e8e0f 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -106,64 +106,55 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
}
}
- public synchronized void
+ public void
deactivate()
{
- if(_instance == null)
- {
- //
- // Ignore deactivation requests if the Object Adapter has
- // already been deactivated.
- //
- return;
- }
-
- final int sz = _incomingConnectionFactories.size();
- for(int i = 0; i < sz; ++i)
- {
- IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
- factory.destroy();
- }
-
- //
- // Don't do a _incomingConnectionFactories.clear()!
- // _incomingConnectionFactories is immutable. Even if all
- // elements are destroyed, the elements are still needed by
- // waitForDeactivate().
- //
-
- _instance.outgoingConnectionFactory().removeAdapter(this);
-
- _activeServantMap.clear();
-
- java.util.Iterator p = _locatorMap.values().iterator();
- while(p.hasNext())
- {
- ServantLocator locator = (ServantLocator)p.next();
- locator.deactivate();
- }
- _locatorMap.clear();
+ synchronized(this)
+ {
+ if(_instance == null)
+ {
+ //
+ // Ignore deactivation requests if the Object Adapter has
+ // already been deactivated.
+ //
+ return;
+ }
+
+ final int sz = _incomingConnectionFactories.size();
+ for(int i = 0; i < sz; ++i)
+ {
+ IceInternal.IncomingConnectionFactory factory =
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
+ factory.destroy();
+ }
+ _incomingConnectionFactories.clear();
+
+ _instance.outgoingConnectionFactory().removeAdapter(this);
+
+ _instance = null;
+ _communicator = null;
+ }
- _instance = null;
- _communicator = null;
+ decUsageCount();
}
- public void
+ public synchronized void
waitForDeactivate()
{
- //
- // _incommingConnectionFactories is immutable, thus no mutex
- // lock is necessary. (A mutex lock wouldn't work here anyway,
- // as there would be a deadlock with upcalls.)
- //
- final int sz = _incomingConnectionFactories.size();
- for(int i = 0; i < sz; ++i)
- {
- IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
- factory.waitUntilFinished();
- }
+ assert(_usageCount >= 0);
+
+ while(_usageCount > 0)
+ {
+ try
+ {
+ wait();
+ }
+ catch(java.lang.InterruptedException ex)
+ {
+ }
+ }
+
+ assert(_usageCount == 0);
}
public synchronized ObjectPrx
@@ -365,13 +356,14 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
_locatorInfo = _instance.locatorManager().get(locator);
}
- public IceInternal.Connection[]
+ public synchronized IceInternal.Connection[]
getIncomingConnections()
{
- //
- // _incommingConnectionFactories is immutable, thus no mutex lock
- // is necessary.
- //
+ if(_instance == null)
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
java.util.ArrayList connections = new java.util.ArrayList();
final int sz = _incomingConnectionFactories.size();
for(int i = 0; i < sz; ++i)
@@ -389,6 +381,40 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
return arr;
}
+ public synchronized void
+ incUsageCount()
+ {
+ assert(_instance != null); // Must not be called after deactivation.
+ assert(_usageCount >= 0);
+ ++_usageCount;
+ }
+
+ public synchronized void
+ decUsageCount()
+ {
+ //
+ // The object adapter may already be deactivated when the usage
+ // count is decremented, thus no check for prior deactivation.
+ //
+
+ assert(_usageCount > 0);
+ --_usageCount;
+ if(_usageCount == 0)
+ {
+ _activeServantMap.clear();
+
+ java.util.Iterator p = _locatorMap.values().iterator();
+ while(p.hasNext())
+ {
+ ServantLocator locator = (ServantLocator)p.next();
+ locator.deactivate();
+ }
+ _locatorMap.clear();
+
+ notify();
+ }
+ }
+
//
// Only for use by IceInternal.ObjectAdapterFactory
//
@@ -400,6 +426,7 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
_printAdapterReadyDone = false;
_name = name;
_id = id;
+ _usageCount = 1;
String s = endpts.toLowerCase();
@@ -444,24 +471,14 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
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();
- }
-*/
}
protected void
finalize()
throws Throwable
{
+ assert(_usageCount == 0);
+
if(_instance != null)
{
_instance.logger().warning("object adapter has not been deactivated");
@@ -602,4 +619,5 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
private java.util.ArrayList _incomingConnectionFactories = new java.util.ArrayList();
private java.util.ArrayList _routerEndpoints = new java.util.ArrayList();
private IceInternal.LocatorInfo _locatorInfo;
+ private int _usageCount;
}
diff --git a/java/src/Ice/_ObjectDelD.java b/java/src/Ice/_ObjectDelD.java
index bca6cfd90ba..39ca54a66a9 100644
--- a/java/src/Ice/_ObjectDelD.java
+++ b/java/src/Ice/_ObjectDelD.java
@@ -23,22 +23,7 @@ public class _ObjectDelD implements _ObjectDel
IceInternal.Direct __direct = new IceInternal.Direct(__current);
try
{
- try
- {
- return __direct.facetServant().ice_isA(__id, __current);
- }
- catch(LocalException ex)
- {
- UnknownLocalException e = new UnknownLocalException();
- e.initCause(ex);
- throw e;
- }
- catch(RuntimeException ex)
- {
- UnknownException e = new UnknownException();
- e.initCause(ex);
- throw e;
- }
+ return __direct.facetServant().ice_isA(__id, __current);
}
finally
{
@@ -58,23 +43,8 @@ public class _ObjectDelD implements _ObjectDel
IceInternal.Direct __direct = new IceInternal.Direct(__current);
try
{
- try
- {
- __direct.facetServant().ice_ping(__current);
- return;
- }
- catch(LocalException ex)
- {
- UnknownLocalException e = new UnknownLocalException();
- e.initCause(ex);
- throw e;
- }
- catch(RuntimeException ex)
- {
- UnknownException e = new UnknownException();
- e.initCause(ex);
- throw e;
- }
+ __direct.facetServant().ice_ping(__current);
+ return;
}
finally
{
@@ -94,22 +64,7 @@ public class _ObjectDelD implements _ObjectDel
IceInternal.Direct __direct = new IceInternal.Direct(__current);
try
{
- try
- {
- return __direct.facetServant().ice_ids(__current);
- }
- catch(LocalException ex)
- {
- UnknownLocalException e = new UnknownLocalException();
- e.initCause(ex);
- throw e;
- }
- catch(RuntimeException ex)
- {
- UnknownException e = new UnknownException();
- e.initCause(ex);
- throw e;
- }
+ return __direct.facetServant().ice_ids(__current);
}
finally
{
@@ -129,22 +84,7 @@ public class _ObjectDelD implements _ObjectDel
IceInternal.Direct __direct = new IceInternal.Direct(__current);
try
{
- try
- {
- return __direct.facetServant().ice_id(__current);
- }
- catch(LocalException ex)
- {
- UnknownLocalException e = new UnknownLocalException();
- e.initCause(ex);
- throw e;
- }
- catch(RuntimeException ex)
- {
- UnknownException e = new UnknownException();
- e.initCause(ex);
- throw e;
- }
+ return __direct.facetServant().ice_id(__current);
}
finally
{
@@ -164,22 +104,7 @@ public class _ObjectDelD implements _ObjectDel
IceInternal.Direct __direct = new IceInternal.Direct(__current);
try
{
- try
- {
- return __direct.facetServant().ice_facets(__current);
- }
- catch(LocalException ex)
- {
- UnknownLocalException e = new UnknownLocalException();
- e.initCause(ex);
- throw e;
- }
- catch(RuntimeException ex)
- {
- UnknownException e = new UnknownException();
- e.initCause(ex);
- throw e;
- }
+ return __direct.facetServant().ice_facets(__current);
}
finally
{
@@ -200,33 +125,20 @@ public class _ObjectDelD implements _ObjectDel
IceInternal.Direct __direct = new IceInternal.Direct(current);
try
{
- Blobject __servant = null;
+ Blobject servant = null;
try
{
- __servant = (Blobject)__direct.facetServant();
+ servant = (Blobject)__direct.facetServant();
}
catch(ClassCastException ex)
{
OperationNotExistException opEx = new OperationNotExistException();
+ opEx.id = current.id;
+ opEx.facet = current.facet;
opEx.operation = current.operation;
throw opEx;
}
- try
- {
- return __servant.ice_invoke(inParams, outParams, current);
- }
- catch(LocalException ex)
- {
- UnknownLocalException e = new UnknownLocalException();
- e.initCause(ex);
- throw e;
- }
- catch(RuntimeException ex)
- {
- UnknownException e = new UnknownException();
- e.initCause(ex);
- throw e;
- }
+ return servant.ice_invoke(inParams, outParams, current);
}
finally
{
diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java
index 443b39bcd3d..1772a7f53f3 100644
--- a/java/src/Ice/_ObjectDelM.java
+++ b/java/src/Ice/_ObjectDelM.java
@@ -161,7 +161,7 @@ public class _ObjectDelM implements _ObjectDel
__reference = from.__reference;
__connection = from.__connection;
- __connection.incProxyUsageCount();
+ __connection.incUsageCount();
}
protected IceInternal.Connection __connection;
@@ -207,7 +207,7 @@ public class _ObjectDelM implements _ObjectDel
}
assert(j < connections.length);
__connection = connections[j];
- __connection.incProxyUsageCount();
+ __connection.incUsageCount();
}
else
{
@@ -250,7 +250,7 @@ public class _ObjectDelM implements _ObjectDel
IceInternal.OutgoingConnectionFactory factory = __reference.instance.outgoingConnectionFactory();
__connection = factory.create(filteredEndpoints);
assert(__connection != null);
- __connection.incProxyUsageCount();
+ __connection.incUsageCount();
}
catch (LocalException ex)
{
@@ -446,7 +446,7 @@ public class _ObjectDelM implements _ObjectDel
{
if(__connection != null)
{
- __connection.decProxyUsageCount();
+ __connection.decUsageCount();
}
while(__outgoingCache != null)
diff --git a/java/src/IceInternal/Connection.java b/java/src/IceInternal/Connection.java
index f99b9a67098..e6799ef31c5 100644
--- a/java/src/IceInternal/Connection.java
+++ b/java/src/IceInternal/Connection.java
@@ -134,13 +134,13 @@ public final class Connection extends EventHandler
}
public void
- incProxyUsageCount()
+ incUsageCount()
{
_mutex.lock();
try
{
- assert(_proxyUsageCount >= 0);
- ++_proxyUsageCount;
+ assert(_usageCount >= 0);
+ ++_usageCount;
}
finally
{
@@ -149,14 +149,14 @@ public final class Connection extends EventHandler
}
public void
- decProxyUsageCount()
+ decUsageCount()
{
_mutex.lock();
try
{
- assert(_proxyUsageCount > 0);
- --_proxyUsageCount;
- if(_proxyUsageCount == 0 && _adapter == null)
+ assert(_usageCount > 0);
+ --_usageCount;
+ if(_usageCount == 0 && _adapter == null)
{
assert(_requests.isEmpty());
setState(StateClosing, new Ice.CloseConnectionException());
@@ -572,66 +572,37 @@ public final class Connection extends EventHandler
{
try
{
+ //
+ // Prepare the invocation.
+ //
BasicStream is = in.is();
- BasicStream os = in.os();
stream.swap(is);
-
- boolean response = false;
+ BasicStream os = null;
try
{
+ //
+ // Prepare the response if necessary.
+ //
if(!batch)
{
int requestId = is.readInt();
if(!_endpoint.datagram() && requestId != 0) // 0 means oneway.
{
- response = true;
++_responseCount;
+ os = in.os();
os.writeBlob(_replyHdr);
os.writeInt(requestId);
}
}
-
+
+ //
+ // Do the invocation, or multiple invocations for
+ // batch messages.
+ //
do
{
- try
- {
- in.invoke(response);
- }
- catch(Ice.LocalException ex)
- {
- _mutex.lock();
- reclaimIncoming(in);
- in = null;
- try
- {
- if(_warn)
- {
- warning("connection exception", ex);
- }
- }
- finally
- {
- _mutex.unlock();
- }
- }
- catch(Exception ex)
- {
- _mutex.lock();
- reclaimIncoming(in);
- in = null;
- try
- {
- if(_warn)
- {
- warning("unknown exception", ex);
- }
- }
- finally
- {
- _mutex.unlock();
- }
- }
+ in.invoke(os != null);
}
while(batch && is.pos() < is.size());
}
@@ -651,9 +622,13 @@ public final class Connection extends EventHandler
}
}
- if(response)
+ //
+ // Send a response if necessary.
+ //
+ if(os != null)
{
_mutex.lock();
+
try
{
try
@@ -763,7 +738,7 @@ public final class Connection extends EventHandler
_nextRequestId = 1;
_batchStream = new BasicStream(instance);
_responseCount = 0;
- _proxyUsageCount = 0;
+ _usageCount = 0;
_state = StateHolding;
_registeredWithPool = false;
}
@@ -772,6 +747,7 @@ public final class Connection extends EventHandler
finalize()
throws Throwable
{
+ assert(_usageCount == 0);
assert(_state == StateClosed);
//
@@ -1045,7 +1021,7 @@ public final class Connection extends EventHandler
in = _incomingCache;
_incomingCache = _incomingCache.next;
in.next = null;
- in.reset();
+ in.reset(_adapter);
}
return in;
}
@@ -1070,7 +1046,7 @@ public final class Connection extends EventHandler
private Ice.LocalException _exception;
private BasicStream _batchStream;
private int _responseCount;
- private int _proxyUsageCount;
+ private int _usageCount;
private int _state;
private boolean _registeredWithPool;
private RecursiveMutex _mutex = new RecursiveMutex();
diff --git a/java/src/IceInternal/Direct.java b/java/src/IceInternal/Direct.java
index 90fdefb12cf..113b33e8f76 100644
--- a/java/src/IceInternal/Direct.java
+++ b/java/src/IceInternal/Direct.java
@@ -19,6 +19,8 @@ public final class Direct
try
{
+ ((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount();
+
_servant = _current.adapter.identityToServant(_current.id);
if(_servant == null && _current.id.category.length() > 0)
@@ -40,42 +42,60 @@ public final class Direct
_servant = _locator.locate(_current, _cookie);
}
}
+
+ if(_servant == null)
+ {
+ Ice.ObjectNotExistException ex = new Ice.ObjectNotExistException();
+ ex.id = _current.id;
+ ex.facet = _current.facet;
+ ex.operation = _current.operation;
+ throw ex;
+ }
- if(_servant != null && _current.facet.length > 0)
+ if(_current.facet.length > 0)
{
_facetServant = _servant.ice_findFacetPath(_current.facet, 0);
if(_facetServant == null)
{
Ice.FacetNotExistException ex = new Ice.FacetNotExistException();
+ ex.id = _current.id;
ex.facet = _current.facet;
+ ex.operation = _current.operation;
throw ex;
}
}
}
catch(RuntimeException ex)
{
- if(_locator != null && _servant != null)
- {
- _locator.finished(_current, _servant, _cookie.value);
- }
- throw ex;
- }
-
- if(_servant == null)
- {
- Ice.ObjectNotExistException ex = new Ice.ObjectNotExistException();
- ex.id = _current.id;
- throw ex;
+ try
+ {
+ if(_locator != null && _servant != null)
+ {
+ _locator.finished(_current, _servant, _cookie.value);
+ }
+ throw ex;
+ }
+ finally
+ {
+ ((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount();
+ }
}
}
public void
destroy()
{
- if(_locator != null && _servant != null)
- {
- _locator.finished(_current, _servant, _cookie.value);
- }
+ try
+ {
+ if(_locator != null && _servant != null)
+ {
+ _locator.finished(_current, _servant, _cookie.value);
+ }
+ }
+ finally
+ {
+ ((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount();
+ }
}
public Ice.Object
diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java
index 5a7b7d0bce8..b247469a7dd 100644
--- a/java/src/IceInternal/Incoming.java
+++ b/java/src/IceInternal/Incoming.java
@@ -15,17 +15,61 @@ public class Incoming
public
Incoming(Instance instance, Ice.ObjectAdapter adapter)
{
- _adapter = adapter;
_is = new BasicStream(instance);
_os = new BasicStream(instance);
_current = new Ice.Current();
+ _current.adapter = adapter;
_current.id = new Ice.Identity();
_cookie = new Ice.LocalObjectHolder();
+
+ if(_current.adapter != null)
+ {
+ ((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount();
+ }
+ }
+
+ //
+ // This function allows this object to be reused, rather than
+ // reallocated.
+ //
+ public void
+ reset(Ice.ObjectAdapter adapter)
+ {
+ _is.reset();
+ _os.reset();
+ if(_current.ctx != null)
+ {
+ _current.ctx.clear();
+ }
+ _current.adapter = adapter;
+
+ if(_current.adapter != null)
+ {
+ ((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount();
+ }
+ }
+
+ //
+ // Reclaim resources.
+ //
+ public void
+ destroy()
+ {
+ _is.destroy();
+ _os.destroy();
+
+ if(_current.adapter != null)
+ {
+ ((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount();
+ }
}
public void
invoke(boolean response)
{
+ //
+ // Read the current.
+ //
_current.id.__read(_is);
_current.facet = _is.readStringSeq();
_current.operation = _is.readString();
@@ -42,54 +86,55 @@ public class Incoming
_current.ctx.put(first, second);
}
- int statusPos = 0;
+ _is.startReadEncaps();
+
+ int statusPos;
if(response)
{
statusPos = _os.size();
_os.writeByte((byte)0);
- }
-
- //
- // Input and output parameters are always sent in an
- // encapsulation, which makes it possible to forward requests as
- // blobs.
- //
- _is.startReadEncaps();
- if(response)
- {
_os.startWriteEncaps();
}
+ else
+ {
+ statusPos = 0; // Initialize, to keep the compiler happy.
+ }
Ice.Object servant = null;
Ice.ServantLocator locator = null;
_cookie.value = null;
+ DispatchStatus status;
+
+ //
+ // Don't put the code above into the try block below. Exceptions
+ // in the code above are considered fatal, and must propagate to
+ // the caller of this operation.
+ //
try
{
- if(_adapter != null)
- {
- servant = _adapter.identityToServant(_current.id);
-
- if(servant == null && _current.id.category.length() > 0)
- {
- locator = _adapter.findServantLocator(_current.id.category);
- if(locator != null)
- {
- servant = locator.locate(_current, _cookie);
- }
- }
-
- if(servant == null)
- {
- locator = _adapter.findServantLocator("");
- if(locator != null)
- {
- servant = locator.locate(_current, _cookie);
- }
- }
- }
-
- DispatchStatus status;
+ if(_current.adapter != null)
+ {
+ servant = _current.adapter.identityToServant(_current.id);
+
+ if(servant == null && _current.id.category.length() > 0)
+ {
+ locator = _current.adapter.findServantLocator(_current.id.category);
+ if(locator != null)
+ {
+ servant = locator.locate(_current, _cookie);
+ }
+ }
+
+ if(servant == null)
+ {
+ locator = _current.adapter.findServantLocator("");
+ if(locator != null)
+ {
+ servant = locator.locate(_current, _cookie);
+ }
+ }
+ }
if(servant == null)
{
@@ -114,49 +159,16 @@ public class Incoming
status = servant.__dispatch(this, _current);
}
}
-
- if(locator != null && servant != null)
- {
- assert(_adapter != null);
- locator.finished(_current, servant, _cookie.value);
- }
-
- _is.endReadEncaps();
- if(response)
- {
- _os.endWriteEncaps();
-
- if(status != DispatchStatus.DispatchOK && status != DispatchStatus.DispatchUserException)
- {
- assert(status == DispatchStatus.DispatchObjectNotExist ||
- status == DispatchStatus.DispatchFacetNotExist ||
- status == DispatchStatus.DispatchOperationNotExist);
-
- _os.resize(statusPos, false);
- _os.writeByte((byte)status.value());
-
- _current.id.__write(_os);
- _os.writeStringSeq(_current.facet);
- _os.writeString(_current.operation);
- }
- else
- {
- int save = _os.pos();
- _os.pos(statusPos);
- _os.writeByte((byte)status.value());
- _os.pos(save);
- }
- }
}
catch(Ice.LocationForward ex)
{
if(locator != null && servant != null)
{
- assert(_adapter != null);
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
+
if(response)
{
_os.endWriteEncaps();
@@ -164,21 +176,22 @@ public class Incoming
_os.writeByte((byte)DispatchStatus._DispatchLocationForward);
_os.writeProxy(ex._prx);
}
+
+ return;
}
catch(Ice.RequestFailedException ex)
{
if(locator != null && servant != null)
{
- assert(_adapter != null);
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
+
if(response)
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
-
if(ex instanceof Ice.ObjectNotExistException)
{
_os.writeByte((byte)DispatchStatus._DispatchObjectNotExist);
@@ -195,26 +208,20 @@ public class Incoming
{
assert(false);
}
-
- // Not current.id.__write(_os), so that the identity
- // can be overwritten.
+ // Write the data from the exception, not from _current,
+ // so that a RequestFailedException can override the
+ // information from _current.
ex.id.__write(_os);
- // Not _os.write(current.facet), so that the facet can
- // be overwritten.
_os.writeStringSeq(ex.facet);
- // Not _os.write(current.operation), so that the
- // operation can be overwritten.
_os.writeString(ex.operation);
}
- // Rethrow, so that the caller can print a warning.
- throw ex;
+ return;
}
catch(Ice.LocalException ex)
{
if(locator != null && servant != null)
{
- assert(_adapter != null);
locator.finished(_current, servant, _cookie.value);
}
@@ -223,53 +230,70 @@ public class Incoming
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
- _os.writeByte(
- (byte)DispatchStatus._DispatchUnknownLocalException);
+ _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException);
+ _os.writeString(ex.toString());
}
- // Rethrow, so that the caller can print a warning.
- throw ex;
+ return;
}
/* Not possible in Java - UserExceptions are checked exceptions
catch(Ice.UserException ex)
{
- if(locator != null && servant != null)
- {
- assert(_adapter != null);
- locator.finished(_current, servant, _cookie.value);
- }
-
- _is.endReadEncaps();
- if(response)
- {
- _os.endWriteEncaps();
- _os.resize(statusPos, false);
- _os.writeByte(
- (byte)DispatchStatus._DispatchUnknownUserException);
- }
-
- throw ex;
- }
- */
+ // ...
+ }
+ */
catch(RuntimeException ex)
{
if(locator != null && servant != null)
{
- assert(_adapter != null);
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
+
if(response)
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
_os.writeByte((byte)DispatchStatus._DispatchUnknownException);
+ _os.writeString(ex.toString());
}
-
- // Rethrow, so that the caller can print a warning.
- throw ex;
+
+ return;
}
+
+ if(locator != null && servant != null)
+ {
+ locator.finished(_current, servant, _cookie.value);
+ }
+
+ _is.endReadEncaps();
+
+ if(response)
+ {
+ _os.endWriteEncaps();
+
+ if(status != DispatchStatus.DispatchOK && status != DispatchStatus.DispatchUserException)
+ {
+ assert(status == DispatchStatus.DispatchObjectNotExist ||
+ status == DispatchStatus.DispatchFacetNotExist ||
+ status == DispatchStatus.DispatchOperationNotExist);
+
+ _os.resize(statusPos, false);
+ _os.writeByte((byte)status.value());
+
+ _current.id.__write(_os);
+ _os.writeStringSeq(_current.facet);
+ _os.writeString(_current.operation);
+ }
+ else
+ {
+ int save = _os.pos();
+ _os.pos(statusPos);
+ _os.writeByte((byte)status.value());
+ _os.pos(save);
+ }
+ }
}
public BasicStream
@@ -284,31 +308,6 @@ public class Incoming
return _os;
}
- //
- // reset() allows this object to be reused, rather than reallocated
- //
- public void
- reset()
- {
- _is.reset();
- _os.reset();
- if(_current.ctx != null)
- {
- _current.ctx.clear();
- }
- }
-
- //
- // Reclaim resources
- //
- public void
- destroy()
- {
- _is.destroy();
- _os.destroy();
- }
-
- private Ice.ObjectAdapter _adapter;
private BasicStream _is;
private BasicStream _os;
private Ice.Current _current;
diff --git a/java/src/IceInternal/IncomingConnectionFactory.java b/java/src/IceInternal/IncomingConnectionFactory.java
index a83981d70c4..60b9b7d4e76 100644
--- a/java/src/IceInternal/IncomingConnectionFactory.java
+++ b/java/src/IceInternal/IncomingConnectionFactory.java
@@ -174,13 +174,10 @@ public class IncomingConnectionFactory extends EventHandler
_acceptor.close();
//
- // Break cyclic object dependency. This is necessary,
- // because the object adapter never clears the list of
- // incoming connections it keeps.
+ // We don't need the adapter anymore after we closed the
+ // acceptor.
//
_adapter = null;
-
- notifyAll(); // For waitUntilFinished().
}
}
@@ -228,12 +225,10 @@ public class IncomingConnectionFactory extends EventHandler
Connection connection = new Connection(_instance, _transceiver, _endpoint, _adapter);
connection.validate();
_connections.add(connection);
-
+
//
// We don't need an adapter anymore if we don't use an
- // acceptor. So we break cyclic object dependency
- // now. This is necessary, because the object adapter
- // never clears the list of incoming connections it keeps.
+ // acceptor.
//
_adapter = null;
}
@@ -275,21 +270,6 @@ public class IncomingConnectionFactory extends EventHandler
setState(StateClosed);
}
- public synchronized void
- waitUntilFinished()
- {
- while(_state != StateClosed || _adapter != null)
- {
- try
- {
- wait();
- }
- catch(InterruptedException ex)
- {
- }
- }
- }
-
private static final int StateActive = 0;
private static final int StateHolding = 1;
private static final int StateClosed = 2;
diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java
index 3b038c26dd4..6700e4c849d 100644
--- a/java/src/IceInternal/Outgoing.java
+++ b/java/src/IceInternal/Outgoing.java
@@ -29,7 +29,6 @@ public final class Outgoing
{
_state = StateUnsent;
_exception = null;
- _fillStackTrace = false;
_is.reset();
_os.reset();
@@ -120,16 +119,6 @@ public final class Outgoing
}
//
- // If _fillStackTrace is true, then we want to update
- // the exception's stack trace to reflect the calling
- // thread.
- //
- if(_fillStackTrace)
- {
- _exception.fillInStackTrace();
- }
-
- //
// Throw the exception wrapped in a NonRepeatable, to
// indicate that the request cannot be resent without
// potentially violating the "at-most-once" principle.
@@ -187,6 +176,7 @@ public final class Outgoing
{
_is.swap(is);
byte status = _is.readByte();
+
switch((int)status)
{
case DispatchStatus._DispatchOK:
@@ -258,43 +248,57 @@ public final class Outgoing
ex.facet = _is.readStringSeq();
ex.operation = _is.readString();
_exception = ex;
- _fillStackTrace = true;
break;
}
+ case DispatchStatus._DispatchUnknownException:
case DispatchStatus._DispatchUnknownLocalException:
- {
- _state = StateLocalException;
- _exception = new Ice.UnknownLocalException();
- _fillStackTrace = true;
- break;
- }
-
case DispatchStatus._DispatchUnknownUserException:
{
- _state = StateLocalException;
- _exception = new Ice.UnknownUserException();
- _fillStackTrace = true;
- break;
- }
+ _state = StateLocalException;
- case DispatchStatus._DispatchUnknownException:
- {
- _state = StateLocalException;
- _exception = new Ice.UnknownException();
- _fillStackTrace = true;
+ Ice.UnknownException ex = null;
+ switch((int)status)
+ {
+ case DispatchStatus._DispatchUnknownException:
+ {
+ ex = new Ice.UnknownException();
+ break;
+ }
+
+ case DispatchStatus._DispatchUnknownLocalException:
+ {
+ ex = new Ice.UnknownLocalException();
+ break;
+ }
+
+ case DispatchStatus._DispatchUnknownUserException:
+ {
+ ex = new Ice.UnknownUserException();
+ break;
+ }
+
+ default:
+ {
+ assert(false);
+ break;
+ }
+ }
+
+ ex.unknown = _is.readString();
+ _exception = ex;
break;
}
-
+
default:
{
_state = StateLocalException;
_exception = new Ice.UnknownReplyStatusException();
- _fillStackTrace = true;
break;
}
}
}
+
notify();
}
@@ -377,7 +381,6 @@ public final class Outgoing
private Connection _connection;
private Reference _reference;
private Ice.LocalException _exception;
- private boolean _fillStackTrace;
private static final int StateUnsent = 0;
private static final int StateInProgress = 1;
diff --git a/java/src/IceInternal/TraceUtil.java b/java/src/IceInternal/TraceUtil.java
index 4ebb46a776c..85fbf8ba5f5 100644
--- a/java/src/IceInternal/TraceUtil.java
+++ b/java/src/IceInternal/TraceUtil.java
@@ -19,9 +19,11 @@ final class TraceUtil
{
int p = str.pos();
str.pos(0);
+
java.io.StringWriter s = new java.io.StringWriter();
s.write(heading);
printHeader(s, str);
+
logger.trace(tl.protocolCat, s.toString());
str.pos(p);
}
@@ -34,16 +36,20 @@ final class TraceUtil
{
int p = str.pos();
str.pos(0);
+
java.io.StringWriter s = new java.io.StringWriter();
s.write(heading);
printHeader(s, str);
+
int requestId = str.readInt();
s.write("\nrequest id = " + requestId);
if(requestId == 0)
{
s.write(" (oneway)");
}
+
printRequestHeader(s, str);
+
logger.trace(tl.protocolCat, s.toString());
str.pos(p);
}
@@ -56,9 +62,11 @@ final class TraceUtil
{
int p = str.pos();
str.pos(0);
+
java.io.StringWriter s = new java.io.StringWriter();
s.write(heading);
printHeader(s, str);
+
int cnt = 0;
while(str.pos() != str.size())
{
@@ -67,6 +75,7 @@ final class TraceUtil
printRequestHeader(s, str);
str.skipEncaps();
}
+
logger.trace(tl.protocolCat, s.toString());
str.pos(p);
}
@@ -79,13 +88,17 @@ final class TraceUtil
{
int p = str.pos();
str.pos(0);
+
java.io.StringWriter s = new java.io.StringWriter();
s.write(heading);
printHeader(s, str);
+
int requestId = str.readInt();
s.write("\nrequest id = " + requestId);
+
byte status = str.readByte();
s.write("\nreply status = " + (int)status + ' ');
+
switch(status)
{
case DispatchStatus._DispatchOK:
@@ -93,47 +106,97 @@ final class TraceUtil
s.write("(ok)");
break;
}
+
case DispatchStatus._DispatchUserException:
{
s.write("(user exception)");
break;
}
+
case DispatchStatus._DispatchLocationForward:
{
s.write("(location forward)");
break;
}
+
case DispatchStatus._DispatchObjectNotExist:
- {
- s.write("(object not exist)");
- break;
- }
case DispatchStatus._DispatchFacetNotExist:
- {
- s.write("(facet not exist)");
- break;
- }
case DispatchStatus._DispatchOperationNotExist:
{
- s.write("(operation not exist)");
- break;
- }
- case DispatchStatus._DispatchUnknownLocalException:
- {
- s.write("(unknown local exception)");
- break;
- }
- case DispatchStatus._DispatchUnknownException:
- {
- s.write("(unknown exception)");
- break;
+ switch(status)
+ {
+ case DispatchStatus._DispatchObjectNotExist:
+ {
+ s.write("(object not exist)");
+ break;
+ }
+
+ case DispatchStatus._DispatchFacetNotExist:
+ {
+ s.write("(facet not exist)");
+ break;
+ }
+
+ case DispatchStatus._DispatchOperationNotExist:
+ {
+ s.write("(operation not exist)");
+ break;
+ }
+
+ default:
+ {
+ assert(false);
+ break;
+ }
+ }
+
+ printIdentityFacetOperation(s, str);
+ break;
}
+
+ case DispatchStatus._DispatchUnknownException:
+ case DispatchStatus._DispatchUnknownLocalException:
+ case DispatchStatus._DispatchUnknownUserException:
+ {
+ switch(status)
+ {
+ case DispatchStatus._DispatchUnknownException:
+ {
+ s.write("(unknown exception)");
+ break;
+ }
+
+ case DispatchStatus._DispatchUnknownLocalException:
+ {
+ s.write("(unknown local exception)");
+ break;
+ }
+
+ case DispatchStatus._DispatchUnknownUserException:
+ {
+ s.write("(unknown user exception)");
+ break;
+ }
+
+ default:
+ {
+ assert(false);
+ break;
+ }
+ }
+
+ String unknown = str.readString();
+ s.write("\nunknown = " + unknown);
+ break;
+ }
+
default:
{
s.write("(unknown)");
break;
}
}
+
logger.trace(tl.protocolCat, s.toString());
str.pos(p);
}
@@ -209,14 +272,77 @@ final class TraceUtil
}
private static void
+ printIdentityFacetOperation(java.io.Writer out, BasicStream stream)
+ {
+ try
+ {
+ Ice.Identity identity = new Ice.Identity();
+ identity.__read(stream);
+ out.write("\nidentity = " + Ice.Util.identityToString(identity));
+
+ String[] facet = stream.readStringSeq();
+ out.write("\nfacet = ");
+ for(int i = 0; i < facet.length ; i++)
+ {
+ //
+ // TODO: Escape for whitespace and slashes.
+ //
+ out.write(facet[i]);
+ if(i < facet.length - 1)
+ {
+ out.write('/');
+ }
+ }
+
+ String operation = stream.readString();
+ out.write("\noperation = " + operation);
+ }
+ catch(java.io.IOException ex)
+ {
+ assert(false);
+ }
+ }
+
+ private static void
+ printRequestHeader(java.io.Writer out, BasicStream stream)
+ {
+ printIdentityFacetOperation(out, stream);
+
+ try
+ {
+ boolean nonmutating = stream.readBool();
+ out.write("\nnonmutating = " + nonmutating);
+
+ int sz = stream.readSize();
+ out.write("\ncontext = ");
+ while(sz-- > 0)
+ {
+ String key = stream.readString();
+ String value = stream.readString();
+ out.write(key + '/'+ value);
+ if(sz > 0)
+ {
+ out.write(", ");
+ }
+ }
+ }
+ catch(java.io.IOException ex)
+ {
+ assert(false);
+ }
+ }
+
+ private static void
printHeader(java.io.Writer out, BasicStream stream)
{
try
{
byte protVer = stream.readByte();
// out.write("\nprotocol version = " + (int)protVer);
+
byte encVer = stream.readByte();
// out.write("\nencoding version = " + (int)encVer);
+
byte type = stream.readByte();
out.write("\nmessage type = " + (int)type + ' ');
switch(type)
@@ -226,32 +352,38 @@ final class TraceUtil
out.write("(request)");
break;
}
+
case Protocol.requestBatchMsg:
{
out.write("(batch request)");
break;
}
+
case Protocol.replyMsg:
{
out.write("(reply)");
break;
}
+
case Protocol.closeConnectionMsg:
{
out.write("(close connection)");
- break;
+ break;
}
+
case Protocol.validateConnectionMsg:
{
out.write("(validate connection)");
break;
}
+
default:
{
out.write("(unknown)");
break;
}
}
+
int size = stream.readInt();
out.write("\nmessage size = " + size);
}
@@ -260,48 +392,4 @@ final class TraceUtil
assert(false);
}
}
-
- private static void
- printRequestHeader(java.io.Writer out, BasicStream stream)
- {
- try
- {
- Ice.Identity identity = new Ice.Identity();
- identity.__read(stream);
- out.write("\nidentity = " + Ice.Util.identityToString(identity));
- String[] facet = stream.readStringSeq();
- out.write("\nfacet = ");
- for(int i = 0; i < facet.length ; i++)
- {
- //
- // TODO: Escape for whitespace and slashes.
- //
- out.write(facet[i]);
- if(i < facet.length - 1)
- {
- out.write('/');
- }
- }
- String operation = stream.readString();
- out.write("\noperation = " + operation);
- boolean nonmutating = stream.readBool();
- out.write("\nnonmutating = " + nonmutating);
- int sz = stream.readSize();
- out.write("\ncontext = ");
- while(sz-- > 0)
- {
- String key = stream.readString();
- String value = stream.readString();
- out.write(key + '/'+ value);
- if(sz > 0)
- {
- out.write(", ");
- }
- }
- }
- catch(java.io.IOException ex)
- {
- assert(false);
- }
- }
}