prepareBatchRequest(BasicStream os)
        {
            lock(this)
            {
                while(_batchStreamInUse)
                {
                    Monitor.Wait(this);
                }

                if(_batchStream.isEmpty())
                {
                    try
                    {
                        _batchStream.writeBlob(Protocol.requestBatchHdr);
                    }
                    catch(Ice.LocalException ex)
                    {
                        throw ex;
                    }
                }

                _batchStreamInUse = true;
                _batchMarker = _batchStream.size();
                _batchStream.swap(os);
            }
        }
示例#2
0
        internal WSEndpoint(ProtocolInstance instance, EndpointI del, BasicStream s)
        {
            _instance = instance;
            _delegate = (IPEndpointI)del;

            _resource = s.readString();
        }
示例#3
0
 public Ice.ObjectPrx streamToProxy(BasicStream s)
 {
     Ice.Identity ident = new Ice.Identity();
     ident.read__(s);
     
     Reference r = instance_.referenceFactory().create(ident, s);
     return referenceToProxy(r);
 }
        public void finishBatchRequest(BasicStream os)
        {
            try
            {
                lock(this)
                {
                    _batchStream.swap(os);

                    if(_batchAutoFlushSize > 0 && (_batchStream.size() > _batchAutoFlushSize))
                    {
                        //
                        // Temporarily save the last request.
                        //
                        byte[] lastRequest = new byte[_batchStream.size() - _batchMarker];
                        Buffer buffer = _batchStream.getBuffer();
                        buffer.b.position(_batchMarker);
                        buffer.b.get(lastRequest);
                        _batchStream.resize(_batchMarker, false);

                        int invokeNum = _batchRequestNum;
                        BasicStream stream = new BasicStream(_reference.getInstance(),
                                                             Ice.Util.currentProtocolEncoding);
                        stream.swap(_batchStream);

                        _adapter.getThreadPool().dispatch(() =>
                        {
                            invokeAll(stream, 0, invokeNum, true);
                        }, null);

                        //
                        // Reset the batch.
                        //
                        _batchRequestNum = 0;
                        _batchMarker = 0;

                        //
                        // Start a new batch with the last message that caused us to go over the limit.
                        //
                        _batchStream.writeBlob(Protocol.requestBatchHdr);
                        _batchStream.writeBlob(lastRequest);
                    }

                    //
                    // Increment the number of requests in the batch.
                    //
                    Debug.Assert(_batchStreamInUse);
                    ++_batchRequestNum;
                    _batchStreamInUse = false;
                    Monitor.PulseAll(this);
                }
            }
            catch(Ice.LocalException ex)
            {
                abortBatchRequest();
                throw ex;
            }
        }
示例#5
0
 //
 // Writeable stream constructor
 //
 public StreamWrapper(BasicStream s)
 {
     type_ = StreamType.Write;
     s_ = s;
     spos_ = s.pos();
     bytes_ = new byte[254];
     pos_ = 0;
     length_ = 0;
 }
示例#6
0
 public IPEndpointI(ProtocolInstance instance, BasicStream s)
 {
     instance_ = instance;
     host_ = s.readString();
     port_ = s.readInt();
     sourceAddr_ = null;
     connectionId_ = "";
     _hashInitialized = false;
 }
示例#7
0
 //
 // Readable stream constructor
 //
 public StreamWrapper(int size, BasicStream s)
 {
     type_ = StreamType.Read;
     s_ = s;
     spos_ = 0;
     bytes_ = null;
     pos_ = 0;
     length_ = size;
 }
示例#8
0
        public OpaqueEndpointI(short type, BasicStream s)
        {
            _type = type;
            _rawEncoding = s.getReadEncoding();
            int sz = s.getReadEncapsSize();
            _rawBytes = new byte[sz];
            s.readBlob(_rawBytes);

            calcHashValue();
        }
示例#9
0
        public static void dumpStream(BasicStream stream)
        {
            int pos = stream.pos();
            stream.pos(0);

            byte[] data = new byte[stream.size()];
            stream.readBlob(data);
            dumpOctets(data);

            stream.pos(pos);
        }
