private void ReQueueEvent(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         m_retryRequests.Enqueue(req);
     }
 }
Пример #2
0
 public void Enqueue(PollServiceHttpRequest req)
 {
     lock (m_requests)
     {
         m_requests.Enqueue(req);
     }
 }
 public void Enqueue(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         m_requests.Add(req);
     }
 }
Пример #4
0
 public void Enqueue(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         m_workerPool.Enqueue(req);
     }
 }
 public void Enqueue(PollServiceHttpRequest req)
 {
     lock (m_requests)
     {
         PokeThreads();
         m_requests.Enqueue(req);
     }
 }
Пример #6
0
        // work threads

        private void PoolWorkerJob(object o)
        {
            PollServiceHttpRequest req = o as PollServiceHttpRequest;

            if (req == null)
            {
                return;
            }
            try
            {
                if (!req.Request.Context.CanSend())
                {
                    req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                    return;
                }

                if (!m_running)
                {
                    req.DoHTTPstop();
                    return;
                }

                if (req.Request.Context.IsSending())
                {
                    ReQueueEvent(req);
                    return;
                }

                if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                {
                    try
                    {
                        Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
                        req.DoHTTPGruntWork(responsedata);
                    }
                    catch { }
                }
                else
                {
                    if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                    {
                        try
                        {
                            req.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                        }
                        catch { }
                    }
                    else
                    {
                        ReQueueEvent(req);
                    }
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
            }
        }
Пример #7
0
 internal void ReQueueEvent(PollServiceHttpRequest req)
 {
     try
     {
         // Do accounting stuff here
         Enqueue(req);
     }
     catch
     {
     }
 }
 internal void ReQueueEvent(PollServiceHttpRequest req)
 {
     try
     {
         // Do accounting stuff here
         Enqueue(req);
     }
     catch
     {
     }
 }
Пример #9
0
        public void Run()
        {
            while (m_running)
            {
                PollServiceHttpRequest req = m_request.Dequeue();

                Watchdog.UpdateThread();

                try
                {
                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        StreamReader str;
                        try
                        {
                            str = new StreamReader(req.Request.Body);
                        }
                        catch (System.ArgumentException)
                        {
                            // Stream was not readable means a child agent
                            // was closed due to logout, leaving the
                            // Event Queue request orphaned.
                            continue;
                        }

                        Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd());
                        DoHTTPGruntWork(m_server, req, responsedata);
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > m_timeout)
                        {
                            DoHTTPGruntWork(
                                m_server,
                                req,
                                req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                        }
                        else
                        {
                            ReQueuePollServiceItem reQueueItem = ReQueue;
                            if (reQueueItem != null)
                            {
                                reQueueItem(req);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
Пример #10
0
        public void DropByContext(PollServiceHttpRequest req)
        {
            Queue <PollServiceHttpRequest> ctxQeueue;

            lock (m_bycontext)
            {
                if (m_bycontext.TryGetValue(req, out ctxQeueue))
                {
                    ctxQeueue.Clear();
                    m_bycontext.Remove(req);
                }
            }
        }
Пример #11
0
        private void ReQueueEvent(PollServiceHttpRequest req)
        {
            if (IsRunning)
            {
                // delay the enqueueing for 100ms. There's no need to have the event
                // actively on the queue
                Timer t = new Timer(self => {
                    ((Timer)self).Dispose();
                    m_requests.Enqueue(req);
                });

                t.Change(100, Timeout.Infinite);
            }
        }
 public void Enqueue(PollServiceHttpRequest req)
 {
     if (IsRunning)
     {
         if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll)
         {
             m_longPollRequests.Add(req);
         }
         else
         {
             m_requests.Enqueue(req);
         }
     }
 }
 public void EnqueueInt(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll)
         {
             m_requests.Enqueue(req);
         }
         else
         {
             lock (m_slowRequests)
                 m_slowRequests.Enqueue(req);
         }
     }
 }
 public void Enqueue(PollServiceHttpRequest req)
 {
     lock (m_bycontext)
     {
         Queue <PollServiceHttpRequest> ctxQeueue;
         if (m_bycontext.TryGetValue(req, out ctxQeueue))
         {
             ctxQeueue.Enqueue(req);
         }
         else
         {
             ctxQeueue        = new Queue <PollServiceHttpRequest>();
             m_bycontext[req] = ctxQeueue;
             EnqueueInt(req);
         }
     }
 }
        public void Stop()
        {
            m_running = false;

            foreach (object o in m_requests)
            {
                PollServiceHttpRequest req = (PollServiceHttpRequest)o;
                PollServiceWorkerThread.DoHTTPGruntWork(
                    m_server, req, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
            }

            m_requests.Clear();

            foreach (Thread t in m_workerThreads)
            {
                t.Abort();
            }
        }
Пример #16
0
        public void Enqueue(PollServiceHttpRequest req)
        {
            Queue <PollServiceHttpRequest> ctxQeueue;
            int rhash = req.contextHash;

            lock (m_bycontext)
            {
                if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
                {
                    ctxQeueue.Enqueue(req);
                }
                else
                {
                    ctxQeueue          = new Queue <PollServiceHttpRequest>();
                    m_bycontext[rhash] = ctxQeueue;
                    EnqueueInt(req);
                }
            }
        }
        public void byContextDequeue(PollServiceHttpRequest req)
        {
            Queue <PollServiceHttpRequest> ctxQeueue;

            lock (m_bycontext)
            {
                if (m_bycontext.TryGetValue(req, out ctxQeueue))
                {
                    if (ctxQeueue.Count > 0)
                    {
                        PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
                        EnqueueInt(newreq);
                    }
                    else
                    {
                        m_bycontext.Remove(req);
                    }
                }
            }
        }
Пример #18
0
        /// <summary>
        /// FIXME: This should be part of BaseHttpServer
        /// </summary>
        internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata)
        {
            OSHttpResponse response
                = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext);

            byte[] buffer = server.DoHTTPGruntWork(responsedata, response);

            response.SendChunked     = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex));
            }
            finally
            {
                //response.OutputStream.Close();
                try
                {
                    response.OutputStream.Flush();
                    response.Send();

                    //if (!response.KeepAlive && response.ReuseContext)
                    //    response.FreeContext();
                }
                catch (Exception e)
                {
                    m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e));
                }
            }
        }
 public void Enqueue(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll)
         {
             lock (m_longPollRequests)
                 m_longPollRequests.Add(req);
         }
         else
             m_requests.Enqueue(req);
     }
 }
        private void ReQueueEvent(PollServiceHttpRequest req)
        {
            if (m_running)
            {
                // delay the enqueueing for 100ms. There's no need to have the event
                // actively on the queue
                Timer t = new Timer(self => {
                    ((Timer)self).Dispose();
                    m_requests.Enqueue(req);
                });

                t.Change(100, Timeout.Infinite);

            }
        }
