summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/CommunicatorBatchOutgoingAsync.java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-12-08 14:10:38 -0800
committerMark Spruiell <mes@zeroc.com>2009-12-08 14:10:38 -0800
commit55527152af356fda6037f836c978c2b3a2e2f045 (patch)
treed1872fe6e2d01fa15455a462df090ef94799cb5b /java/src/IceInternal/CommunicatorBatchOutgoingAsync.java
parentvsplugin fxcop issues (diff)
downloadice-55527152af356fda6037f836c978c2b3a2e2f045.tar.bz2
ice-55527152af356fda6037f836c978c2b3a2e2f045.tar.xz
ice-55527152af356fda6037f836c978c2b3a2e2f045.zip
- bug 3533: add async version of Connection/Communicator
flushBatchRequests operation - Slice file cleanup in C# tests - Updating C++ dependencies
Diffstat (limited to 'java/src/IceInternal/CommunicatorBatchOutgoingAsync.java')
-rw-r--r--java/src/IceInternal/CommunicatorBatchOutgoingAsync.java134
1 files changed, 134 insertions, 0 deletions
diff --git a/java/src/IceInternal/CommunicatorBatchOutgoingAsync.java b/java/src/IceInternal/CommunicatorBatchOutgoingAsync.java
new file mode 100644
index 00000000000..3e0fbda6ae2
--- /dev/null
+++ b/java/src/IceInternal/CommunicatorBatchOutgoingAsync.java
@@ -0,0 +1,134 @@
+// **********************************************************************
+//
+// 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 CommunicatorBatchOutgoingAsync extends BatchOutgoingAsync
+{
+ public CommunicatorBatchOutgoingAsync(Ice.Communicator communicator, Instance instance, String operation,
+ CallbackBase callback)
+ {
+ super(instance, operation, callback);
+ _communicator = communicator;
+
+ //
+ // _useCount is initialized to 1 to prevent premature callbacks.
+ // The caller must invoke ready() after all flush requests have
+ // been initiated.
+ //
+ _useCount = 1;
+
+ //
+ // Assume all connections are flushed synchronously.
+ //
+ _sentSynchronously = true;
+ }
+
+ @Override
+ public Ice.Communicator getCommunicator()
+ {
+ return _communicator;
+ }
+
+ public void flushConnection(Ice.Connection con)
+ {
+ synchronized(_monitor)
+ {
+ ++_useCount;
+ }
+ con.begin_flushBatchRequests(_cb);
+ }
+
+ public void ready()
+ {
+ check(null, null, true);
+ }
+
+ private void completed(Ice.AsyncResult r)
+ {
+ Ice.Connection con = r.getConnection();
+ assert(con != null);
+
+ try
+ {
+ con.end_flushBatchRequests(r);
+ assert(false); // completed() should only be called when an exception occurs.
+ }
+ catch(Ice.LocalException ex)
+ {
+ check(r, ex, false);
+ }
+ }
+
+ private void sent(Ice.AsyncResult r)
+ {
+ check(r, null, r.sentSynchronously());
+ }
+
+ private void check(Ice.AsyncResult r, Ice.LocalException ex, boolean userThread)
+ {
+ boolean done = false;
+
+ synchronized(_monitor)
+ {
+ assert(_useCount > 0);
+ --_useCount;
+
+ //
+ // We report that the communicator flush request was sent synchronously
+ // if all of the connection flush requests are sent synchronously.
+ //
+ if((r != null && !r.sentSynchronously()) || ex != null)
+ {
+ _sentSynchronously = false;
+ }
+
+ if(_useCount == 0)
+ {
+ done = true;
+ _state |= Done | OK | Sent;
+ _monitor.notifyAll();
+ }
+ }
+
+ if(done)
+ {
+ //
+ // sentSynchronously_ is immutable here.
+ //
+ if(!_sentSynchronously && userThread)
+ {
+ __sentAsync();
+ }
+ else
+ {
+ assert(_sentSynchronously == userThread); // sentSynchronously && !userThread is impossible.
+ __sent();
+ }
+ }
+ }
+
+ private Ice.Communicator _communicator;
+ private int _useCount;
+
+ private Ice.AsyncCallback _cb = new Ice.AsyncCallback()
+ {
+ @Override
+ public void completed(Ice.AsyncResult r)
+ {
+ CommunicatorBatchOutgoingAsync.this.completed(r);
+ }
+
+ @Override
+ public void sent(Ice.AsyncResult r)
+ {
+ CommunicatorBatchOutgoingAsync.this.sent(r);
+ }
+ };
+}