示例#10
0
 prepareBatchRequest(BasicStream os)
 {
     lock(this)
     {
         if(_exception != null)
         {
             throw _exception;
         }
         waitStreamInUse(false);
         _batchStreamInUse = true;
         _batchStream.swap(os);
     }
 }
示例#11
0
        public Outgoing(RequestHandler handler, string operation, Ice.OperationMode mode,
                        Dictionary<string, string> context, InvocationObserver observer)
        {
            _state = StateUnsent;
            _sent = false;
            _handler = handler;
            _observer = observer;
            _encoding = Protocol.getCompatibleEncoding(handler.getReference().getEncoding());
            _os = new BasicStream(_handler.getReference().getInstance(), Ice.Util.currentProtocolEncoding);

            Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(_handler.getReference().getProtocol()));

            writeHeader(operation, mode, context);
        }
示例#12
0
 public ConnectRequestHandler(Reference @ref, Ice.ObjectPrx proxy, Ice.ObjectDelM_ del)
 {
     _reference = @ref;
     _response = _reference.getMode() == Reference.Mode.ModeTwoway;
     _proxy = (Ice.ObjectPrxHelperBase)proxy;
     _delegate = del;
     _batchAutoFlush = @ref.getInstance().initializationData().properties.getPropertyAsIntWithDefault(
         "Ice.BatchAutoFlush", 1) > 0 ? true : false;
     _initialized = false;
     _flushing = false;
     _batchRequestInProgress = false;
     _batchRequestsSize = Protocol.requestBatchHdr.Length;
     _batchStream = new BasicStream(@ref.getInstance(), _batchAutoFlush);
     _updateRequestHandler = false;
 }
示例#13
0
 public UdpEndpointI(ProtocolInstance instance, BasicStream s) :
     base(instance, s)
 {
     if(s.getReadEncoding().Equals(Ice.Util.Encoding_1_0))
     {
         s.readByte();
         s.readByte();
         s.readByte();
         s.readByte();
     }
     // Not transmitted.
     //_connect = s.readBool();
     _connect = false;
     _compress = s.readBool();
 }
示例#14
0
        CollocatedRequestHandler(Reference @ref, Ice.ObjectAdapter adapter)
        {
            _reference = @ref;
            _dispatcher = _reference.getInstance().initializationData().dispatcher != null;
            _response = _reference.getMode() == Reference.Mode.ModeTwoway;
            _adapter = (Ice.ObjectAdapterI)adapter;

            _logger = _reference.getInstance().initializationData().logger; // Cached for better performance.
            _traceLevels = _reference.getInstance().traceLevels(); // Cached for better performance.
            _batchAutoFlushSize = @ref.getInstance().batchAutoFlushSize();
            _requestId = 0;
            _batchStreamInUse = false;
            _batchRequestNum = 0;
            _batchStream = new BasicStream(@ref.getInstance(), Ice.Util.currentProtocolEncoding);
        }
示例#15
0
        internal static void traceRecv(BasicStream str, Ice.Logger logger, TraceLevels tl)
        {
            if(tl.protocol >= 1)
            {
                int p = str.pos();
                str.pos(0);

                using(System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    byte type = printMessage(s, str);

                    logger.trace(tl.protocolCat, "received " + getMessageTypeAsString(type) + " " + s.ToString());
                }
                str.pos(p);
            }
        }
示例#16
0
 public void proxyToStream(Ice.ObjectPrx proxy, BasicStream s)
 {
     if(proxy != null)
     {
         Ice.ObjectPrxHelperBase h = (Ice.ObjectPrxHelperBase)proxy;
         Reference r = h.reference__();
         r.getIdentity().write__(s);
         r.streamWrite(s);
     }
     else
     {
         Ice.Identity ident = new Ice.Identity();
         ident.name = "";
         ident.category = "";
         ident.write__(s);
     }
 }
示例#17
0
        internal static void trace(string heading, BasicStream str, Ice.Logger logger, TraceLevels tl)
        {
            if(tl.protocol >= 1)
            {
                int p = str.pos();
                str.pos(0);

                using(System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture))
                {
                    s.Write(heading);
                    printMessage(s, str);

                    logger.trace(tl.protocolCat, s.ToString());
                }
                str.pos(p);
            }
        }
