Exemple #1
0
        public virtual bool addRequestToBatch(DestroyRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != CONTROL)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            string key = request.Session;

            RequestObjects requestObj = new RequestObjects(request, tutor, listener);

            RequestObjects queuedRequest = null;

            keys.TryGetValue(key, out queuedRequest);

            if (queuedRequest != null)
            {
                log.Debug("Substituting DESTROY request");
                queuedRequest.tutor.notifyAbort();
                this.substituteRequest(key, requestObj);
            }
            else
            {
                this.addRequestInternal(key, requestObj);
            }

            return(true);
        }
Exemple #2
0
        public virtual bool addRequestToBatch(SubscribeRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != CONTROL)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            string key = request.SubscriptionId.ToString();

            RequestObjects requestObj = new RequestObjects(request, tutor, listener);

            RequestObjects queuedRequest = null;

            keys.TryGetValue(key, out queuedRequest);
            if (queuedRequest != null)
            {
                //can never happen that an ADD request substitutes a REMOVE request for 2 reasons:
                //  *if those requests are part of the same session than to remove and re-add a table
                //   changes its key.
                //  *if those requests are not part of the same session than during session change
                //   all pending request are removed.
                //so, all cases should pass from the if (requestType == ControlRequest.REMOVE) case

                // thus, this is an unexpected case, let's handle it anyway
                queuedRequest.tutor.notifyAbort();
                this.substituteRequest(key, requestObj);
            }
            else
            {
                this.addRequestInternal(key, requestObj);
            }

            return(true);
        }
Exemple #3
0
        public virtual bool addRequestToBatch(ChangeSubscriptionRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != CONTROL)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            string key = CHANGE_SUB_KEY + request.SubscriptionId;

            RequestObjects requestObj = new RequestObjects(request, tutor, listener);

            RequestObjects queuedRequest = null;

            keys.TryGetValue(key, out queuedRequest);
            if (queuedRequest != null)
            {
                //this change frequency request is newer, replace the old one
                queuedRequest.tutor.notifyAbort();
                this.substituteRequest(key, requestObj);
            }
            else
            {
                this.addRequestInternal(key, requestObj);
            }

            return(true);
        }
Exemple #4
0
        public virtual bool addRequestToBatch(UnsubscribeRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != CONTROL)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            string key = request.SubscriptionId.ToString();

            RequestObjects requestObj = new RequestObjects(request, tutor, listener);

            RequestObjects queuedRequest = null;

            keys.TryGetValue(key, out queuedRequest);
            if (queuedRequest != null)
            {
                if (queuedRequest.request is SubscribeRequest)
                { //can't be the first attempt, otherwise the unsubscribe request would not be here
                    log.Debug("Substituting SUBSCRIBE request with UNSUBSCRIBE");
                    queuedRequest.tutor.notifyAbort();
                    this.substituteRequest(key, requestObj);
                }
                else
                {
                    //delete already queued, should not happen, still, we don't have nothing to do
                }
            }
            else
            {
                this.addRequestInternal(key, requestObj);
            }

            return(true);
        }
Exemple #5
0
        public virtual bool addRequestToBatch(ForceRebindRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != CONTROL)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            //can we queue force rebind for 2 different sessions? (NO)

            string key = FORCE_REBIND_KEY;

            RequestObjects requestObj = new RequestObjects(request, tutor, listener);

            RequestObjects queuedRequest = null;

            keys.TryGetValue(key, out queuedRequest);
            if (queuedRequest != null)
            {
                queuedRequest.tutor.notifyAbort();
                this.substituteRequest(key, requestObj);
            }
            else
            {
                this.addRequestInternal(key, requestObj);
            }

            return(true);
        }
        private bool sendBatch(BatchRequest batch)
        {
            if (batch.Length <= 0)
            {
                //something wrong o_O
                log.Error("Unexpected call");

                //XXX exit here??
            }

            BatchedListener combinedRequestListener = new BatchedListener(this);
            BatchedRequest  combinedRequest         = new BatchedRequest(this);

            /* find the first request to be sent: it provides the server address and the request name for the whole combined request */
            RequestObjects first = null;

            while (first == null && batch.Length > 0)
            {
                first = batch.shift();
                if (first.tutor.shouldBeSent())
                {
                    combinedRequest.Server      = first.request.TargetServer;
                    combinedRequest.RequestName = first.request.RequestName;

                    combinedRequest.add(first.request);
                    combinedRequestListener.add(first.listener);
                    ongoingRequests.AddLast(first);
                }
                else
                {
                    first.tutor.notifyAbort();
                    first = null;
                }
            }
            if (combinedRequest.length() == 0)
            {
                //nothing to send
                return(false);
            }
            /* add the other requests to the combined request: they share the server address and the request name */
            while ((requestLimit == 0 || (combinedRequest.length() + batch.NextRequestLength) < requestLimit) && batch.Length > 0)
            {
                RequestObjects next = batch.shift();
                if (next.tutor.shouldBeSent())
                {
                    combinedRequest.add(next.request);
                    combinedRequestListener.add(next.listener);
                    ongoingRequests.AddLast(next);
                }
                else
                {
                    next.tutor.notifyAbort();
                }
            }

            activeConnection = transport.sendRequest(protocol, combinedRequest, combinedRequestListener, options.HttpExtraHeadersOnSessionCreationOnly ? null : options.HttpExtraHeaders, options.Proxy, options.TCPConnectTimeout, options.TCPReadTimeout);

            return(true);
        }
Exemple #7
0
        public virtual bool addRequestToBatch(ReverseHeartbeatRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != HEARTBEAT)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            //I should only add to queue, the heart-beats are always sent to the server
            RequestObjects hb = new RequestObjects(request, tutor, listener);

            this.addRequestInternal(this.messageNextKey++, hb);
            return(true);
        }
Exemple #8
0
        public virtual bool addRequestToBatch(MessageRequest request, RequestTutor tutor, RequestListener listener)
        {
            if (this.batchType != MESSAGE)
            {
                log.Error("Unexpected request type was given to batch");
                return(false);
            }

            //I should only add to queue, the sendMessages are always sent to the server
            RequestObjects message = new RequestObjects(request, tutor, listener);

            this.addRequestInternal(this.messageNextKey++, message);
            return(true);
        }
Exemple #9
0
        public virtual RequestObjects shift()
        {
            if (this.Length <= 0)
            {
                return(null);
            }


            string key = queue[0];

            queue.RemoveAt(0);
            RequestObjects k = keys.GetValueOrNull(key);

            keys.Remove(key);
            return(k);
        }
Exemple #10
0
 private void addRequestInternal(string key, RequestObjects request)
 {
     this.keys[key] = request;
     this.queue.Add(key);
 }
Exemple #11
0
 private void addRequestInternal(int key, RequestObjects request)
 {
     this.addRequestInternal(key.ToString(), request);
 }
Exemple #12
0
 private void substituteRequest(string key, RequestObjects newRequest)
 {
     this.keys[key] = newRequest;
 }