diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-12-12 18:54:19 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-12-12 18:54:19 +0100 |
commit | 3dff2b82d498d2e29dc4c42c4053557e16a373d4 (patch) | |
tree | 4242da8678ce8f36e34b9d821212cf78519af415 /java/src/IceInternal/OutgoingAsyncMessageCallback.java | |
parent | Merge branch 'master' of ssh://cvs.zeroc.com/home/git/ice (diff) | |
download | ice-3dff2b82d498d2e29dc4c42c4053557e16a373d4.tar.bz2 ice-3dff2b82d498d2e29dc4c42c4053557e16a373d4.tar.xz ice-3dff2b82d498d2e29dc4c42c4053557e16a373d4.zip |
Fixed bug 2592
Diffstat (limited to 'java/src/IceInternal/OutgoingAsyncMessageCallback.java')
-rw-r--r-- | java/src/IceInternal/OutgoingAsyncMessageCallback.java | 138 |
1 files changed, 135 insertions, 3 deletions
diff --git a/java/src/IceInternal/OutgoingAsyncMessageCallback.java b/java/src/IceInternal/OutgoingAsyncMessageCallback.java index 2575dd33b38..677075f59e9 100644 --- a/java/src/IceInternal/OutgoingAsyncMessageCallback.java +++ b/java/src/IceInternal/OutgoingAsyncMessageCallback.java @@ -9,8 +9,140 @@ package IceInternal; -public interface OutgoingAsyncMessageCallback +abstract public class OutgoingAsyncMessageCallback { - void __sent(Ice.ConnectionI connection); - void __finished(Ice.LocalException ex); + public abstract void __sent(Ice.ConnectionI connection); + public abstract void __finished(Ice.LocalException ex); + public abstract void ice_exception(Ice.LocalException ex); + + public final BasicStream + __os() + { + return __os; + } + + public void + __exception(Ice.LocalException exc) + { + try + { + ice_exception(exc); + } + catch(java.lang.Exception ex) + { + __warning(ex); + } + finally + { + __release(); + } + } + + protected synchronized void + finalize() + throws Throwable + { + assert(__os == null); + assert(__is == null); + } + + protected void + __acquire(Ice.ObjectPrx proxy) + { + synchronized(__monitor) + { + // + // We must first wait for other requests to finish. + // + while(__os != null) + { + try + { + __monitor.wait(); + } + catch(InterruptedException ex) + { + } + } + + Reference ref = ((Ice.ObjectPrxHelperBase)proxy).__reference(); + assert(__is == null); + __is = new BasicStream(ref.getInstance()); + assert(__os == null); + __os = new BasicStream(ref.getInstance()); + } + } + + protected void + __release(final Ice.LocalException ex) + { + synchronized(__monitor) + { + assert(__os != null); + + // + // This is called by the invoking thread to release the callback following a direct + // failure to marhsall/send the request. We call the ice_exception() callback with + // the thread pool to avoid potential deadlocks in case the invoking thread locked + // some mutexes/resources (which couldn't be re-acquired by the callback). + // + + try + { + __os.instance().clientThreadPool().execute(new ThreadPoolWorkItem() + { + public void + execute(ThreadPool threadPool) + { + threadPool.promoteFollower(); + __exception(ex); + } + }); + } + catch(Ice.CommunicatorDestroyedException exc) + { + __release(); + throw exc; // CommunicatorDestroyedException is the only exception that can propagate directly. + } + } + } + + protected void + __release() + { + synchronized(__monitor) + { + assert(__is != null); + __is = null; + + assert(__os != null); + __os = null; + + __monitor.notify(); + } + } + + protected void + __warning(java.lang.Exception ex) + { + if(__os != null) // Don't print anything if release() was already called. + { + Instance instance = __os.instance(); + if(instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.AMICallback", 1) > 0) + { + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + IceUtil.OutputBase out = new IceUtil.OutputBase(pw); + out.setUseTab(false); + out.print("exception raised by AMI callback:\n"); + ex.printStackTrace(pw); + pw.flush(); + instance.initializationData().logger.warning(sw.toString()); + } + } + } + + protected final java.lang.Object __monitor = new java.lang.Object(); + protected BasicStream __is; + protected BasicStream __os; };
\ No newline at end of file |