示例#18
0
        public void prepareBatchRequest(BasicStream os)
        {
            lock(this)
            {
                while(_batchRequestInProgress)
                {
                    System.Threading.Monitor.Wait(this);
                }

                if(!initialized())
                {
                    _batchRequestInProgress = true;
                    _batchStream.swap(os);
                    return;
                }
            }
            _connection.prepareBatchRequest(os);
        }
示例#19
0
        protected internal IncomingBase(Instance instance, ResponseHandler handler, Ice.ConnectionI connection, 
                                        Ice.ObjectAdapter adapter, bool response, byte compress, int requestId)
        {
            instance_ = instance;
            responseHandler_ = handler;
            response_ = response;
            compress_ = compress;
            if(response_)
            {
                os_ = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
            }

            current_ = new Ice.Current();
            current_.id = new Ice.Identity();
            current_.adapter = adapter;
            current_.con = connection;
            current_.requestId = requestId;

            cookie_ = null;
        }
示例#20
0
        public BatchRequestQueue(Instance instance, bool datagram)
        {
            Ice.InitializationData initData = instance.initializationData();
            _interceptor = initData.batchRequestInterceptor;
            _batchStreamInUse = false;
            _batchRequestNum = 0;
            _batchStream = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
            _batchStream.writeBlob(Protocol.requestBatchHdr);
            _batchMarker = _batchStream.size();
            _request = new BatchRequestI(this);

            _maxSize = instance.batchAutoFlushSize();
            if(_maxSize > 0 && datagram)
            {
                int udpSndSize = initData.properties.getPropertyAsIntWithDefault("Ice.UDP.SndSize",
                                                                                 65535 - _udpOverhead);
                if(udpSndSize < _maxSize)
                {
                    _maxSize = udpSndSize;
                }
            }
        }
示例#21
0
        public void prepareBatchRequest(BasicStream os)
        {
            _m.Lock();
            try
            {
                while(_batchRequestInProgress)
                {
                    _m.Wait();
                }

                if(!initialized())
                {
                    _batchRequestInProgress = true;
                    _batchStream.swap(os);
                    return;
                }
            }
            finally
            {
                _m.Unlock();
            }
            _connection.prepareBatchRequest(os);
        }
示例#22
0
        public void abortBatchRequest()
        {
            _m.Lock();
            try
            {
                if(!initialized())
                {
                    Debug.Assert(_batchRequestInProgress);
                    _batchRequestInProgress = false;
                    _m.NotifyAll();

                    BasicStream dummy = new BasicStream(_reference.getInstance(), _batchAutoFlush);
                    _batchStream.swap(dummy);
                    _batchRequestsSize = Protocol.requestBatchHdr.Length;

                    return;
                }
            }
            finally
            {
                _m.Unlock();
            }
            _connection.abortBatchRequest();
        }
示例#23
0
 public BatchOutgoing(RequestHandler handler, InvocationObserver observer)
 {
     _handler = handler;
     _sent = false;
     _observer = observer;
     _os = new BasicStream(handler.getReference().getInstance(), Ice.Util.currentProtocolEncoding);
     Protocol.checkSupportedProtocol(handler.getReference().getProtocol());
 }
示例#24
0
 public BatchOutgoing(Ice.ConnectionI connection, Instance instance, InvocationObserver observer)
 {
     _connection = connection;
     _sent = false;
     _observer = observer;
     _os = new BasicStream(instance, Ice.Util.currentProtocolEncoding);
 }
