示例#1
0
        finishBatchRequest(Ice.OutputStream os, Ice.ObjectPrx proxy, string operation)
        {
            //
            // No need for synchronization, no other threads are supposed
            // to modify the queue since we set _batchStreamInUse to true.
            //
            Debug.Assert(_batchStreamInUse);
            _batchStream.swap(os);

            try
            {
                _batchStreamCanFlush = true; // Allow flush to proceed even if the stream is marked in use.

                if (_maxSize > 0 && _batchStream.size() >= _maxSize)
                {
                    proxy.begin_ice_flushBatchRequests(); // Auto flush
                }

                Debug.Assert(_batchMarker < _batchStream.size());
                if (_interceptor != null)
                {
                    _request.reset(proxy, operation, _batchStream.size() - _batchMarker);
                    _interceptor(_request, _batchRequestNum, _batchMarker);
                }
                else
                {
                    bool compress;
                    if (((Ice.ObjectPrxHelperBase)proxy).iceReference().getCompressOverride(out compress))
                    {
                        _batchCompress |= compress;
                    }
                    _batchMarker = _batchStream.size();
                    ++_batchRequestNum;
                }
            }
            finally
            {
                lock (this)
                {
                    _batchStream.resize(_batchMarker);
                    _batchStreamInUse    = false;
                    _batchStreamCanFlush = false;
                    System.Threading.Monitor.PulseAll(this);
                }
            }
        }
示例#2
0
    internal static void batchOneways(Test.MyClassPrx p)
    {
        byte[] bs1 = new byte[10 * 1024];

        Test.MyClassPrx batch = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway());
        batch.end_ice_flushBatchRequests(batch.begin_ice_flushBatchRequests());

        test(batch.begin_ice_flushBatchRequests().isSent());
        test(batch.begin_ice_flushBatchRequests().isCompleted_());
        test(batch.begin_ice_flushBatchRequests().sentSynchronously());

        for (int i = 0; i < 30; ++i)
        {
            batch.begin_opByteSOneway(bs1).whenCompleted(
                () =>
            {
            },
                (Ice.Exception ex) =>
            {
                test(false);
            });
        }

        int count = 0;

        while (count < 27) // 3 * 9 requests auto-flushed.
        {
            count += p.opByteSOnewayCallCount();
            System.Threading.Thread.Sleep(10);
        }

        if (batch.ice_getConnection() != null)
        {
            Test.MyClassPrx batch1 = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway());
            Test.MyClassPrx batch2 = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway());

            batch1.begin_ice_ping();
            batch2.begin_ice_ping();
            batch1.end_ice_flushBatchRequests(batch1.begin_ice_flushBatchRequests());
            batch1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
            batch1.begin_ice_ping();
            batch2.begin_ice_ping();

            batch1.ice_getConnection();
            batch2.ice_getConnection();

            batch1.begin_ice_ping();
            batch1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);

            batch1.begin_ice_ping();
            batch2.begin_ice_ping();
        }

        Ice.Identity identity = new Ice.Identity();
        identity.name = "invalid";
        Ice.ObjectPrx batch3 = batch.ice_identity(identity);
        batch3.begin_ice_ping();
        batch3.end_ice_flushBatchRequests(batch3.begin_ice_flushBatchRequests());

        // Make sure that a bogus batch request doesn't cause troubles to other ones.
        batch3.begin_ice_ping();
        batch.begin_ice_ping();
        batch.end_ice_flushBatchRequests(batch.begin_ice_flushBatchRequests());
        batch.begin_ice_ping();
    }