diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-11-23 13:28:08 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-11-23 13:28:08 +0100 |
commit | 2c578015edcb36cdc0acd0227295de1dcca1b995 (patch) | |
tree | e163980b5dabb43a40089a29fdf8ff47a3e07f1c /java/src | |
parent | no longer generating inspect method for each Ruby exception (diff) | |
download | ice-2c578015edcb36cdc0acd0227295de1dcca1b995.tar.bz2 ice-2c578015edcb36cdc0acd0227295de1dcca1b995.tar.xz ice-2c578015edcb36cdc0acd0227295de1dcca1b995.zip |
New AMI mapping
Diffstat (limited to 'java/src')
32 files changed, 2394 insertions, 637 deletions
diff --git a/java/src/Ice/AMI_Object_ice_flushBatchRequests.java b/java/src/Ice/AMI_Object_ice_flushBatchRequests.java index 211f002b9d6..5093553469b 100644 --- a/java/src/Ice/AMI_Object_ice_flushBatchRequests.java +++ b/java/src/Ice/AMI_Object_ice_flushBatchRequests.java @@ -12,7 +12,7 @@ package Ice; /** * Callback object for {@link ObjectPrx#.ice_flushBatchRequests_async}. **/ -public abstract class AMI_Object_ice_flushBatchRequests extends IceInternal.BatchOutgoingAsync +public abstract class AMI_Object_ice_flushBatchRequests extends Callback_Object_ice_flushBatchRequests { /** * Indicates to the caller that a call to <code>ice_flushBatchRequests_async</code> @@ -24,31 +24,16 @@ public abstract class AMI_Object_ice_flushBatchRequests extends IceInternal.Batc **/ public abstract void ice_exception(LocalException ex); - public final boolean __invoke(Ice.ObjectPrx prx) + public final void exception(LocalException ex) { - __acquireCallback(prx); - try - { - // - // We don't automatically retry if ice_flushBatchRequests fails. Otherwise, if some batch - // requests were queued with the connection, they would be lost without being noticed. - // - Ice._ObjectDel delegate = null; - Ice.ObjectPrxHelperBase proxy = (Ice.ObjectPrxHelperBase)prx; - try - { - delegate = proxy.__getDelegate(true); - return delegate.__getRequestHandler().flushAsyncBatchRequests(this); - } - catch(Ice.LocalException ex) - { - proxy.__handleException(delegate, ex, null, -1); // Don't retry - } - } - catch(Ice.LocalException ex) + ice_exception(ex); + } + + public final void sent() + { + if(this instanceof AMISentCallback) { - __releaseCallback(ex); + ((AMISentCallback)this).ice_sent(); } - return false; } } diff --git a/java/src/Ice/AMI_Object_ice_invoke.java b/java/src/Ice/AMI_Object_ice_invoke.java index 097ba8258c8..8b273f4caab 100644 --- a/java/src/Ice/AMI_Object_ice_invoke.java +++ b/java/src/Ice/AMI_Object_ice_invoke.java @@ -10,15 +10,12 @@ package Ice; /** - * Callback object for {@link Blobject} AMI invocations. - * - * @see Blobject + * Callback object for {@link ObjectPrx#.ice_invoke_async}. **/ -public abstract class AMI_Object_ice_invoke extends IceInternal.OutgoingAsync +public abstract class AMI_Object_ice_invoke extends Callback_Object_ice_invoke { /** - * The Ice run time calls <code>ice_response</code> when an asynchronous operation invocation - * completes successfully or raises a user exception. + * Called when an asynchronous operation invocation completes successfully or raises a user exception. * * @param ok Indicates the result of the invocation. If <code>true</code>, the operation * completed succesfully; if <code>false</code>, the operation raised a user exception. @@ -29,50 +26,27 @@ public abstract class AMI_Object_ice_invoke extends IceInternal.OutgoingAsync public abstract void ice_response(boolean ok, byte[] outParams); /** - * The Ice run time calls <code>ice_exception</code> when an asynchronous operation invocation - * raises an Ice run-time exception. + * Called when the invocation raises an Ice run-time exception. * - * @param ex The encoded Ice run-time exception raised by the operation. + * @param ex The Ice run-time exception raised by the operation. **/ public abstract void ice_exception(LocalException ex); - public final boolean __invoke(Ice.ObjectPrx prx, String operation, OperationMode mode, - byte[] inParams, java.util.Map<String, String> context) + public final void response(boolean ok, byte[] outParams) { - __acquireCallback(prx); - try - { - __prepare(prx, operation, mode, context); - if(inParams != null) - { - __os.writeBlob(inParams); - } - __os.endWriteEncaps(); - return __send(); - } - catch(LocalException ex) - { - __releaseCallback(ex); - return false; - } + ice_response(ok, outParams); } - protected final void __response(boolean ok) // ok == true means no user exception. + public final void exception(LocalException ex) { - byte[] outParams; - try - { - __is.startReadEncaps(); - int sz = __is.getReadEncapsSize(); - outParams = __is.readBlob(sz); - __is.endReadEncaps(); - } - catch(LocalException ex) + ice_exception(ex); + } + + public final void sent() + { + if(this instanceof AMISentCallback) { - __finished(ex); - return; + ((AMISentCallback)this).ice_sent(); } - ice_response(ok, outParams); - __releaseCallback(); } } diff --git a/java/src/Ice/AsyncCallback.java b/java/src/Ice/AsyncCallback.java new file mode 100644 index 00000000000..a5bb1a17a13 --- /dev/null +++ b/java/src/Ice/AsyncCallback.java @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * An application can optionally supply an instance of this class in an + * asynchronous invocation. The application must create a subclass and + * implement the completed method. + **/ +public abstract class AsyncCallback extends Callback +{ + /** + * Invoked when the invocation completes. The subclass should + * call the matching <code>end_OP</code> method on the proxy and + * must be prepared to handle exceptions. + * + * @param r The asynchronous result object returned by the <code>begin_OP</code> method. + **/ + public abstract void completed(AsyncResult r); + + /** + * Invoked when the Ice run time has passed the outgoing message + * buffer to the transport. + * + * @param r The asynchronous result object returned by the <code>begin_OP</code> method. + **/ + public void sent(AsyncResult r) + { + } + + public final void __completed(AsyncResult r) + { + completed(r); + } + + public final void __sent(AsyncResult r) + { + sent(r); + } +} diff --git a/java/src/Ice/AsyncResult.java b/java/src/Ice/AsyncResult.java new file mode 100644 index 00000000000..a006a83f511 --- /dev/null +++ b/java/src/Ice/AsyncResult.java @@ -0,0 +1,311 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public class AsyncResult +{ + protected AsyncResult(IceInternal.Instance instance, String op, IceInternal.CallbackBase del) + { + _instance = instance; + _operation = op; + _is = new IceInternal.BasicStream(instance); + _os = new IceInternal.BasicStream(instance); + _state = 0; + _exception = null; + _callback = del; + } + + public Communicator getCommunicator() + { + return null; + } + + public Connection getConnection() + { + return null; + } + + public ObjectPrx getProxy() + { + return null; + } + + public final boolean isCompleted() + { + synchronized(_monitor) + { + return (_state & Done) > 0; + } + } + + public final void waitForCompleted() + { + synchronized(_monitor) + { + while((_state & Done) == 0) + { + try + { + _monitor.wait(); + } + catch(InterruptedException ex) + { + } + } + } + } + + public final boolean isSent() + { + synchronized(_monitor) + { + return (_state & (Sent | Done)) > 0; + } + } + + public final void waitForSent() + { + synchronized(_monitor) + { + while((_state & (Sent | Done)) == 0) + { + try + { + _monitor.wait(); + } + catch(InterruptedException ex) + { + } + } + } + } + + public final boolean sentSynchronously() + { + return _sentSynchronously; // No lock needed, immutable once __send() is called + } + + public final String getOperation() + { + return _operation; + } + + public final IceInternal.BasicStream __os() + { + return _os; + } + + public final IceInternal.BasicStream __is() + { + return _is; + } + + public final boolean __wait() + { + synchronized(_monitor) + { + if((_state & EndCalled) > 0) + { + throw new java.lang.IllegalArgumentException("end_ method called more than once"); + } + _state |= EndCalled; + while((_state & Done) == 0) + { + try + { + _monitor.wait(); + } + catch(InterruptedException ex) + { + } + } + if(_exception != null) + { + throw (LocalException)_exception.fillInStackTrace(); // TODO: Correct? + } + return (_state & OK) > 0; + } + } + + public final void __throwUserException() + throws UserException + { + try + { + _is.startReadEncaps(); + _is.throwException(); + } + catch(UserException ex) + { + _is.endReadEncaps(); + throw ex; + } + } + + public final void __exceptionAsync(final LocalException ex) + { + // + // This is called when it's not safe to call the exception callback synchronously + // from this thread. Instead the exception callback is called asynchronously from + // the client thread pool. + // + try + { + _instance.clientThreadPool().execute(new IceInternal.ThreadPoolWorkItem() + { + public void + execute(IceInternal.ThreadPoolCurrent current) + { + current.ioCompleted(); + __exception(ex); + } + }); + } + catch(CommunicatorDestroyedException exc) + { + throw exc; // CommunicatorDestroyedException is the only exception that can propagate directly. + } + } + + public static void __check(AsyncResult r, ObjectPrx prx, String operation) + { + __check(r, operation); + if(r.getProxy() != prx) + { + throw new IllegalArgumentException("Proxy for call to end_" + operation + + " does not match proxy that was used to call corresponding begin_" + + operation + " method"); + } + } + + public static void __check(AsyncResult r, Connection con, String operation) + { + __check(r, operation); + if(r.getConnection() != con) + { + throw new IllegalArgumentException("Connection for call to end_" + operation + + " does not match connection that was used to call corresponding begin_" + + operation + " method"); + } + } + + public static void __check(AsyncResult r, Communicator com, String operation) + { + __check(r, operation); + if(r.getCommunicator() != com) + { + throw new IllegalArgumentException("Communicator for call to end_" + operation + + " does not match communicator that was used to call corresponding " + + "begin_" + operation + " method"); + } + } + + public final void __exception(LocalException ex) + { + synchronized(_monitor) + { + _state |= Done; + _exception = ex; + _monitor.notifyAll(); + } + + if(_callback != null) + { + try + { + _callback.__completed(this); + } + catch(RuntimeException exc) + { + __warning(exc); + } + } + } + + protected static void __check(AsyncResult r, String operation) + { + if(r == null) + { + throw new IllegalArgumentException("AsyncResult == null"); + } + else if(r.getOperation() != operation) // Do NOT use equals() here - we are comparing reference equality + { + throw new IllegalArgumentException("Incorrect operation for end_" + operation + " method: " + + r.getOperation()); + } + } + + protected final void __sentInternal() + { + // + // Note: no need to change the _state here, specializations are responsible for + // changing the state. + // + + if(_callback != null) + { + try + { + _callback.__sent(this); + } + catch(RuntimeException ex) + { + __warning(ex); + } + } + } + + protected final void __response() + { + // + // Note: no need to change the _state here, specializations are responsible for + // changing the state. + // + + if(_callback != null) + { + try + { + _callback.__completed(this); + } + catch(RuntimeException ex) + { + __warning(ex); + } + } + } + + protected final void __warning(RuntimeException ex) + { + if(_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.AMICallback", 1) > 0) + { + String s = "exception raised by AMI callback:\n" + IceInternal.Ex.toString(ex); + _instance.initializationData().logger.warning(s); + } + } + + protected IceInternal.Instance _instance; + protected String _operation; + + protected java.lang.Object _monitor = new java.lang.Object(); + protected IceInternal.BasicStream _is; + protected IceInternal.BasicStream _os; + + protected static final byte OK = 0x1; + protected static final byte Done = 0x2; + protected static final byte Sent = 0x4; + protected static final byte EndCalled = 0x8; + + protected byte _state; + protected boolean _sentSynchronously; + protected LocalException _exception; + + private IceInternal.CallbackBase _callback; +} diff --git a/java/src/Ice/Callback.java b/java/src/Ice/Callback.java new file mode 100644 index 00000000000..5375fdc8f70 --- /dev/null +++ b/java/src/Ice/Callback.java @@ -0,0 +1,19 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * An application can optionally supply an instance of this class in an + * asynchronous invocation. The application must create a subclass and + * implement the completed method. + **/ +public abstract class Callback extends IceInternal.CallbackBase +{ +} diff --git a/java/src/Ice/Callback_Object_ice_flushBatchRequests.java b/java/src/Ice/Callback_Object_ice_flushBatchRequests.java new file mode 100644 index 00000000000..423d7104992 --- /dev/null +++ b/java/src/Ice/Callback_Object_ice_flushBatchRequests.java @@ -0,0 +1,17 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Callback object for {@link ObjectPrx#.begin_ice_flushBatchRequests}. + **/ +public abstract class Callback_Object_ice_flushBatchRequests extends OnewayCallback +{ +} diff --git a/java/src/Ice/Callback_Object_ice_id.java b/java/src/Ice/Callback_Object_ice_id.java new file mode 100644 index 00000000000..88814d2b0db --- /dev/null +++ b/java/src/Ice/Callback_Object_ice_id.java @@ -0,0 +1,38 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Callback object for {@link ObjectPrx#.begin_ice_id}. + **/ +public abstract class Callback_Object_ice_id extends TwowayCallback +{ + /** + * Called when the invocation completes successfully. + * + * @param __ret The Slice type id of the most-derived interface supported by the target object. + **/ + public abstract void response(String __ret); + + public final void __completed(AsyncResult __result) + { + String __ret = null; + try + { + __ret = __result.getProxy().end_ice_id(__result); + } + catch(LocalException __ex) + { + exception(__ex); + return; + } + response(__ret); + } +} diff --git a/java/src/Ice/Callback_Object_ice_ids.java b/java/src/Ice/Callback_Object_ice_ids.java new file mode 100644 index 00000000000..b1ce3a7e084 --- /dev/null +++ b/java/src/Ice/Callback_Object_ice_ids.java @@ -0,0 +1,38 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Callback object for {@link ObjectPrx#.begin_ice_ids}. + **/ +public abstract class Callback_Object_ice_ids extends TwowayCallback +{ + /** + * Called when the invocation completes successfully. + * + * @param __ret The Slice type ids of the interfaces supported by the target object. + **/ + public abstract void response(String[] __ret); + + public final void __completed(AsyncResult __result) + { + String[] __ret = null; + try + { + __ret = __result.getProxy().end_ice_ids(__result); + } + catch(LocalException __ex) + { + exception(__ex); + return; + } + response(__ret); + } +} diff --git a/java/src/Ice/Callback_Object_ice_invoke.java b/java/src/Ice/Callback_Object_ice_invoke.java new file mode 100644 index 00000000000..14e0287cd4a --- /dev/null +++ b/java/src/Ice/Callback_Object_ice_invoke.java @@ -0,0 +1,44 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Callback object for {@link ObjectPrx#.begin_ice_invoke}. + **/ +public abstract class Callback_Object_ice_invoke extends TwowayCallback +{ + /** + * The Ice run time calls <code>response</code> when an asynchronous operation invocation + * completes successfully or raises a user exception. + * + * @param __ret Indicates the result of the invocation. If <code>true</code>, the operation + * completed succesfully; if <code>false</code>, the operation raised a user exception. + * @param outParams Contains the encoded out-parameters of the operation (if any) if <code>ok</code> + * is <code>true</code>; otherwise, if <code>ok</code> is <code>false</code>, contains the + * encoded user exception raised by the operation. + **/ + public abstract void response(boolean __ret, byte[] outParams); + + public final void __completed(AsyncResult __result) + { + ByteSeqHolder outParams = new ByteSeqHolder(); + boolean __ret = false; + try + { + __ret = __result.getProxy().end_ice_invoke(outParams, __result); + } + catch(LocalException __ex) + { + exception(__ex); + return; + } + response(__ret, outParams.value); + } +} diff --git a/java/src/Ice/Callback_Object_ice_isA.java b/java/src/Ice/Callback_Object_ice_isA.java new file mode 100644 index 00000000000..6b13c145a20 --- /dev/null +++ b/java/src/Ice/Callback_Object_ice_isA.java @@ -0,0 +1,38 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Callback object for {@link ObjectPrx#.begin_ice_isA}. + **/ +public abstract class Callback_Object_ice_isA extends TwowayCallback +{ + /** + * Called when the invocation completes successfully. + * + * @param __ret True if the target object supports the given interface, false otherwise. + **/ + public abstract void response(boolean __ret); + + public final void __completed(AsyncResult __result) + { + boolean __ret = false; + try + { + __ret = __result.getProxy().end_ice_isA(__result); + } + catch(LocalException __ex) + { + exception(__ex); + return; + } + response(__ret); + } +} diff --git a/java/src/Ice/Callback_Object_ice_ping.java b/java/src/Ice/Callback_Object_ice_ping.java new file mode 100644 index 00000000000..3fa50fd5078 --- /dev/null +++ b/java/src/Ice/Callback_Object_ice_ping.java @@ -0,0 +1,17 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Callback object for {@link ObjectPrx#.begin_ice_ping}. + **/ +public abstract class Callback_Object_ice_ping extends OnewayCallback +{ +} diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index 01f86f523f6..f1cbcd0723d 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -324,7 +324,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne boolean sent = false; try { - sent = sendMessage(new OutgoingMessage(out, out.os(), compress, response)); + sent = sendMessage(new OutgoingMessage(out, out.os(), compress, requestId)); } catch(Ice.LocalException ex) { @@ -392,7 +392,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne boolean sent; try { - sent = sendMessage(new OutgoingMessage(out, out.__os(), compress, response)); + sent = sendMessage(new OutgoingMessage(out, out.__os(), compress, requestId)); } catch(Ice.LocalException ex) { @@ -652,7 +652,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne boolean sent = false; try { - OutgoingMessage message = new OutgoingMessage(out, out.os(), _batchRequestCompress, false); + OutgoingMessage message = new OutgoingMessage(out, out.os(), _batchRequestCompress, 0); sent = sendMessage(message); } catch(Ice.LocalException ex) @@ -708,7 +708,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne boolean sent; try { - OutgoingMessage message = new OutgoingMessage(outAsync, outAsync.__os(), _batchRequestCompress, false); + OutgoingMessage message = new OutgoingMessage(outAsync, outAsync.__os(), _batchRequestCompress, 0); sent = sendMessage(message); } catch(Ice.LocalException ex) @@ -1081,7 +1081,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne { for(OutgoingMessage msg : sentCBs) { - msg.outAsync.__sent(_instance); + msg.outAsync.__sent(); } } @@ -1136,21 +1136,39 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne _startCallback = null; } + // + // NOTE: for twoway requests which are not sent, finished can be called twice: the + // first time because the outgoing is in the _sendStreams set and the second time + // because it's either in the _requests/_asyncRequests set. This is fine, only the + // first call should be taken into account by the implementation of finished. + // + for(OutgoingMessage p : _sendStreams) { + if(p.requestId > 0) + { + if(p.out != null) // Make sure finished isn't called twice. + { + _requests.remove(p.requestId); + } + else + { + _asyncRequests.remove(p.requestId); + } + } p.finished(_exception); } _sendStreams.clear(); for(IceInternal.Outgoing p : _requests.values()) { - p.finished(_exception); + p.finished(_exception, true); } _requests.clear(); for(IceInternal.OutgoingAsync p : _asyncRequests.values()) { - p.__finished(_exception); + p.__finished(_exception, true); } _asyncRequests.clear(); @@ -1769,8 +1787,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne // OutgoingMessage message = _sendStreams.getFirst(); _writeStream.swap(message.stream); - message.sent(this, true); - if(message.outAsync instanceof Ice.AMISentCallback) + if(message.sent(this, true)) { callbacks.add(message); } @@ -2388,24 +2405,28 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne this.stream = stream; this.compress = compress; this.adopt = adopt; + this.isSent = false; + this.requestId = 0; } OutgoingMessage(IceInternal.OutgoingMessageCallback out, IceInternal.BasicStream stream, boolean compress, - boolean resp) + int requestId) { this.stream = stream; this.compress = compress; this.out = out; - this.response = resp; + this.requestId = requestId; + this.isSent = false; } OutgoingMessage(IceInternal.OutgoingAsyncMessageCallback out, IceInternal.BasicStream stream, boolean compress, - boolean resp) + int requestId) { this.stream = stream; this.compress = compress; this.outAsync = out; - this.response = resp; + this.requestId = requestId; + this.isSent = false; } public void @@ -2420,37 +2441,36 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne } } - public void + public boolean sent(ConnectionI connection, boolean notify) { + isSent = true; // The message is sent. + if(out != null) { out.sent(notify); // true = notify the waiting thread that the request was sent. + return false; } else if(outAsync != null) { - outAsync.__sent(connection); + return outAsync.__sent(connection); + } + else + { + return false; } } public void finished(Ice.LocalException ex) { - // - // Only notify oneway requests. The connection keeps track of twoway - // requests in the _requests/_asyncRequests maps and will notify them - // of the connection exceptions. - // - if(!response) + if(out != null) { - if(out != null) - { - out.finished(ex); - } - else if(outAsync != null) - { - outAsync.__finished(ex); - } + out.finished(ex, isSent); + } + else if(outAsync != null) + { + outAsync.__finished(ex, isSent); } } @@ -2458,9 +2478,10 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne public IceInternal.OutgoingMessageCallback out; public IceInternal.OutgoingAsyncMessageCallback outAsync; public boolean compress; - public boolean response; + public int requestId; boolean adopt; boolean prepared; + boolean isSent; } private final IceInternal.Instance _instance; diff --git a/java/src/Ice/ExceptionCallback.java b/java/src/Ice/ExceptionCallback.java new file mode 100644 index 00000000000..733542b213a --- /dev/null +++ b/java/src/Ice/ExceptionCallback.java @@ -0,0 +1,50 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * An application can optionally supply an instance of this class in an + * asynchronous invocation. The application must create a subclass and + * implement the exception method. + **/ +public abstract class ExceptionCallback extends Callback +{ + /** + * Called when the invocation raises an Ice run-time exception. + * + * @param __ex The Ice run-time exception raised by the operation. + **/ + public abstract void exception(LocalException __ex); + + /** + * Called when a queued invocation is sent successfully. + **/ + public void sent() + { + } + + public final void __completed(AsyncResult __result) + { + try + { + __result.__wait(); + } + catch(LocalException __ex) + { + exception(__ex); + return; + } + } + + public final void __sent(AsyncResult __result) + { + sent(); + } +} diff --git a/java/src/Ice/ObjectPrx.java b/java/src/Ice/ObjectPrx.java index 7e97a124432..188b5b1bc34 100644 --- a/java/src/Ice/ObjectPrx.java +++ b/java/src/Ice/ObjectPrx.java @@ -53,6 +53,69 @@ public interface ObjectPrx boolean ice_isA(String __id, java.util.Map<String, String> __context); /** + * Tests whether this object supports a specific Slice interface. + * + * @param __id The type ID of the Slice interface to test against. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_isA(String __id); + + /** + * Tests whether this object supports a specific Slice interface. + * + * @param __id The type ID of the Slice interface to test against. + * @param __context The context map for the invocation. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_isA(String __id, java.util.Map<String, String> __context); + + /** + * Tests whether this object supports a specific Slice interface. + * + * @param __id The type ID of the Slice interface to test against. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_isA(String __id, Callback __cb); + + /** + * Tests whether this object supports a specific Slice interface. + * + * @param __id The type ID of the Slice interface to test against. + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_isA(String __id, java.util.Map<String, String> __context, Callback __cb); + + /** + * Tests whether this object supports a specific Slice interface. + * + * @param __id The type ID of the Slice interface to test against. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_isA(String __id, Callback_Object_ice_isA __cb); + + /** + * Tests whether this object supports a specific Slice interface. + * + * @param __id The type ID of the Slice interface to test against. + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_isA(String __id, java.util.Map<String, String> __context, Callback_Object_ice_isA __cb); + + /** + * Completes the asynchronous ice_isA request. + * + * @param __result The asynchronous result. + * @return <code>true</code> if this proxy supports the specified interface; <code>false</code>, otherwise. + **/ + boolean end_ice_isA(AsyncResult __result); + + /** * Tests whether the target object of this proxy can be reached. **/ void ice_ping(); @@ -65,6 +128,62 @@ public interface ObjectPrx void ice_ping(java.util.Map<String, String> __context); /** + * Tests whether the target object of this proxy can be reached. + * + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ping(); + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __context The context map for the invocation. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ping(java.util.Map<String, String> __context); + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ping(Callback __cb); + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ping(java.util.Map<String, String> __context, Callback __cb); + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ping(Callback_Object_ice_ping __cb); + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ping(java.util.Map<String, String> __context, Callback_Object_ice_ping __cb); + + /** + * Completes the asynchronous ice_ping request. + * + * @param __result The asynchronous result. + **/ + void end_ice_ping(AsyncResult __result); + + /** * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. * * @return The Slice type IDs of the interfaces supported by the target object, in base-to-derived @@ -75,12 +194,69 @@ public interface ObjectPrx /** * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. * + * @param __context The context map for the invocation. * @return The Slice type IDs of the interfaces supported by the target object, in base-to-derived * order. The first element of the returned array is always <code>::Ice::Object</code>. + **/ + String[] ice_ids(java.util.Map<String, String> __context); + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ids(); + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. * * @param __context The context map for the invocation. + * @return The asynchronous result object. **/ - String[] ice_ids(java.util.Map<String, String> __context); + AsyncResult begin_ice_ids(java.util.Map<String, String> __context); + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ids(Callback __cb); + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ids(java.util.Map<String, String> __context, Callback __cb); + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ids(Callback_Object_ice_ids __cb); + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_ids(java.util.Map<String, String> __context, Callback_Object_ice_ids __cb); + + /** + * Completes the asynchronous ice_ids request. + * + * @param __result The asynchronous result. + * @return The Slice type IDs of the interfaces supported by the target object, in base-to-derived + * order. The first element of the returned array is always <code>::Ice::Object</code>. + **/ + String[] end_ice_ids(AsyncResult __result); /** * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. @@ -98,6 +274,63 @@ public interface ObjectPrx String ice_id(java.util.Map<String, String> __context); /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_id(); + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_id(java.util.Map<String, String> __context); + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_id(Callback __cb); + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_id(java.util.Map<String, String> __context, Callback __cb); + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_id(Callback_Object_ice_id __cb); + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_id(java.util.Map<String, String> __context, Callback_Object_ice_id __cb); + + /** + * Completes the asynchronous ice_id request. + * + * @param __result The asynchronous result. + * @return The Slice type ID of the most-derived interface. + **/ + String end_ice_id(AsyncResult __result); + + /** * Invokes an operation dynamically. * * @param operation The name of the operation to invoke. @@ -140,6 +373,113 @@ public interface ObjectPrx /** * Invokes an operation dynamically and asynchronously. * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + AsyncResult begin_ice_invoke(String operation, OperationMode mode, byte[] inParams); + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __context The context map for the invocation. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + AsyncResult begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, + java.util.Map<String, String> __context); + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + AsyncResult begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, Callback __cb); + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + AsyncResult begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, + java.util.Map<String, String> __context, Callback __cb); + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + AsyncResult begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, + Callback_Object_ice_invoke __cb); + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + AsyncResult begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, + java.util.Map<String, String> __context, Callback_Object_ice_invoke __cb); + + /** + * Completes the asynchronous ice_invoke request. + * + * @param outParams The encoded out-paramaters and return value. + * @param __result The asynchronous result. + * @return If the operation completed successfully, the return value + * is <code>true</code>. If the operation raises a user exception, + * the return value is <code>false</code>; in this case, <code>outParams</code> + * contains the encoded user exception. If the operation raises a run-time exception, + * it throws it directly. + **/ + boolean end_ice_invoke(ByteSeqHolder outParams, AsyncResult __result); + + /** + * Invokes an operation dynamically and asynchronously. + * * @param cb The callback object to notify when the operation completes. * @param operation The name of the operation to invoke. * @param mode The operation mode (normal or idempotent). @@ -521,6 +861,35 @@ public interface ObjectPrx boolean ice_flushBatchRequests_async(AMI_Object_ice_flushBatchRequests cb); /** + * Asynchronously flushes any pending batched requests for this communicator. The call does not block. + * + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_flushBatchRequests(); + + /** + * Asynchronously flushes any pending batched requests for this communicator. The call does not block. + * + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_flushBatchRequests(Callback __cb); + + /** + * Asynchronously flushes any pending batched requests for this communicator. The call does not block. + * + * @param cb The callback object to notify the application when the flush is complete. + * @return The asynchronous result object. + **/ + AsyncResult begin_ice_flushBatchRequests(Callback_Object_ice_flushBatchRequests __cb); + + /** + * Completes the asynchronous flush request. + * + * @param __result The asynchronous result. + **/ + void end_ice_flushBatchRequests(AsyncResult __result); + + /** * Returns whether this proxy equals the passed object. Two proxies are equal if they are equal in all respects, * that is, if their object identity, endpoints timeout settings, and so on are all equal. * diff --git a/java/src/Ice/ObjectPrxHelperBase.java b/java/src/Ice/ObjectPrxHelperBase.java index f92e634eb65..171abe39367 100644 --- a/java/src/Ice/ObjectPrxHelperBase.java +++ b/java/src/Ice/ObjectPrxHelperBase.java @@ -39,7 +39,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable * * @return The communicator that created this proxy. **/ - public final Communicator ice_getCommunicator() + public final Communicator + ice_getCommunicator() { return _reference.getCommunicator(); } @@ -49,7 +50,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable * * @return The stringified proxy. **/ - public final String toString() + public final String + toString() { return _reference.toString(); } @@ -57,7 +59,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable /** * @deprecated **/ - public final String ice_toString() + public final String + ice_toString() { return toString(); } @@ -87,6 +90,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable return ice_isA(__id, __context, true); } + private static final String __ice_isA_name = "ice_isA"; + private boolean ice_isA(String __id, java.util.Map<String, String> __context, boolean __explicitCtx) { @@ -94,14 +99,14 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable { __context = _emptyContext; } - + int __cnt = 0; while(true) { _ObjectDel __del = null; try { - __checkTwowayOnly("ice_isA"); + __checkTwowayOnly(__ice_isA_name); __del = __getDelegate(false); return __del.ice_isA(__id, __context); } @@ -117,6 +122,135 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } /** + * Tests whether this proxy supports a given interface. + * + * @param __id The Slice type ID of an interface. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_isA(String __id) + { + return begin_ice_isA(__id, null, false, null); + } + + /** + * Tests whether this proxy supports a given interface. + * + * @param __id The Slice type ID of an interface. + * @param __context The <code>Context</code> map for the invocation. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_isA(String __id, java.util.Map<String, String> __context) + { + return begin_ice_isA(__id, __context, true, null); + } + + /** + * Tests whether this proxy supports a given interface. + * + * @param __id The Slice type ID of an interface. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_isA(String __id, Callback __cb) + { + return begin_ice_isA(__id, null, false, __cb); + } + + /** + * Tests whether this proxy supports a given interface. + * + * @param __id The Slice type ID of an interface. + * @param __context The <code>Context</code> map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_isA(String __id, java.util.Map<String, String> __context, Callback __cb) + { + return begin_ice_isA(__id, __context, true, __cb); + } + + /** + * Tests whether this proxy supports a given interface. + * + * @param __id The Slice type ID of an interface. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_isA(String __id, Callback_Object_ice_isA __cb) + { + return begin_ice_isA(__id, null, false, __cb); + } + + /** + * Tests whether this proxy supports a given interface. + * + * @param __id The Slice type ID of an interface. + * @param __context The <code>Context</code> map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_isA(String __id, java.util.Map<String, String> __context, Callback_Object_ice_isA __cb) + { + return begin_ice_isA(__id, __context, true, __cb); + } + + private AsyncResult + begin_ice_isA(String __id, java.util.Map<String, String> __context, boolean __explicitCtx, + IceInternal.CallbackBase __cb) + { + IceInternal.OutgoingAsync __result = new IceInternal.OutgoingAsync(this, __ice_isA_name, __cb); + try + { + __checkTwowayOnly(__ice_isA_name); + __result.__prepare(__ice_isA_name, OperationMode.Nonmutating, __context, __explicitCtx); + IceInternal.BasicStream __os = __result.__os(); + __os.writeString(__id); + __os.endWriteEncaps(); + __result.__send(true); + } + catch(LocalException __ex) + { + __result.__exceptionAsync(__ex); + } + return __result; + } + + /** + * Completes the asynchronous ice_isA request. + * + * @param __result The asynchronous result. + * @return <code>true</code> if this proxy supports the specified interface; <code>false</code>, otherwise. + **/ + public final boolean + end_ice_isA(AsyncResult __result) + { + AsyncResult.__check(__result, this, __ice_isA_name); + if(!__result.__wait()) + { + try + { + __result.__throwUserException(); + } + catch(UserException __ex) + { + throw new UnknownUserException(__ex.ice_name()); + } + } + boolean __ret; + IceInternal.BasicStream __is = __result.__is(); + __is.startReadEncaps(); + __ret = __is.readBool(); + __is.endReadEncaps(); + return __ret; + } + + /** * Tests whether the target object of this proxy can be reached. **/ public final void @@ -136,6 +270,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable ice_ping(__context, true); } + private static final String __ice_ping_name = "ice_ping"; + private void ice_ping(java.util.Map<String, String> __context, boolean __explicitCtx) { @@ -166,6 +302,108 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } /** + * Tests whether the target object of this proxy can be reached. + * + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ping() + { + return begin_ice_ping(null, false, null); + } + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __context The context map for the invocation. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ping(java.util.Map<String, String> __context) + { + return begin_ice_ping(__context, true, null); + } + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ping(Callback __cb) + { + return begin_ice_ping(null, false, __cb); + } + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ping(java.util.Map<String, String> __context, Callback __cb) + { + return begin_ice_ping(__context, true, __cb); + } + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ping(Callback_Object_ice_ping __cb) + { + return begin_ice_ping(null, false, __cb); + } + + /** + * Tests whether the target object of this proxy can be reached. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ping(java.util.Map<String, String> __context, Callback_Object_ice_ping __cb) + { + return begin_ice_ping(__context, true, __cb); + } + + private AsyncResult + begin_ice_ping(java.util.Map<String, String> __context, boolean __explicitCtx, IceInternal.CallbackBase __cb) + { + IceInternal.OutgoingAsync __result = new IceInternal.OutgoingAsync(this, __ice_ping_name, __cb); + try + { + __result.__prepare(__ice_ping_name, OperationMode.Nonmutating, __context, __explicitCtx); + IceInternal.BasicStream __os = __result.__os(); + __os.endWriteEncaps(); + __result.__send(true); + } + catch(LocalException __ex) + { + __result.__exceptionAsync(__ex); + } + return __result; + } + + /** + * Completes the asynchronous ping request. + * + * @param __result The asynchronous result. + **/ + public final void + end_ice_ping(AsyncResult __result) + { + __end(__result, __ice_ping_name); + } + + /** * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. * * @return The Slice type IDs of the interfaces supported by the target object, in base-to-derived @@ -190,6 +428,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable return ice_ids(__context, true); } + private static final String __ice_ids_name = "ice_ids"; + private String[] ice_ids(java.util.Map<String, String> __context, boolean __explicitCtx) { @@ -204,7 +444,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable _ObjectDel __del = null; try { - __checkTwowayOnly("ice_ids"); + __checkTwowayOnly(__ice_ids_name); __del = __getDelegate(false); return __del.ice_ids(__context); } @@ -220,6 +460,128 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ids() + { + return begin_ice_ids(null, false, null); + } + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ids(java.util.Map<String, String> __context) + { + return begin_ice_ids(__context, true, null); + } + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ids(Callback __cb) + { + return begin_ice_ids(null, false, __cb); + } + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ids(java.util.Map<String, String> __context, Callback __cb) + { + return begin_ice_ids(__context, true, __cb); + } + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ids(Callback_Object_ice_ids __cb) + { + return begin_ice_ids(null, false, __cb); + } + + /** + * Returns the Slice type IDs of the interfaces supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_ids(java.util.Map<String, String> __context, Callback_Object_ice_ids __cb) + { + return begin_ice_ids(__context, true, __cb); + } + + private AsyncResult + begin_ice_ids(java.util.Map<String, String> __context, boolean __explicitCtx, IceInternal.CallbackBase __cb) + { + IceInternal.OutgoingAsync __result = new IceInternal.OutgoingAsync(this, __ice_ids_name, __cb); + try + { + __checkTwowayOnly(__ice_ids_name); + __result.__prepare(__ice_ids_name, OperationMode.Nonmutating, __context, __explicitCtx); + IceInternal.BasicStream __os = __result.__os(); + __os.endWriteEncaps(); + __result.__send(true); + } + catch(LocalException __ex) + { + __result.__exceptionAsync(__ex); + } + return __result; + } + + /** + * Completes the asynchronous ice_ids request. + * + * @param __result The asynchronous result. + * @return The Slice type IDs of the interfaces supported by the target object, in base-to-derived + * order. The first element of the returned array is always <code>::Ice::Object</code>. + **/ + public final String[] + end_ice_ids(AsyncResult __result) + { + AsyncResult.__check(__result, this, __ice_ids_name); + if(!__result.__wait()) + { + try + { + __result.__throwUserException(); + } + catch(UserException __ex) + { + throw new UnknownUserException(__ex.ice_name()); + } + } + String[] __ret = null; + IceInternal.BasicStream __is = __result.__is(); + __is.startReadEncaps(); + __ret = StringSeqHelper.read(__is); + __is.endReadEncaps(); + return __ret; + } + + /** * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. * * @return The Slice type ID of the most-derived interface. @@ -242,6 +604,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable return ice_id(__context, true); } + private static final String __ice_id_name = "ice_id"; + private String ice_id(java.util.Map<String, String> __context, boolean __explicitCtx) { @@ -256,7 +620,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable _ObjectDel __del = null; try { - __checkTwowayOnly("ice_id"); + __checkTwowayOnly(__ice_id_name); __del = __getDelegate(false); return __del.ice_id(__context); } @@ -272,6 +636,127 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_id() + { + return begin_ice_id(null, false, null); + } + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_id(java.util.Map<String, String> __context) + { + return begin_ice_id(__context, true, null); + } + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_id(Callback __cb) + { + return begin_ice_id(null, false, __cb); + } + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_id(java.util.Map<String, String> __context, Callback __cb) + { + return begin_ice_id(__context, true, __cb); + } + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_id(Callback_Object_ice_id __cb) + { + return begin_ice_id(null, false, __cb); + } + + /** + * Returns the Slice type ID of the most-derived interface supported by the target object of this proxy. + * + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + **/ + public final AsyncResult + begin_ice_id(java.util.Map<String, String> __context, Callback_Object_ice_id __cb) + { + return begin_ice_id(__context, true, __cb); + } + + private AsyncResult + begin_ice_id(java.util.Map<String, String> __context, boolean __explicitCtx, IceInternal.CallbackBase __cb) + { + IceInternal.OutgoingAsync __result = new IceInternal.OutgoingAsync(this, __ice_id_name, __cb); + try + { + __checkTwowayOnly(__ice_id_name); + __result.__prepare(__ice_id_name, OperationMode.Nonmutating, __context, __explicitCtx); + IceInternal.BasicStream __os = __result.__os(); + __os.endWriteEncaps(); + __result.__send(true); + } + catch(LocalException __ex) + { + __result.__exceptionAsync(__ex); + } + return __result; + } + + /** + * Completes the asynchronous ice_id request. + * + * @param __result The asynchronous result. + * @return The Slice type ID of the most-derived interface. + **/ + public final String + end_ice_id(AsyncResult __result) + { + AsyncResult.__check(__result, this, __ice_id_name); + if(!__result.__wait()) + { + try + { + __result.__throwUserException(); + } + catch(UserException __ex) + { + throw new UnknownUserException(__ex.ice_name()); + } + } + String __ret = null; + IceInternal.BasicStream __is = __result.__is(); + __is.startReadEncaps(); + __ret = __is.readString(); + __is.endReadEncaps(); + return __ret; + } + + /** * Invoke an operation dynamically. * * @param operation The name of the operation to invoke. @@ -316,7 +801,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable { return ice_invoke(operation, mode, inParams, outParams, context, true); } - + private boolean ice_invoke(String operation, OperationMode mode, byte[] inParams, ByteSeqHolder outParams, java.util.Map<String, String> context, boolean explicitCtx) @@ -343,7 +828,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } else { - __handleExceptionWrapper(__del, __ex, null); + __handleExceptionWrapper(__del, __ex); } } catch(LocalException __ex) @@ -353,6 +838,175 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } } + private static final String __ice_invoke_name = "ice_invoke"; + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + public final AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams) + { + return begin_ice_invoke(operation, mode, inParams, null, false, null); + } + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __context The context map for the invocation. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + public final AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, + java.util.Map<String, String> __context) + { + return begin_ice_invoke(operation, mode, inParams, __context, true, null); + } + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + public final AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, Callback __cb) + { + return begin_ice_invoke(operation, mode, inParams, null, false, __cb); + } + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + public final AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, java.util.Map<String, String> __context, + Callback __cb) + { + return begin_ice_invoke(operation, mode, inParams, __context, true, __cb); + } + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + public final AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, Callback_Object_ice_invoke __cb) + { + return begin_ice_invoke(operation, mode, inParams, null, false, __cb); + } + + /** + * Invokes an operation dynamically and asynchronously. + * + * @param operation The name of the operation to invoke. + * @param mode The operation mode (normal or idempotent). + * @param inParams The encoded in-parameters for the operation. + * for the operation. The return value follows any out-parameters. + * @param __context The context map for the invocation. + * @param __cb The asynchronous callback object. + * @return The asynchronous result object. + * + * @see Blobject + * @see OperationMode + **/ + public final AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, java.util.Map<String, String> __context, + Callback_Object_ice_invoke __cb) + { + return begin_ice_invoke(operation, mode, inParams, __context, true, __cb); + } + + private AsyncResult + begin_ice_invoke(String operation, OperationMode mode, byte[] inParams, java.util.Map<String, String> __context, + boolean __explicitCtx, IceInternal.CallbackBase __cb) + { + IceInternal.OutgoingAsync __result = new IceInternal.OutgoingAsync(this, __ice_invoke_name, __cb); + try + { + __result.__prepare(operation, mode, __context, __explicitCtx); + IceInternal.BasicStream __os = __result.__os(); + __os.writeBlob(inParams); + __os.endWriteEncaps(); + __result.__send(true); + } + catch(LocalException __ex) + { + __result.__exceptionAsync(__ex); + } + return __result; + } + + /** + * Completes the asynchronous ice_invoke request. + * + * @param outParams The encoded out-paramaters and return value. + * @param __result The asynchronous result. + * @return If the operation completed successfully, the return value + * is <code>true</code>. If the operation raises a user exception, + * the return value is <code>false</code>; in this case, <code>outParams</code> + * contains the encoded user exception. If the operation raises a run-time exception, + * it throws it directly. + **/ + public final boolean + end_ice_invoke(ByteSeqHolder outParams, AsyncResult __result) + { + AsyncResult.__check(__result, this, __ice_invoke_name); + boolean ok = __result.__wait(); + if(_reference.getMode() == IceInternal.Reference.ModeTwoway) + { + IceInternal.BasicStream __is = __result.__is(); + __is.startReadEncaps(); + int sz = __is.getReadEncapsSize(); + if(outParams != null) + { + outParams.value = __is.readBlob(sz); + } + __is.endReadEncaps(); + } + return ok; + } + /** * Invokes an operation dynamically and asynchronously. * @@ -370,8 +1024,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable public final boolean ice_invoke_async(AMI_Object_ice_invoke cb, String operation, OperationMode mode, byte[] inParams) { - __checkTwowayOnly("ice_invoke_async"); - return cb.__invoke(this, operation, mode, inParams, null); + AsyncResult __result = begin_ice_invoke(operation, mode, inParams, cb); + return __result.sentSynchronously(); } /** @@ -393,14 +1047,10 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable ice_invoke_async(AMI_Object_ice_invoke cb, String operation, OperationMode mode, byte[] inParams, java.util.Map<String, String> context) { - if(context == null) - { - context = _emptyContext; - } - __checkTwowayOnly("ice_invoke_async"); - return cb.__invoke(this, operation, mode, inParams, context); + AsyncResult __result = begin_ice_invoke(operation, mode, inParams, context, cb); + return __result.sentSynchronously(); } - + /** * Returns the identity embedded in this proxy. * @@ -1020,7 +1670,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable * * @param connectionId The connection ID for the new proxy. An empty string removes the * connection ID. - * + * * @return A new proxy with the specified connection ID. **/ public final ObjectPrx @@ -1086,7 +1736,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable { __del = _delegate; } - + if(__del != null) { try @@ -1135,7 +1785,85 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable public boolean ice_flushBatchRequests_async(AMI_Object_ice_flushBatchRequests cb) { - return cb.__invoke(this); + AsyncResult result = begin_ice_flushBatchRequests(cb); + return result.sentSynchronously(); + } + + /** + * Asynchronously flushes any pending batched requests for this communicator. The call does not block. + * + * @return The asynchronous result object. + **/ + public AsyncResult + begin_ice_flushBatchRequests() + { + AsyncResult result = begin_ice_flushBatchRequestsInternal(null); + return result; + } + + /** + * Asynchronously flushes any pending batched requests for this communicator. The call does not block. + * + * @param __cb The callback object to notify the application when the flush is complete. + * @return The asynchronous result object. + **/ + public AsyncResult + begin_ice_flushBatchRequests(Callback __cb) + { + AsyncResult result = begin_ice_flushBatchRequestsInternal(__cb); + return result; + } + + /** + * Asynchronously flushes any pending batched requests for this communicator. The call does not block. + * + * @param __cb The callback object to notify the application when the flush is complete. + * @return The asynchronous result object. + **/ + public AsyncResult + begin_ice_flushBatchRequests(Callback_Object_ice_flushBatchRequests __cb) + { + AsyncResult result = begin_ice_flushBatchRequestsInternal(__cb); + return result; + } + + private static final String __ice_flushBatchRequests_name = "ice_flushBatchRequests"; + + private AsyncResult + begin_ice_flushBatchRequestsInternal(IceInternal.CallbackBase __cb) + { + IceInternal.BatchOutgoingAsync __result = + new IceInternal.ProxyBatchOutgoingAsync(this, __ice_flushBatchRequests_name, __cb); + try + { + // + // We don't automatically retry if ice_flushBatchRequests fails. Otherwise, if some batch + // requests were queued with the connection, they would be lost without being noticed. + // + _ObjectDel delegate = null; + int cnt = -1; // Don't retry. + try + { + delegate = __getDelegate(false); + delegate.__getRequestHandler().flushAsyncBatchRequests(__result); + } + catch(LocalException __ex) + { + cnt = __handleException(delegate, __ex, null, cnt); + } + } + catch(LocalException __ex) + { + __result.__exceptionAsync(__ex); + } + return __result; + } + + public void + end_ice_flushBatchRequests(AsyncResult __result) + { + AsyncResult.__check(__result, this, __ice_flushBatchRequests_name); + __result.__wait(); } /** @@ -1210,8 +1938,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable // The _delegate attribute is only used if "cache connection" // is enabled. If it's not enabled, we don't keep track of the // delegate -- a new delegate is created for each invocation. - // - + // + if(delegateD != null) { _ObjectDelD delegate = __createDelegateD(); @@ -1228,7 +1956,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } public final int - __handleException(_ObjectDel delegate, LocalException ex, IceInternal.OutgoingAsync out, int cnt) + __handleException(_ObjectDel delegate, LocalException ex, Ice.IntHolder interval, int cnt) { // // Only _delegate needs to be mutex protected here. @@ -1248,7 +1976,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable try { - return _reference.getInstance().proxyFactory().checkRetryAfterException(ex, _reference, out, cnt); + return _reference.getInstance().proxyFactory().checkRetryAfterException(ex, _reference, interval, cnt); } catch(CommunicatorDestroyedException e) { @@ -1262,7 +1990,7 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } public final void - __handleExceptionWrapper(_ObjectDel delegate, IceInternal.LocalExceptionWrapper ex, IceInternal.OutgoingAsync out) + __handleExceptionWrapper(_ObjectDel delegate, IceInternal.LocalExceptionWrapper ex) { synchronized(this) { @@ -1276,20 +2004,17 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable { throw ex.get(); } - - if(out != null) - { - out.__send(); - } } public final int - __handleExceptionWrapperRelaxed(_ObjectDel delegate, IceInternal.LocalExceptionWrapper ex, - IceInternal.OutgoingAsync out, int cnt) + __handleExceptionWrapperRelaxed(_ObjectDel delegate, + IceInternal.LocalExceptionWrapper ex, + Ice.IntHolder interval, + int cnt) { if(!ex.retry()) { - return __handleException(delegate, ex.get(), out, cnt); + return __handleException(delegate, ex.get(), interval, cnt); } else { @@ -1301,11 +2026,6 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } } - if(out != null) - { - out.__send(); - } - return cnt; } } @@ -1345,8 +2065,8 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable else { final int mode = _reference.getMode(); - return createDelegate(ami || - mode == IceInternal.Reference.ModeBatchOneway || + return createDelegate(ami || + mode == IceInternal.Reference.ModeBatchOneway || mode == IceInternal.Reference.ModeBatchDatagram); } } @@ -1371,7 +2091,30 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable } } } - + + public final void + __end(AsyncResult __result, String operation) + { + AsyncResult.__check(__result, this, operation); + boolean ok = __result.__wait(); + if(_reference.getMode() == IceInternal.Reference.ModeTwoway) + { + if(!ok) + { + try + { + __result.__throwUserException(); + } + catch(UserException __ex) + { + throw new UnknownUserException(__ex.ice_name()); + } + } + IceInternal.BasicStream __is = __result.__is(); + __is.skipEmptyEncaps(); + } + } + protected _ObjectDelM __createDelegateM() { diff --git a/java/src/Ice/OnewayCallback.java b/java/src/Ice/OnewayCallback.java new file mode 100644 index 00000000000..c613a0fadae --- /dev/null +++ b/java/src/Ice/OnewayCallback.java @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Base class for generated oneway operation callback. + **/ +public abstract class OnewayCallback extends IceInternal.CallbackBase +{ + /** + * Called when the invocation response is received. + **/ + public abstract void response(); + + /** + * Called when the invocation raises an Ice run-time exception. + * + * @param ex The Ice run-time exception raised by the operation. + **/ + public abstract void exception(LocalException ex); + + /** + * Called when a queued invocation is sent successfully. + **/ + public void sent() + { + } + + public final void __sent(AsyncResult __result) + { + sent(); + } + + public final void __completed(AsyncResult __result) + { + try + { + ((ObjectPrxHelperBase)__result.getProxy()).__end(__result, __result.getOperation()); + } + catch(LocalException __ex) + { + exception(__ex); + return; + } + response(); + } +} diff --git a/java/src/Ice/SentCallback.java b/java/src/Ice/SentCallback.java new file mode 100644 index 00000000000..1a2f8a08009 --- /dev/null +++ b/java/src/Ice/SentCallback.java @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * An application can optionally supply an instance of this class in an + * asynchronous invocation. The application must create a subclass and + * implement the sent method. + **/ +public abstract class SentCallback extends Callback +{ + /** + * Called when a queued invocation is sent successfully. + **/ + public abstract void sent(); + + public final void __completed(AsyncResult __result) + { + // Ignore. + } + + public final void __sent(AsyncResult __result) + { + sent(); + } +} diff --git a/java/src/Ice/TwowayCallback.java b/java/src/Ice/TwowayCallback.java new file mode 100644 index 00000000000..0ebe4316ef8 --- /dev/null +++ b/java/src/Ice/TwowayCallback.java @@ -0,0 +1,35 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +/** + * Base class for generated twoway operation callback. + **/ +public abstract class TwowayCallback extends IceInternal.CallbackBase +{ + /** + * Called when the invocation raises an Ice run-time exception. + * + * @param __ex The Ice run-time exception raised by the operation. + **/ + public abstract void exception(LocalException __ex); + + /** + * Called when a queued invocation is sent successfully. + **/ + public void sent() + { + } + + public final void __sent(AsyncResult __result) + { + sent(); + } +} diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 1ec9747ea32..6c79108c582 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -688,6 +688,10 @@ public class BasicStream public void writeBlob(byte[] v) { + if(v == null) + { + return; + } expand(v.length); _buf.b.put(v); } @@ -695,6 +699,10 @@ public class BasicStream public void writeBlob(byte[] v, int off, int len) { + if(v == null) + { + return; + } expand(len); _buf.b.put(v, off, len); } diff --git a/java/src/IceInternal/BatchOutgoing.java b/java/src/IceInternal/BatchOutgoing.java index 766b8eb99d4..b8e1b04adbc 100644 --- a/java/src/IceInternal/BatchOutgoing.java +++ b/java/src/IceInternal/BatchOutgoing.java @@ -74,7 +74,7 @@ public final class BatchOutgoing implements OutgoingMessageCallback } public synchronized void - finished(Ice.LocalException ex) + finished(Ice.LocalException ex, boolean sent) { _exception = ex; notify(); diff --git a/java/src/IceInternal/BatchOutgoingAsync.java b/java/src/IceInternal/BatchOutgoingAsync.java index 4564fde7d3f..4ac4aa396da 100644 --- a/java/src/IceInternal/BatchOutgoingAsync.java +++ b/java/src/IceInternal/BatchOutgoingAsync.java @@ -9,18 +9,30 @@ package IceInternal; -public abstract class BatchOutgoingAsync extends OutgoingAsyncMessageCallback +public class BatchOutgoingAsync extends Ice.AsyncResult implements OutgoingAsyncMessageCallback { - public final void - __sent(final Ice.ConnectionI connection) + public BatchOutgoingAsync(Instance instance, String operation, CallbackBase callback) { - __releaseCallback(); + super(instance, operation, callback); + } + + public boolean __sent(Ice.ConnectionI connection) + { + synchronized(_monitor) + { + _state |= Done | OK | Sent; + _monitor.notifyAll(); + return true; + } + } + + public void __sent() + { + __sentInternal(); } - public final void - __finished(Ice.LocalException exc) + public void __finished(Ice.LocalException exc, boolean sent) { __exception(exc); } - } diff --git a/java/src/IceInternal/CallbackBase.java b/java/src/IceInternal/CallbackBase.java new file mode 100644 index 00000000000..6de57305851 --- /dev/null +++ b/java/src/IceInternal/CallbackBase.java @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +public abstract class CallbackBase +{ + public abstract void __completed(Ice.AsyncResult r); + public abstract void __sent(Ice.AsyncResult r); +} diff --git a/java/src/IceInternal/ConnectRequestHandler.java b/java/src/IceInternal/ConnectRequestHandler.java index 2b8a18881ac..6b1a0a34d6b 100644 --- a/java/src/IceInternal/ConnectRequestHandler.java +++ b/java/src/IceInternal/ConnectRequestHandler.java @@ -9,7 +9,7 @@ package IceInternal; -public class ConnectRequestHandler +public class ConnectRequestHandler implements RequestHandler, Reference.GetConnectionCallback, RouterInfo.AddProxyCallback { static class Request @@ -71,15 +71,15 @@ public class ConnectRequestHandler { } } - + if(!initialized()) { - _batchStream.swap(os); _batchRequestInProgress = true; + _batchStream.swap(os); return; } } - + _connection.prepareBatchRequest(os); } @@ -107,7 +107,6 @@ public class ConnectRequestHandler return; } } - _connection.finishBatchRequest(os, _compress); } @@ -125,10 +124,10 @@ public class ConnectRequestHandler BasicStream dummy = new BasicStream(_reference.getInstance(), _batchAutoFlush); _batchStream.swap(dummy); _batchRequestsSize = Protocol.requestBatchHdr.length; + return; } } - _connection.abortBatchRequest(); } @@ -210,16 +209,16 @@ public class ConnectRequestHandler _connection.reclaimOutgoing(out); } - public Reference + public Reference getReference() { return _reference; } synchronized public Ice.ConnectionI - getConnection(boolean wait) + getConnection(boolean waitInit) { - if(wait) + if(waitInit) { // // Wait for the connection establishment to complete or fail. @@ -242,7 +241,7 @@ public class ConnectRequestHandler } else { - assert(!wait || _initialized); + assert(!waitInit || _initialized); return _connection; } } @@ -256,7 +255,9 @@ public class ConnectRequestHandler { synchronized(this) { - assert(_connection == null && _exception == null); + assert(_exception == null && _connection == null); + assert(_updateRequestHandler || _requests.isEmpty()); + _connection = connection; _compress = compress; } @@ -277,24 +278,24 @@ public class ConnectRequestHandler flushRequests(); } - public synchronized void + public synchronized void setException(final Ice.LocalException ex) { assert(!_initialized && _exception == null); assert(_updateRequestHandler || _requests.isEmpty()); - + _exception = ex; _proxy = null; // Break cyclic reference count. _delegate = null; // Break cyclic reference count. - + // // If some requests were queued, we notify them of the failure. This is done from a thread - // from the client thread pool since this will result in ice_exception callbacks to be + // from the client thread pool since this will result in ice_exception callbacks to be // called. // if(!_requests.isEmpty()) { - _reference.getInstance().clientThreadPool().execute(new ThreadPoolWorkItem() + _reference.getInstance().clientThreadPool().execute(new ThreadPoolWorkItem() { public void execute(ThreadPoolCurrent current) @@ -315,30 +316,34 @@ public class ConnectRequestHandler addedProxy() { // - // The proxy was added to the router info, we're now ready to send the + // The proxy was added to the router info, we're now ready to send the // queued requests. // flushRequests(); } - public + public ConnectRequestHandler(Reference ref, Ice.ObjectPrx proxy, Ice._ObjectDelM delegate) { _reference = ref; _response = _reference.getMode() == Reference.ModeTwoway; - _proxy = (Ice.ObjectPrxHelperBase)proxy; + _proxy = (Ice.ObjectPrxHelperBase)proxy; _delegate = delegate; _batchAutoFlush = ref.getInstance().initializationData().properties.getPropertyAsIntWithDefault( "Ice.BatchAutoFlush", 1) > 0 ? true : false; - _batchStream = new BasicStream(ref.getInstance(), _batchAutoFlush); + _initialized = false; + _flushing = false; _batchRequestInProgress = false; _batchRequestsSize = Protocol.requestBatchHdr.length; + _batchStream = new BasicStream(ref.getInstance(), _batchAutoFlush); _updateRequestHandler = false; } private boolean initialized() { + // Must be called with the mutex locked. + if(_initialized) { assert(_connection != null); @@ -357,14 +362,14 @@ public class ConnectRequestHandler } } - if(_exception != null) - { - throw (Ice.LocalException)_exception.fillInStackTrace(); - } - else - { - return _initialized; - } + if(_exception != null) + { + throw (Ice.LocalException)_exception.fillInStackTrace(); + } + else + { + return _initialized; + } } } @@ -374,7 +379,7 @@ public class ConnectRequestHandler synchronized(this) { assert(_connection != null && !_initialized); - + while(_batchRequestInProgress) { try @@ -385,16 +390,16 @@ public class ConnectRequestHandler { } } - + // // We set the _flushing flag to true to prevent any additional queuing. Callers // might block for a little while as the queued requests are being sent but this // shouldn't be an issue as the request sends are non-blocking. - // + // _flushing = true; } - final java.util.List<OutgoingAsyncMessageCallback> sentCallbacks = + final java.util.List<OutgoingAsyncMessageCallback> sentCallbacks = new java.util.ArrayList<OutgoingAsyncMessageCallback>(); try { @@ -406,20 +411,14 @@ public class ConnectRequestHandler { if(_connection.sendAsyncRequest(request.out, _compress, _response)) { - if(request.out instanceof Ice.AMISentCallback) - { - sentCallbacks.add(request.out); - } + sentCallbacks.add(request.out); } } else if(request.batchOut != null) { if(_connection.flushAsyncBatchRequests(request.batchOut)) { - if(request.batchOut instanceof Ice.AMISentCallback) - { - sentCallbacks.add(request.batchOut); - } + sentCallbacks.add(request.batchOut); } } else @@ -447,7 +446,7 @@ public class ConnectRequestHandler { assert(_exception == null && !_requests.isEmpty()); _exception = ex.get(); - _reference.getInstance().clientThreadPool().execute(new ThreadPoolWorkItem() + _reference.getInstance().clientThreadPool().execute(new ThreadPoolWorkItem() { public void execute(ThreadPoolCurrent current) @@ -464,7 +463,7 @@ public class ConnectRequestHandler { assert(_exception == null && !_requests.isEmpty()); _exception = ex; - _reference.getInstance().clientThreadPool().execute(new ThreadPoolWorkItem() + _reference.getInstance().clientThreadPool().execute(new ThreadPoolWorkItem() { public void execute(ThreadPoolCurrent current) @@ -475,11 +474,11 @@ public class ConnectRequestHandler }); } } - + if(!sentCallbacks.isEmpty()) { final Instance instance = _reference.getInstance(); - instance.clientThreadPool().execute(new ThreadPoolWorkItem() + instance.clientThreadPool().execute(new ThreadPoolWorkItem() { public void execute(ThreadPoolCurrent current) @@ -487,16 +486,16 @@ public class ConnectRequestHandler current.ioCompleted(); for(OutgoingAsyncMessageCallback callback : sentCallbacks) { - callback.__sent(instance); + callback.__sent(); } }; }); } - + // // We've finished sending the queued requests and the request handler now send - // the requests over the connection directly. It's time to substitute the - // request handler of the proxy with the more efficient connection request + // the requests over the connection directly. It's time to substitute the + // request handler of the proxy with the more efficient connection request // handler which does not have any synchronization. This also breaks the cyclic // reference count with the proxy. // @@ -509,9 +508,9 @@ public class ConnectRequestHandler synchronized(this) { + assert(!_initialized); if(_exception == null) { - assert(!_initialized); _initialized = true; _flushing = false; } @@ -527,12 +526,12 @@ public class ConnectRequestHandler for(Request request : _requests) { if(request.out != null) - { - request.out.__finished(ex); + { + request.out.__finished(ex, false); } else if(request.batchOut != null) { - request.batchOut.__finished(ex); + request.batchOut.__finished(ex, false); } } _requests.clear(); @@ -544,27 +543,30 @@ public class ConnectRequestHandler for(Request request : _requests) { if(request.out != null) - { + { request.out.__finished(ex); } else if(request.batchOut != null) { - request.batchOut.__finished(ex.get()); + request.batchOut.__finished(ex.get(), false); } } _requests.clear(); } private final Reference _reference; - private final boolean _batchAutoFlush; + private boolean _response; + private Ice.ObjectPrxHelperBase _proxy; private Ice._ObjectDelM _delegate; - private boolean _initialized = false; - private boolean _flushing = false; - private Ice.ConnectionI _connection = null; - private boolean _compress = false; - private boolean _response; - private Ice.LocalException _exception = null; + + private final boolean _batchAutoFlush; + + private Ice.ConnectionI _connection; + private boolean _compress; + private Ice.LocalException _exception; + private boolean _initialized; + private boolean _flushing; private java.util.List<Request> _requests = new java.util.LinkedList<Request>(); private boolean _batchRequestInProgress; diff --git a/java/src/IceInternal/LocatorInfo.java b/java/src/IceInternal/LocatorInfo.java index c68fc32b9e5..c1c2ff162a0 100644 --- a/java/src/IceInternal/LocatorInfo.java +++ b/java/src/IceInternal/LocatorInfo.java @@ -245,19 +245,19 @@ public final class LocatorInfo public void ice_response(Ice.ObjectPrx proxy) { - response(proxy); + ObjectRequest.this.response(proxy); } public void ice_exception(Ice.UserException ex) { - exception(ex); + ObjectRequest.this.exception(ex); } public void ice_exception(Ice.LocalException ex) { - exception(ex); + ObjectRequest.this.exception(ex); } }, _ref.getIdentity()); @@ -295,19 +295,19 @@ public final class LocatorInfo public void ice_response(Ice.ObjectPrx proxy) { - response(proxy); + AdapterRequest.this.response(proxy); } public void ice_exception(Ice.UserException ex) { - exception(ex); + AdapterRequest.this.exception(ex); } public void ice_exception(Ice.LocalException ex) { - exception(ex); + AdapterRequest.this.exception(ex); } }, _ref.getAdapterId()); diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java index 6413b7ab884..bc11dd68f5d 100644 --- a/java/src/IceInternal/Outgoing.java +++ b/java/src/IceInternal/Outgoing.java @@ -412,11 +412,12 @@ public final class Outgoing implements OutgoingMessageCallback } public synchronized void - finished(Ice.LocalException ex) + finished(Ice.LocalException ex, boolean sent) { assert(_state <= StateInProgress); _state = StateFailed; _exception = ex; + _sent = sent; notify(); } diff --git a/java/src/IceInternal/OutgoingAsync.java b/java/src/IceInternal/OutgoingAsync.java index 490b15a73ee..75f52715837 100644 --- a/java/src/IceInternal/OutgoingAsync.java +++ b/java/src/IceInternal/OutgoingAsync.java @@ -9,70 +9,212 @@ package IceInternal; -public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback +public class OutgoingAsync extends Ice.AsyncResult implements OutgoingAsyncMessageCallback { - public final void - __sent(final Ice.ConnectionI connection) + public OutgoingAsync(Ice.ObjectPrx prx, String operation, CallbackBase callback) { - synchronized(__monitor) + super(((Ice.ObjectPrxHelperBase)prx).__reference().getInstance(), operation, callback); + _proxy = (Ice.ObjectPrxHelperBase)prx; + } + + public void __prepare(String operation, Ice.OperationMode mode, java.util.Map<String, String> ctx, + boolean explicitCtx) + { + _delegate = null; + _cnt = 0; + _mode = mode; + _sentSynchronously = false; + + if(explicitCtx && ctx == null) + { + ctx = _emptyContext; + } + + // + // Can't call async via a batch proxy. + // + if(_proxy.ice_isBatchOneway() || _proxy.ice_isBatchDatagram()) + { + throw new Ice.FeatureNotSupportedException("can't send batch requests with AMI"); + } + + _os.writeBlob(IceInternal.Protocol.requestHdr); + + Reference ref = _proxy.__reference(); + + ref.getIdentity().__write(_os); + + // + // For compatibility with the old FacetPath. + // + String facet = ref.getFacet(); + if(facet == null || facet.length() == 0) + { + _os.writeStringSeq(null); + } + else { - _sent = true; + String[] facetPath = { facet }; + _os.writeStringSeq(facetPath); + } + + _os.writeString(operation); + + _os.writeByte((byte)mode.ordinal()); - if(!_proxy.ice_isTwoway()) + if(ctx != null) + { + // + // Explicit context + // + Ice.ContextHelper.write(_os, ctx); + } + else + { + // + // Implicit context + // + Ice.ImplicitContextI implicitContext = ref.getInstance().getImplicitContext(); + java.util.Map<String, String> prxContext = ref.getContext(); + + if(implicitContext == null) { - __releaseCallback(); + Ice.ContextHelper.write(_os, prxContext); } - else if(_response) + else { - __monitor.notifyAll(); // If the response was already received notify finished() which is waiting. + implicitContext.write(prxContext, _os); } - else if(connection.timeout() >= 0) + } + + _os.startWriteEncaps(); + } + + public Ice.ObjectPrx getProxy() + { + return _proxy; + } + + public boolean __sent(final Ice.ConnectionI connection) + { + synchronized(_monitor) + { + boolean alreadySent = (_state & Sent) != 0; + _state |= Sent; + + if((_state & Done) == 0) { - assert(_timerTask == null); - _timerTask = new TimerTask() + if(!_proxy.ice_isTwoway()) { - public void - runTimerTask() - { - __runTimerTask(connection); - } - }; - _proxy.__reference().getInstance().timer().schedule(_timerTask, connection.timeout()); + _state |= Done | OK; + } + else if(connection.timeout() > 0) + { + assert(_timerTaskConnection == null && _timerTask == null); + _timerTaskConnection = connection; + _timerTask = new TimerTask() + { + public void + runTimerTask() + { + __runTimerTask(); + } + }; + _instance.timer().schedule(_timerTask, connection.timeout()); + } } + _monitor.notifyAll(); + return !alreadySent; // Don't call the sent call is already sent. } } - public final void - __finished(BasicStream is) + public void __sent() + { + __sentInternal(); + } + + public void __finished(Ice.LocalException exc, boolean sent) + { + synchronized(_monitor) + { + assert((_state & Done) == 0); + if(_timerTaskConnection != null) + { + _instance.timer().cancel(_timerTask); + _timerTaskConnection = null; + _timerTask = null; + } + } + + // + // NOTE: at this point, synchronization isn't needed, no other threads should be + // calling on the callback. + // + + try + { + int interval = handleException(exc, sent); // This will throw if the invocation can't be retried. + if(interval > 0) + { + _instance.retryQueue().add(this, interval); + } + else + { + __send(false); + } + } + catch(Ice.LocalException ex) + { + __exception(ex); + } + } + + public final void __finished(LocalExceptionWrapper exc) + { + // + // NOTE: at this point, synchronization isn't needed, no other threads should be + // calling on the callback. The LocalExceptionWrapper exception is only called + // before the invocation is sent. + // + + try + { + int interval = handleException(exc); // This will throw if the invocation can't be retried. + if(interval > 0) + { + _instance.retryQueue().add(this, interval); + } + else + { + __send(false); + } + } + catch(Ice.LocalException ex) + { + __exception(ex); + } + } + + public final void __finished(BasicStream is) { assert(_proxy.ice_isTwoway()); // Can only be called for twoways. byte replyStatus; try { - synchronized(__monitor) + synchronized(_monitor) { - assert(__os != null); - _response = true; + assert(_exception == null && (_state & Done) == 0); - if(_timerTask != null && _proxy.__reference().getInstance().timer().cancel(_timerTask)) + if(_timerTaskConnection != null) { - _timerTask = null; // Timer cancelled. + _instance.timer().cancel(_timerTask); + _timerTaskConnection = null; + _timerTask = null; } - while(!_sent || _timerTask != null) - { - try - { - __monitor.wait(); - } - catch(java.lang.InterruptedException ex) - { - } - } - - __is.swap(is); - replyStatus = __is.readByte(); + _is.swap(is); + replyStatus = _is.readByte(); switch(replyStatus) { @@ -87,12 +229,12 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback case ReplyStatus.replyOperationNotExist: { Ice.Identity id = new Ice.Identity(); - id.__read(__is); + id.__read(_is); // // For compatibility with the old FacetPath. // - String[] facetPath = __is.readStringSeq(); + String[] facetPath = _is.readStringSeq(); String facet; if(facetPath.length > 0) { @@ -107,7 +249,7 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback facet = ""; } - String operation = __is.readString(); + String operation = _is.readString(); Ice.RequestFailedException ex = null; switch(replyStatus) @@ -147,7 +289,7 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback case ReplyStatus.replyUnknownLocalException: case ReplyStatus.replyUnknownUserException: { - String unknown = __is.readString(); + String unknown = _is.readString(); Ice.UnknownException ex = null; switch(replyStatus) @@ -186,234 +328,61 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback throw new Ice.UnknownReplyStatusException(); } } + + _state |= Done; + if(replyStatus == ReplyStatus.replyOK) + { + _state |= OK; + } + _monitor.notifyAll(); } } catch(Ice.LocalException ex) { - __finished(ex); + __finished(ex, true); return; } assert(replyStatus == ReplyStatus.replyOK || replyStatus == ReplyStatus.replyUserException); - - try - { - __response(replyStatus == ReplyStatus.replyOK); - } - catch(java.lang.Exception ex) - { - __warning(ex); - __releaseCallback(); - } + __response(); } - - public final void - __finished(Ice.LocalException exc) + public final boolean __send(boolean synchronous) { - synchronized(__monitor) + while(true) { - if(__os != null) // Might be called from __prepare or before __prepare + int interval = 0; + try { - if(_timerTask != null && _proxy.__reference().getInstance().timer().cancel(_timerTask)) - { - _timerTask = null; // Timer cancelled. - } - - while(_timerTask != null) + _delegate = _proxy.__getDelegate(true); + boolean sent = _delegate.__getRequestHandler().sendAsyncRequest(this); + if(synchronous) // Only set sentSynchronously_ If called synchronously by the user thread. { - try - { - __monitor.wait(); - } - catch(java.lang.InterruptedException ex) - { - } + _sentSynchronously = sent; } + break; } - } - - // - // NOTE: at this point, synchronization isn't needed, no other threads should be - // calling on the callback. - // - - try - { - handleException(exc); // This will throw if the invocation can't be retried. - } - catch(Ice.LocalException ex) - { - __exception(ex); - } - } - - public final void - __finished(LocalExceptionWrapper ex) - { - assert(__os != null && !_sent); - - // - // NOTE: at this point, synchronization isn't needed, no other threads should be - // calling on the callback. The LocalExceptionWrapper exception is only called - // before the invocation is sent. - // - - try - { - handleException(ex); // This will throw if the invocation can't be retried. - } - catch(Ice.LocalException exc) - { - __exception(exc); - } - } - - public final void - __retry(int cnt, int interval) - { - // - // This method is called by the proxy to retry an invocation. It's safe to update - // the count here without synchronization, no other threads can access this object. - // - _cnt = cnt; - if(interval > 0) - { - assert(__os != null); - __os.instance().retryQueue().add(this, interval); - } - else - { - __send(); - } - } - - public final boolean - __send() - { - try - { - _sent = false; - _response = false; - _delegate = _proxy.__getDelegate(true); - _sentSynchronously = _delegate.__getRequestHandler().sendAsyncRequest(this); - } - catch(LocalExceptionWrapper ex) - { - handleException(ex); // Might call __send() again upon retry and assign _sentSynchronously - } - catch(Ice.LocalException ex) - { - handleException(ex); // Might call __send() again upon retry and assign _sentSynchronously - } - return _sentSynchronously; - } - - protected final void - __prepare(Ice.ObjectPrx prx, String operation, Ice.OperationMode mode, java.util.Map<String, String> context) - { - assert(__os != null); - - _proxy = (Ice.ObjectPrxHelperBase)prx; - _delegate = null; - _cnt = 0; - _mode = mode; - _sentSynchronously = false; - - // - // Can't call async via a batch proxy. - // - if(_proxy.ice_isBatchOneway() || _proxy.ice_isBatchDatagram()) - { - throw new Ice.FeatureNotSupportedException("can't send batch requests with AMI"); - } - - __os.writeBlob(IceInternal.Protocol.requestHdr); - - Reference ref = _proxy.__reference(); - - ref.getIdentity().__write(__os); - - // - // For compatibility with the old FacetPath. - // - String facet = ref.getFacet(); - if(facet == null || facet.length() == 0) - { - __os.writeStringSeq(null); - } - else - { - String[] facetPath = { facet }; - __os.writeStringSeq(facetPath); - } - - __os.writeString(operation); - - __os.writeByte((byte)mode.ordinal()); - - if(context != null) - { - // - // Explicit context - // - Ice.ContextHelper.write(__os, context); - } - else - { - // - // Implicit context - // - Ice.ImplicitContextI implicitContext = ref.getInstance().getImplicitContext(); - java.util.Map<String, String> prxContext = ref.getContext(); - - if(implicitContext == null) + catch(LocalExceptionWrapper ex) { - Ice.ContextHelper.write(__os, prxContext); + interval = handleException(ex); } - else + catch(Ice.LocalException ex) { - implicitContext.write(prxContext, __os); + interval = handleException(ex, false); } - } - - __os.startWriteEncaps(); - } - protected abstract void __response(boolean ok); - - protected void - __throwUserException() - throws Ice.UserException - { - try - { - __is.startReadEncaps(); - __is.throwException(); - } - catch(Ice.UserException ex) - { - __is.endReadEncaps(); - throw ex; - } - } - - private void - handleException(LocalExceptionWrapper ex) - { - if(_mode == Ice.OperationMode.Nonmutating || _mode == Ice.OperationMode.Idempotent) - { - _proxy.__handleExceptionWrapperRelaxed(_delegate, ex, this, _cnt); - } - else - { - _proxy.__handleExceptionWrapper(_delegate, ex, this); + if(interval > 0) + { + _instance.retryQueue().add(this, interval); + return false; + } } + return _sentSynchronously; } - private void - handleException(Ice.LocalException exc) + private int handleException(Ice.LocalException exc, boolean sent) { + Ice.IntHolder interval = new Ice.IntHolder(0); try { // @@ -426,7 +395,7 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback // "at-most-once" (see the implementation of the checkRetryAfterException method of // the ProxyFactory class for the reasons why it can be useful). // - if(!_sent || + if(!sent || exc instanceof Ice.CloseConnectionException || exc instanceof Ice.ObjectNotExistException) { @@ -444,32 +413,43 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback { if(_mode == Ice.OperationMode.Nonmutating || _mode == Ice.OperationMode.Idempotent) { - _proxy.__handleExceptionWrapperRelaxed(_delegate, ex, this, _cnt); + _cnt = _proxy.__handleExceptionWrapperRelaxed(_delegate, ex, interval, _cnt); } else { - _proxy.__handleExceptionWrapper(_delegate, ex, this); + _proxy.__handleExceptionWrapper(_delegate, ex); } } catch(Ice.LocalException ex) { - _proxy.__handleException(_delegate, ex, this, _cnt); + _cnt = _proxy.__handleException(_delegate, ex, interval, _cnt); } + return interval.value; } - private final void - __runTimerTask(Ice.ConnectionI connection) + private int handleException(LocalExceptionWrapper ex) { - synchronized(__monitor) + Ice.IntHolder interval = new Ice.IntHolder(0); + if(_mode == Ice.OperationMode.Nonmutating || _mode == Ice.OperationMode.Idempotent) + { + _cnt = _proxy.__handleExceptionWrapperRelaxed(_delegate, ex, interval, _cnt); + } + else { - assert(_timerTask != null && _sent); // Can only be set once the request is sent. + _proxy.__handleExceptionWrapper(_delegate, ex); + } + return interval.value; + } - if(_response) // If the response was just received, don't close the connection. - { - connection = null; - } + private final void + __runTimerTask() + { + Ice.ConnectionI connection; + synchronized(_monitor) + { + connection = _timerTaskConnection; + _timerTaskConnection = null; _timerTask = null; - __monitor.notifyAll(); } if(connection != null) @@ -478,12 +458,14 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback } } - private boolean _sent; - private boolean _sentSynchronously; - private boolean _response; - private Ice.ObjectPrxHelperBase _proxy; + protected Ice.ObjectPrxHelperBase _proxy; + + private Ice.ConnectionI _timerTaskConnection; + private TimerTask _timerTask; + private Ice._ObjectDel _delegate; private int _cnt; private Ice.OperationMode _mode; - private TimerTask _timerTask; + + private static final java.util.Map<String, String> _emptyContext = new java.util.HashMap<String, String>(); } diff --git a/java/src/IceInternal/OutgoingAsyncMessageCallback.java b/java/src/IceInternal/OutgoingAsyncMessageCallback.java index 3f875de3336..93a1fe94d02 100644 --- a/java/src/IceInternal/OutgoingAsyncMessageCallback.java +++ b/java/src/IceInternal/OutgoingAsyncMessageCallback.java @@ -9,152 +9,30 @@ package IceInternal; -abstract public class OutgoingAsyncMessageCallback +// +// This interface is used by the connection to handle OutgoingAsync +// and BatchOutgoingAsync messages. +// +public interface OutgoingAsyncMessageCallback { - 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 - __sent(Instance instance) - { - try - { - ((Ice.AMISentCallback)this).ice_sent(); - } - catch(java.lang.Exception ex) - { - __warning(instance, ex); - } - } - - public void - __exception(Ice.LocalException exc) - { - try - { - ice_exception(exc); - } - catch(java.lang.Exception ex) - { - __warning(ex); - } - finally - { - __releaseCallback(); - } - } - - protected synchronized void - finalize() - throws Throwable - { - assert(__os == null); - assert(__is == null); - } - - protected void - __acquireCallback(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 - __releaseCallback(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(ThreadPoolCurrent current) - { - current.ioCompleted(); - __exception(ex); - } - }); - } - catch(Ice.CommunicatorDestroyedException exc) - { - __releaseCallback(); - throw exc; // CommunicatorDestroyedException is the only exception that can propagate directly. - } - } - } - - protected void - __releaseCallback() - { - synchronized(__monitor) - { - assert(__is != null); - __is = null; - - assert(__os != null); - __os = null; - - __monitor.notify(); - } - } - - protected void - __warning(java.lang.Exception ex) - { - if(__os != null) - { - __warning(__os.instance(), ex); - } - } - - protected void - __warning(Instance instance, java.lang.Exception ex) - { - if(instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.AMICallback", 1) > 0) - { - String s = "exception raised by AMI callback:\n" + Ex.toString(ex); - instance.initializationData().logger.warning(s); - } - } - - protected final java.lang.Object __monitor = new java.lang.Object(); - protected BasicStream __is; - protected BasicStream __os; -}; + // + // Called by the connection when the message is confirmed sent. The connection is locked + // when this is called so this method can call the sent callback. Instead, this method + // returns true if there's a sent callback and false otherwise. If true is returned, the + // connection will call the __sent() method bellow (which in turn should call the sent + // callback). + // + public abstract boolean __sent(Ice.ConnectionI connection); + + // + // Called by the connection to call the user sent callback. + // + public abstract void __sent(); + + // + // Called by the connection when the request failed. The boolean indicates whether or + // not the message was possibly sent (this is useful for retry to figure out whether + // or not the request can't be retried without breaking at-most-once semantics.) + // + public abstract void __finished(Ice.LocalException ex, boolean sent); +} diff --git a/java/src/IceInternal/OutgoingMessageCallback.java b/java/src/IceInternal/OutgoingMessageCallback.java index 4f11091ddc9..b2ef7318d12 100644 --- a/java/src/IceInternal/OutgoingMessageCallback.java +++ b/java/src/IceInternal/OutgoingMessageCallback.java @@ -12,5 +12,5 @@ package IceInternal; public interface OutgoingMessageCallback { void sent(boolean notify); - void finished(Ice.LocalException ex); + void finished(Ice.LocalException ex, boolean sent); } diff --git a/java/src/IceInternal/ProxyBatchOutgoingAsync.java b/java/src/IceInternal/ProxyBatchOutgoingAsync.java new file mode 100644 index 00000000000..c6f7efdbe5b --- /dev/null +++ b/java/src/IceInternal/ProxyBatchOutgoingAsync.java @@ -0,0 +1,26 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +public class ProxyBatchOutgoingAsync extends BatchOutgoingAsync +{ + public ProxyBatchOutgoingAsync(Ice.ObjectPrx prx, String operation, CallbackBase callback) + { + super(((Ice.ObjectPrxHelperBase)prx).__reference().getInstance(), operation, callback); + _proxy = prx; + } + + public Ice.ObjectPrx getProxy() + { + return _proxy; + } + + private Ice.ObjectPrx _proxy; +} diff --git a/java/src/IceInternal/ProxyFactory.java b/java/src/IceInternal/ProxyFactory.java index 00472d81bd4..7a77a756856 100644 --- a/java/src/IceInternal/ProxyFactory.java +++ b/java/src/IceInternal/ProxyFactory.java @@ -99,7 +99,7 @@ public final class ProxyFactory } public int - checkRetryAfterException(Ice.LocalException ex, Reference ref, final OutgoingAsync out, int cnt) + checkRetryAfterException(Ice.LocalException ex, Reference ref, Ice.IntHolder sleepInterval, int cnt) { TraceLevels traceLevels = _instance.traceLevels(); Ice.Logger logger = _instance.initializationData().logger; @@ -135,9 +135,9 @@ public final class ProxyFactory logger.trace(traceLevels.retryCat, s); } - if(out != null) + if(sleepInterval != null) { - out.__retry(cnt, 0); + sleepInterval.value = 0; } return cnt; // We must always retry, so we don't look at the retry count. } @@ -237,9 +237,9 @@ public final class ProxyFactory logger.trace(traceLevels.retryCat, s); } - if(out != null) + if(sleepInterval != null) { - out.__retry(cnt, interval); + sleepInterval.value = interval; } else if(interval > 0) { diff --git a/java/src/IceInternal/RetryQueue.java b/java/src/IceInternal/RetryQueue.java index 44802e60dca..b8a187b0859 100644 --- a/java/src/IceInternal/RetryQueue.java +++ b/java/src/IceInternal/RetryQueue.java @@ -43,5 +43,4 @@ public class RetryQueue final private Instance _instance; final private java.util.HashSet<RetryTask> _requests = new java.util.HashSet<RetryTask>(); -}; - +} diff --git a/java/src/IceInternal/RetryTask.java b/java/src/IceInternal/RetryTask.java index a9266657a78..636e1d5f3e4 100644 --- a/java/src/IceInternal/RetryTask.java +++ b/java/src/IceInternal/RetryTask.java @@ -24,11 +24,11 @@ class RetryTask implements TimerTask { try { - _outAsync.__send(); + _outAsync.__send(false); } catch(Ice.LocalException ex) { - _outAsync.__releaseCallback(ex); + _outAsync.__exceptionAsync(ex); } } } @@ -36,7 +36,7 @@ class RetryTask implements TimerTask public void destroy() { - _outAsync.__releaseCallback(new Ice.CommunicatorDestroyedException()); + _outAsync.__exceptionAsync(new Ice.CommunicatorDestroyedException()); } private final RetryQueue _queue; |