示例#25
0
        public void finished(BasicStream istr)
        {
            _m.Lock();
            try
            {
                Debug.Assert(_handler.getReference().getMode() == Reference.Mode.ModeTwoway); // Only for twoways.

                Debug.Assert(_state <= StateInProgress);

                if(_remoteObserver != null)
                {
                    _remoteObserver.reply(istr.size() - Protocol.headerSize - 4);
                    _remoteObserver.detach();
                    _remoteObserver = null;
                }

                if(_is == null)
                {
                    _is = new IceInternal.BasicStream(_handler.getReference().getInstance(), 
                                                      Ice.Util.currentProtocolEncoding);
                }
                _is.swap(istr);
                byte replyStatus = _is.readByte();

                switch(replyStatus)
                {
                    case ReplyStatus.replyOK:
                    {
                        _state = StateOK; // The state must be set last, in case there is an exception.
                        break;
                    }

                    case ReplyStatus.replyUserException:
                    {
                        if(_observer != null)
                        {
                            _observer.userException();
                        }
                        _state = StateUserException; // The state must be set last, in case there is an exception.
                        break;
                    }

                    case ReplyStatus.replyObjectNotExist:
                    case ReplyStatus.replyFacetNotExist:
                    case ReplyStatus.replyOperationNotExist:
                    {
                        Ice.RequestFailedException ex = null;
                        switch(replyStatus)
                        {
                            case ReplyStatus.replyObjectNotExist:
                            {
                                ex = new Ice.ObjectNotExistException();
                                break;
                            }

                            case ReplyStatus.replyFacetNotExist:
                            {
                                ex = new Ice.FacetNotExistException();
                                break;
                            }

                            case ReplyStatus.replyOperationNotExist:
                            {
                                ex = new Ice.OperationNotExistException();
                                break;
                            }

                            default:
                            {
                                Debug.Assert(false);
                                break;
                            }
                        }

                        ex.id = new Ice.Identity();
                        ex.id.read__(_is);

                        //
                        // For compatibility with the old FacetPath.
                        //
                        string[] facetPath = _is.readStringSeq();
                        if(facetPath.Length > 0)
                        {
                            if(facetPath.Length > 1)
                            {
                                throw new Ice.MarshalException();
                            }
                            ex.facet = facetPath[0];
                        }
                        else
                        {
                            ex.facet = "";
                        }

                        ex.operation = _is.readString();
                        _exception = ex;

                        _state = StateLocalException; // The state must be set last, in case there is an exception.
                        break;
                    }

                    case ReplyStatus.replyUnknownException:
                    case ReplyStatus.replyUnknownLocalException:
                    case ReplyStatus.replyUnknownUserException:
                    {
                        Ice.UnknownException ex = null;
                        switch(replyStatus)
                        {
                            case ReplyStatus.replyUnknownException:
                            {
                                ex = new Ice.UnknownException();
                                break;
                            }

                            case ReplyStatus.replyUnknownLocalException:
                            {
                                ex = new Ice.UnknownLocalException();
                                break;
                            }

                            case ReplyStatus.replyUnknownUserException:
                            {
                                ex = new Ice.UnknownUserException();
                                break;
                            }

                            default:
                            {
                                Debug.Assert(false);
                                break;
                            }
                        }

                        ex.unknown = _is.readString();
                        _exception = ex;

                        _state = StateLocalException; // The state must be set last, in case there is an exception.
                        break;
                    }

                    default:
                    {
                        _exception = new Ice.UnknownReplyStatusException();
                        _state = StateLocalException;
                        break;
                    }
                }

                _m.Notify();
            }
            finally
            {
                _m.Unlock();
            }
        }
示例#26
0
 internal Request(BasicStream os)
 {
     this.os = new BasicStream(os.instance());
     this.os.swap(os);
 }
示例#27
0
 public virtual void streamWriteImpl(BasicStream s)
 {
     s.writeString(host_);
     s.writeInt(port_);
 }