Пример #21
0
 internal void Enqueue(PollServiceHttpRequest pPollServiceHttpRequest)
 {
     m_request.Enqueue(pPollServiceHttpRequest);
 }
Пример #22
0
        /// <summary>
        /// FIXME: This should be part of BaseHttpServer
        /// </summary>
        internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata)
        {
            OSHttpResponse response
                = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext);

            byte[] buffer = server.DoHTTPGruntWork(responsedata, response);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex));
            }
            finally
            {
                //response.OutputStream.Close();
                try
                {
                    response.OutputStream.Flush();
                    response.Send();

                    //if (!response.KeepAlive && response.ReuseContext)
                    //    response.FreeContext();
                }
                catch (Exception e)
                {
                    m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e));
                }
            }
        }
 public void Enqueue(PollServiceHttpRequest req)
 {
     lock (m_bycontext)
     {
         Queue<PollServiceHttpRequest> ctxQeueue;
         if (m_bycontext.TryGetValue(req, out ctxQeueue))
         {
             ctxQeueue.Enqueue(req);
         }
         else
         {
             ctxQeueue = new Queue<PollServiceHttpRequest>();
             m_bycontext[req] = ctxQeueue;
             EnqueueInt(req);
         }
     }
 }
        // work threads

        private void PoolWorkerJob()
        {
            while (m_running)
            {
                PollServiceHttpRequest req = m_requests.Dequeue(5000);

                Watchdog.UpdateThread();
                if (req != null)
                {
                    try
                    {
                        if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                        {
                            Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);

                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    req.DoHTTPGruntWork(m_server, responsedata);
                                    byContextDequeue(req);
                                }
                                catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
                                {
                                    // Ignore it, no need to reply
                                }
                                return(null);
                            }, null);
                        }
                        else
                        {
                            if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                            {
                                m_threadPool.QueueWorkItem(x =>
                                {
                                    try
                                    {
                                        req.DoHTTPGruntWork(m_server,
                                                            req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                                        byContextDequeue(req);
                                    }
                                    catch (ObjectDisposedException)
                                    {
                                        // Ignore it, no need to reply
                                    }
                                    return(null);
                                }, null);
                            }
                            else
                            {
                                ReQueueEvent(req);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                    }
                }
            }
        }
