Exemplo n.º 1
0
        public void SendEvent(EventQueueEvent eventQueueEvent)
        {
            if (!running)
            {
                throw new InvalidOperationException("Cannot add event while the queue is stopped");
            }

            eventQueue.Enqueue(eventQueueEvent);
        }
Exemplo n.º 2
0
        void SendResponse(IHttpClientContext context, IHttpRequest request, IHttpResponse response, List <EventQueueEvent> eventsToSend)
        {
            response.Connection = request.Connection;

            if (eventsToSend != null)
            {
                OSDArray responseArray = new OSDArray(eventsToSend.Count);

                // Put all of the events in an array
                for (int i = 0; i < eventsToSend.Count; i++)
                {
                    EventQueueEvent currentEvent = eventsToSend[i];

                    OSDMap eventMap = new OSDMap(2);
                    eventMap.Add("message", OSD.FromString(currentEvent.Name));
                    eventMap.Add("body", currentEvent.Body);
                    responseArray.Add(eventMap);
                }

                // Create a map containing the events array and the id of this response
                OSDMap responseMap = new OSDMap(2);
                responseMap.Add("events", responseArray);
                responseMap.Add("id", OSD.FromInteger(currentID++));

                // Serialize the events and send the response
                string responseBody = OSDParser.SerializeLLSDXmlString(responseMap);

                Logger.Log.Debug("[EventQueue] Sending " + responseArray.Count + " events over the event queue");
                context.Respond(HttpHelper.HTTP11, HttpStatusCode.OK, "OK", responseBody, "application/xml");
            }
            else
            {
                //Logger.Log.Debug("[EventQueue] Sending a timeout response over the event queue");

                // The 502 response started as a bug in the LL event queue server implementation,
                // but is now hardcoded into the protocol as the code to use for a timeout
                context.Respond(HttpHelper.HTTP10, HttpStatusCode.BadGateway, "Upstream error:", "Upstream error:", null);
            }
        }
Exemplo n.º 3
0
        void EventQueueThread()
        {
            threadRunning = true;
            EventQueueEvent eventQueueEvent = null;
            int             totalMsPassed   = 0;

            while (running && context.Stream != null && context.Stream.CanWrite)
            {
                if (eventQueue.Dequeue(BATCH_WAIT_INTERVAL, ref eventQueueEvent))
                {
                    // An event was dequeued
                    totalMsPassed = 0;
                    List <EventQueueEvent> eventsToSend = null;

                    if (eventQueueEvent != null)
                    {
                        eventsToSend = new List <EventQueueEvent>();
                        eventsToSend.Add(eventQueueEvent);

                        DateTime start         = DateTime.Now;
                        int      batchMsPassed = 0;

                        // Wait BATCH_WAIT_INTERVAL milliseconds looking for more events,
                        // or until the size of the current batch equals MAX_EVENTS_PER_RESPONSE
                        while (batchMsPassed < BATCH_WAIT_INTERVAL && eventsToSend.Count < MAX_EVENTS_PER_RESPONSE)
                        {
                            if (eventQueue.Dequeue(BATCH_WAIT_INTERVAL - batchMsPassed, ref eventQueueEvent) && eventQueueEvent != null)
                            {
                                eventsToSend.Add(eventQueueEvent);
                            }

                            batchMsPassed = (int)(DateTime.Now - start).TotalMilliseconds;
                        }
                    }
                    else
                    {
                        Logger.Log.Info("[EventQueue] Dequeued a signal to close the handler thread");
                    }

                    // Make sure we can actually send the events right now
                    if (context.Stream == null || !context.Stream.CanWrite)
                    {
                        Logger.Log.Info("[EventQueue] Connection is closed, requeuing events and closing the handler thread");
                        if (eventsToSend != null)
                        {
                            for (int i = 0; i < eventsToSend.Count; i++)
                            {
                                eventQueue.Enqueue(eventsToSend[i]);
                            }
                        }
                        goto ThreadDone;
                    }

                    SendResponse(context, request, response, eventsToSend);
                    goto ThreadDone;
                }
                else
                {
                    // BATCH_WAIT_INTERVAL milliseconds passed with no event. Check if the connection
                    // has timed out yet.
                    totalMsPassed += BATCH_WAIT_INTERVAL;

                    if (totalMsPassed >= CONNECTION_TIMEOUT)
                    {
                        Logger.Log.DebugFormat(
                            "[EventQueue] {0}ms passed without an event, timing out the event queue",
                            totalMsPassed);
                        SendResponse(context, request, response, null);
                        goto ThreadDone;
                    }
                }
            }

ThreadDone:
            threadRunning = false;
            //Logger.Log.Debug("[EventQueue] Handler thread is exiting");
        }
Exemplo n.º 4
0
        public void SendEvent(EventQueueEvent eventQueueEvent)
        {
            if (!running)
                throw new InvalidOperationException("Cannot add event while the queue is stopped");

            eventQueue.Enqueue(eventQueueEvent);
        }
Exemplo n.º 5
0
 public void SendEvent(EventQueueEvent eventQueueEvent)
 {
     if (!Running)
         throw new InvalidOperationException("Cannot add event while the queue is stopped");
     Console.WriteLine("[EvenetQueue]: posting event to EQ " + id);
     eventQueue.Enqueue(eventQueueEvent);
 }