示例#28
0
        private void flushRequests()
        {
            _m.Lock();
            try
            {
                Debug.Assert(_connection != null && !_initialized);

                while(_batchRequestInProgress)
                {
                    _m.Wait();
                }

                //
                // 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;
            }
            finally
            {
                _m.Unlock();
            }

            LinkedList<Request> sentCallbacks = new LinkedList<Request>();
            try
            {
                LinkedListNode<Request> p = _requests.First; // _requests is immutable when _flushing = true
                while(p != null)
                {
                    Request request = p.Value;
                    if(request.@out != null)
                    {
                        if(_connection.sendAsyncRequest(request.@out, _compress, _response, out request.sentCallback))
                        {
                            if(request.sentCallback != null)
                            {
                                sentCallbacks.AddLast(request);
                            }
                        }
                    }
                    else if(request.batchOut != null)
                    {
                        if(_connection.flushAsyncBatchRequests(request.batchOut, out request.sentCallback))
                        {
                            if(request.sentCallback != null)
                            {
                                sentCallbacks.AddLast(request);
                            }
                        }
                    }
                    else
                    {
                        BasicStream os = new BasicStream(request.os.instance());
                        _connection.prepareBatchRequest(os);
                        try
                        {
                            request.os.pos(0);
                            os.writeBlob(request.os.readBlob(request.os.size()));
                        }
                        catch(Ice.LocalException)
                        {
                            _connection.abortBatchRequest();
                            throw;
                        }
                        _connection.finishBatchRequest(os, _compress);
                    }
                    LinkedListNode<Request> tmp = p;
                    p = p.Next;
                    _requests.Remove(tmp);
                }
            }
            catch(LocalExceptionWrapper ex)
            {
                _m.Lock();
                try
                {
                    Debug.Assert(_exception == null && _requests.Count > 0);
                    _exception = ex.get();
                    _reference.getInstance().clientThreadPool().dispatch(delegate()
                                                                        {
                                                                            flushRequestsWithException(ex);
                                                                        });
                }
                finally
                {
                    _m.Unlock();
                }
            }
            catch(Ice.LocalException ex)
            {
                _m.Lock();
                try
                {
                    Debug.Assert(_exception == null && _requests.Count > 0);
                    _exception = ex;
                    _reference.getInstance().clientThreadPool().dispatch(delegate()
                                                                        {
                                                                            flushRequestsWithException(ex);
                                                                        });
                }
                finally
                {
                    _m.Unlock();
                }
            }

            if(sentCallbacks.Count > 0)
            {
                Instance instance = _reference.getInstance();
                instance.clientThreadPool().dispatch(delegate()
                                                    {
                                                        foreach(Request r in sentCallbacks)
                                                        {
                                                            if(r.@out != null)
                                                            {
                                                                [email protected]__(r.sentCallback);
                                                            }
                                                            else if(r.batchOut != null)
                                                            {
                                                                r.batchOut.sent__(r.sentCallback);
                                                            }
                                                        }
                                                    });
            }

            //
            // 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
            // handler which does not have any synchronization. This also breaks the cyclic
            // reference count with the proxy.
            //
            // NOTE: _updateRequestHandler is immutable once _flushing = true
            //
            if(_updateRequestHandler && _exception == null)
            {
                _proxy.setRequestHandler__(_delegate, new ConnectionRequestHandler(_reference, _connection, _compress));
            }

            _m.Lock();
            try
            {
                Debug.Assert(!_initialized);
                if(_exception == null)
                {
                    _initialized = true;
                    _flushing = false;
                }
                _proxy = null; // Break cyclic reference count.
                _delegate = null; // Break cyclic reference count.
                _m.NotifyAll();
            }
            finally
            {
                _m.Unlock();
            }
        }
示例#29
0
        public void finishBatchRequest(BasicStream os)
        {
            _m.Lock();
            try
            {
                if(!initialized())
                {
                    Debug.Assert(_batchRequestInProgress);
                    _batchRequestInProgress = false;
                    _m.NotifyAll();

                    _batchStream.swap(os);

                    if(!_batchAutoFlush &&
                       _batchStream.size() + _batchRequestsSize > _reference.getInstance().messageSizeMax())
                    {
                        Ex.throwMemoryLimitException(_batchStream.size() + _batchRequestsSize,
                                                     _reference.getInstance().messageSizeMax());
                    }
                    _requests.AddLast(new Request(_batchStream));
                    return;
                }
            }
            finally
            {
                _m.Unlock();
            }
            _connection.finishBatchRequest(os, _compress);
        }
示例#30
0
 public override void streamWrite(BasicStream s)
 {
     s.startWriteEncaps();
     streamWriteImpl(s);
     s.endWriteEncaps();
 }