Пример #25
0
        // work threads

        private void PoolWorkerJob()
        {
            while (m_running)
            {
                PollServiceHttpRequest req = m_requests.Dequeue(4500);
                Watchdog.UpdateThread();
                if (req == null)
                {
                    continue;
                }

                try
                {
                    if (!req.HttpContext.CanSend())
                    {
                        req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                        byContextDequeue(req);
                        continue;
                    }

                    if (req.HttpContext.IsSending())
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                            byContextDequeue(req);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                        continue;
                    }

                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        m_threadPool.QueueWorkItem(x =>
                        {
                            try
                            {
                                Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
                                req.DoHTTPGruntWork(m_server, responsedata);
                            }
                            catch (ObjectDisposedException) { }
                            finally
                            {
                                byContextDequeue(req);
                            }
                            return(null);
                        }, null);
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    req.DoHTTPGruntWork(m_server,
                                                        req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                                }
                                catch (ObjectDisposedException) {}
                                finally
                                {
                                    byContextDequeue(req);
                                }
                                return(null);
                            }, null);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
 public void EnqueueInt(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll)
         {
             m_requests.Enqueue(req);
         }
         else
         {
             lock (m_slowRequests)
                 m_slowRequests.Enqueue(req);
         }
     }
 }
Пример #27
0
        // work threads

        private void PoolWorkerJob()
        {
            PollServiceHttpRequest req;

            while (m_running)
            {
                try
                {
                    req = null;
                    if (!m_requests.TryTake(out req, 4500) || req == null)
                    {
                        Watchdog.UpdateThread();
                        continue;
                    }

                    Watchdog.UpdateThread();

                    if (!req.HttpContext.CanSend())
                    {
                        req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                        byContextDequeue(req);
                        continue;
                    }

                    if (req.HttpContext.IsSending())
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
                            byContextDequeue(req);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                        continue;
                    }

                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        PollServiceHttpRequest nreq = req;
                        m_threadPool.QueueWorkItem(x =>
                        {
                            try
                            {
                                Hashtable responsedata = nreq.PollServiceArgs.GetEvents(nreq.RequestID, nreq.PollServiceArgs.Id);
                                nreq.DoHTTPGruntWork(responsedata);
                            }
                            catch (ObjectDisposedException) { }
                            finally
                            {
                                byContextDequeue(nreq);
                                nreq = null;
                            }
                            return(null);
                        }, null);
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            PollServiceHttpRequest nreq = req;
                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    nreq.DoHTTPGruntWork(nreq.PollServiceArgs.NoEvents(nreq.RequestID, nreq.PollServiceArgs.Id));
                                }
                                catch (ObjectDisposedException) { }
                                finally
                                {
                                    byContextDequeue(nreq);
                                    nreq = null;
                                }
                                return(null);
                            }, null);
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                    // Shouldn't set this to 'false', the normal shutdown should cause things to exit
                    // but robust is still not normal neither is mono
                    m_running = false;
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
Пример #28
0
        private void OnRequest(object source, RequestEventArgs args)
        {
            try
            {
                IHttpClientContext context = (IHttpClientContext)source;
                IHttpRequest request = args.Request;

                PollServiceEventArgs psEvArgs;

                if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs))
                {
                    PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);

                    if (psEvArgs.Request != null)
                    {
                        OSHttpRequest req = new OSHttpRequest(context, request);

                        Stream requestStream = req.InputStream;

                        Encoding encoding = Encoding.UTF8;
                        StreamReader reader = new StreamReader(requestStream, encoding);

                        string requestBody = reader.ReadToEnd();

                        Hashtable keysvals = new Hashtable();
                        Hashtable headervals = new Hashtable();

                        string[] querystringkeys = req.QueryString.AllKeys;
                        string[] rHeaders = req.Headers.AllKeys;

                        keysvals.Add("body", requestBody);
                        keysvals.Add("uri", req.RawUrl);
                        keysvals.Add("content-type", req.ContentType);
                        keysvals.Add("http-method", req.HttpMethod);

                        foreach (string queryname in querystringkeys)
                        {
                            keysvals.Add(queryname, req.QueryString[queryname]);
                        }

                        foreach (string headername in rHeaders)
                        {
                            headervals[headername] = req.Headers[headername];
                        }

                        keysvals.Add("headers", headervals);
                        keysvals.Add("querystringkeys", querystringkeys);

                        psEvArgs.Request(psreq.RequestID, keysvals);
                    }

                    m_PollServiceManager.Enqueue(psreq);
                }
                else
                {
                    OnHandleRequestIOThread(context, request);
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[BASE HTTP SERVER]: OnRequest() failed with {0}{1}", e.Message, e.StackTrace);
            }
        }
 public void Enqueue(PollServiceHttpRequest req)
 {
     lock (m_requests)
         m_requests.Enqueue(req);
 }
Пример #30
0
 internal void Enqueue(PollServiceHttpRequest pPollServiceHttpRequest)
 {
     m_request.Enqueue(pPollServiceHttpRequest);
 }
 private void ReQueueEvent(PollServiceHttpRequest req)
 {
     if (m_running)
     {
         lock (m_retryRequests)
             m_retryRequests.Enqueue(req);
     }
 }
Пример #32
0
        public void WaitPerformResponse()
        {
            PollServiceHttpRequest req = m_requests.Dequeue(5000);

            //            m_log.DebugFormat("[YYY]: Dequeued {0}", (req == null ? "null" : req.PollServiceArgs.Type.ToString()));

            if (req != null)
            {
                try
                {
                    if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
                    {
                        Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);

                        if (responsedata == null)
                        {
                            return;
                        }

                        // This is the event queue.
                        // Even if we're not running we can still perform responses by explicit request.
                        if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll ||
                            !PerformResponsesAsync)
                        {
                            try
                            {
                                ResponsesProcessed++;
                                req.DoHTTPGruntWork(m_server, responsedata);
                            }
                            catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream
                            {
                                // Ignore it, no need to reply
                                m_log.Error(e);
                            }
                        }
                        else
                        {
                            m_threadPool.QueueWorkItem(x =>
                            {
                                try
                                {
                                    ResponsesProcessed++;
                                    req.DoHTTPGruntWork(m_server, responsedata);
                                }
                                catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream
                                {
                                    // Ignore it, no need to reply
                                    m_log.Error(e);
                                }
                                catch (Exception e)
                                {
                                    m_log.Error(e);
                                }

                                return(null);
                            }, null);
                        }
                    }
                    else
                    {
                        if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
                        {
                            ResponsesProcessed++;
                            req.DoHTTPGruntWork(
                                m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
                        }
                        else
                        {
                            ReQueueEvent(req);
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
                }
            }
        }
 public void byContextDequeue(PollServiceHttpRequest req)
 {
     Queue<PollServiceHttpRequest> ctxQeueue;
     lock (m_bycontext)
     {
         if (m_bycontext.TryGetValue(req, out ctxQeueue))
         {
             if (ctxQeueue.Count > 0)
             {
                 PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
                 EnqueueInt(newreq);
             }
             else
             {
                 m_bycontext.Remove(req);
             }
         }
     }
 }