示例#1
0
        private void UpdateBrokerDone(IAsyncResult result)
        {
            BrokerState bs = null;

            try
            {
                bs = result.AsyncState as BrokerState;
                HttpWebRequest updatePost = bs.Poster;
                using (HttpWebResponse response = updatePost.EndGetResponse(result) as HttpWebResponse)
                {
                    m_log.DebugFormat("[Concierge] broker update: status {0}", response.StatusCode);
                }
                bs.Timer.Dispose();
            }
            catch (WebException we)
            {
                m_log.ErrorFormat("[Concierge] broker update to {0} failed with status {1}", bs.Uri, we.Status);
                if (null != we.Response)
                {
                    using (HttpWebResponse resp = we.Response as HttpWebResponse)
                    {
                        m_log.ErrorFormat("[Concierge] response from {0} status code: {1}", bs.Uri, resp.StatusCode);
                        m_log.ErrorFormat("[Concierge] response from {0} status desc: {1}", bs.Uri, resp.StatusDescription);
                        m_log.ErrorFormat("[Concierge] response from {0} server:      {1}", bs.Uri, resp.Server);

                        if (resp.ContentLength > 0)
                        {
                            StreamReader content = new StreamReader(resp.GetResponseStream());
                            m_log.ErrorFormat("[Concierge] response from {0} content:     {1}", bs.Uri, content.ReadToEnd());
                            content.Close();
                        }
                    }
                }
            }
        }
示例#2
0
        private void UpdateBrokerSend(IAsyncResult result)
        {
            BrokerState bs = null;

            try
            {
                bs = result.AsyncState as BrokerState;
                string         payload    = bs.Payload;
                HttpWebRequest updatePost = bs.Poster;

                using (StreamWriter payloadStream = new StreamWriter(updatePost.EndGetRequestStream(result)))
                {
                    payloadStream.Write(payload);
                    payloadStream.Close();
                }
                updatePost.BeginGetResponse(UpdateBrokerDone, bs);
            }
            catch (WebException we)
            {
                m_log.DebugFormat("[Concierge]: async broker POST to {0} failed: {1}", bs.Uri, we.Status);
            }
            catch (Exception)
            {
                m_log.DebugFormat("[Concierge]: async broker POST to {0} failed", bs.Uri);
            }
        }
示例#3
0
        protected void UpdateBroker(IScene scene)
        {
            if (String.IsNullOrEmpty(m_brokerURI))
            {
                return;
            }

            string uri = String.Format(m_brokerURI, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID);

            // create XML sniplet
            StringBuilder      list = new StringBuilder();
            IEntityCountModule entityCountModule = scene.RequestModuleInterface <IEntityCountModule>();

            if (entityCountModule != null)
            {
                list.Append(String.Format("<avatars count=\"{0}\" region_name=\"{1}\" region_uuid=\"{2}\" timestamp=\"{3}\">\n",
                                          entityCountModule.RootAgents, scene.RegionInfo.RegionName,
                                          scene.RegionInfo.RegionID,
                                          DateTime.UtcNow.ToString("s")));
            }
            scene.ForEachScenePresence(delegate(IScenePresence sp)
            {
                if (!sp.IsChildAgent)
                {
                    list.Append(String.Format("    <avatar name=\"{0}\" uuid=\"{1}\" />\n", sp.Name, sp.UUID));
                    list.Append("</avatars>");
                }
            });
            string payload = list.ToString();

            // post via REST to broker
            HttpWebRequest updatePost = WebRequest.Create(uri) as HttpWebRequest;

            updatePost.Method        = "POST";
            updatePost.ContentType   = "text/xml";
            updatePost.ContentLength = payload.Length;
            updatePost.UserAgent     = "OpenSim.Concierge";


            BrokerState bs = new BrokerState(uri, payload, updatePost);

            bs.Timer = new Timer(delegate(object state)
            {
                BrokerState b = state as BrokerState;
                b.Poster.Abort();
                b.Timer.Dispose();
                m_log.Debug("[Concierge]: async broker POST abort due to timeout");
            }, bs, m_brokerUpdateTimeout * 1000, Timeout.Infinite);

            try
            {
                updatePost.BeginGetRequestStream(UpdateBrokerSend, bs);
                m_log.DebugFormat("[Concierge] async broker POST to {0} started", uri);
            }
            catch (WebException we)
            {
                m_log.ErrorFormat("[Concierge] async broker POST to {0} failed: {1}", uri, we.Status);
            }
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the BrokerStateManager class
 /// </summary>
 /// <param name="sharedData">indicating the shared data</param>
 /// <param name="clientAvaliable">indicating whether there is client avaliable when starting up</param>
 public BrokerStateManager(SharedData sharedData, bool clientAvaliable)
 {
     this.sharedData     = sharedData;
     this.timeoutManager = new TimeoutManager("BrokerStateManager");
     this.state          = BrokerState.Started;
     this.timeoutManager.RegisterTimeout(this.sharedData.Config.Monitor.ClientConnectionTimeout, clientAvaliable ? new WaitCallback(this.TimeoutToSuspended) : new WaitCallback(this.TimeoutToFinish), null);
     BrokerTracing.TraceInfo("[BrokerStateManager] Successfully initialized BrokerStateManager: State = {0}", this.state);
 }
示例#5
0
        private bool HandleQueueException(QueueException ex)
        {
            log.Notice("QueueException: " + ex.EntryType + " with " + count + " ticks so far.");
            switch (ex.EntryType)
            {
            case EventType.StartHistorical:
                symbolState = SymbolState.Historical;
                break;

            case EventType.EndHistorical:
                symbolState = SymbolState.None;
                break;

            case EventType.StartRealTime:
                symbolState = SymbolState.RealTime;
                break;

            case EventType.EndRealTime:
                symbolState = SymbolState.None;
                break;

            case EventType.StartBroker:
                brokerState = BrokerState.Connected;
                if (SyncTicks.Enabled)
                {
                    while (tickSync.SentSwtichBrokerState)
                    {
                        tickSync.ClearSwitchBrokerState("endbroker");
                    }
                }
                break;

            case EventType.EndBroker:
                brokerState = BrokerState.Disconnected;
                if (SyncTicks.Enabled)
                {
                    while (tickSync.SentSwtichBrokerState)
                    {
                        tickSync.ClearSwitchBrokerState("endbroker");
                    }
                }
                break;

            case EventType.Terminate:
                symbolState = SymbolState.None;
                return(true);

            case EventType.RequestPosition:
                symbolState = SymbolState.None;
                return(false);

            default:
                throw new ApplicationException("Unexpected QueueException: " + ex.EntryType);
            }
            return(false);
        }
示例#6
0
 /// <summary>
 /// Informs that all clients have disconnectted
 /// </summary>
 public void AllClientsDisconnected()
 {
     BrokerTracing.TraceInfo("[BrokerStateManager] All clients have disconnectted.");
     lock (this.lockState)
     {
         if (this.state == BrokerState.Running)
         {
             BrokerTracing.TraceInfo("[BrokerStateManager] State: Running ==> Idle");
             this.state = BrokerState.Idle;
             this.timeoutManager.RegisterTimeout(this.sharedData.Config.Monitor.SessionIdleTimeout, this.TimeoutToSuspended, null);
         }
     }
 }
示例#7
0
 /// <summary>
 /// Informs that a client has connectted
 /// </summary>
 public void ClientConnected()
 {
     BrokerTracing.TraceInfo("[BrokerStateManager] A client has connectted.");
     lock (this.lockState)
     {
         if (this.state == BrokerState.Started || this.state == BrokerState.Idle)
         {
             BrokerTracing.TraceInfo("[BrokerStateManager] State: {0} ==> Running", this.state);
             this.state = BrokerState.Running;
             this.timeoutManager.Stop();
         }
     }
 }
        public bool VerifyState(BrokerState expectedBrokerState,
                                ReceiverState expectedSymbolState,
                                SymbolInfo symbol,
                                int timeout)
        {
            if (debug)
            {
                log.Debug("VerifyFeed");
            }
            if (SyncTicks.Enabled)
            {
                tickSync = SyncTicks.GetTickSync(symbol.BinaryIdentifier);
            }
            long startTime = Factory.TickCount;

            count = 0;
            TickBinary binary = new TickBinary();

            while (Factory.TickCount - startTime < timeout * 1000)
            {
                if (propagateException != null)
                {
                    throw propagateException;
                }
                try {
                    if (!tickQueue.TryDequeue(ref binary))
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        if (SyncTicks.Enabled)
                        {
                            tickSync.RemoveTick();
                        }
                    }
                } catch (QueueException ex) {
                    if (HandleQueueException(ex))
                    {
                        break;
                    }
                }
                if (brokerState == expectedBrokerState && receiverState == expectedSymbolState)
                {
                    return(true);
                }
            }
            return(false);
        }
        private bool HandleQueueException(QueueException ex)
        {
            log.Notice("QueueException: " + ex.EntryType);
            switch (ex.EntryType)
            {
            case EventType.StartHistorical:
                receiverState = ReceiverState.Historical;
                isRealTime    = false;
                break;

            case EventType.EndHistorical:
                receiverState = ReceiverState.Ready;
                isRealTime    = false;
                break;

            case EventType.StartRealTime:
                receiverState = ReceiverState.RealTime;
                isRealTime    = true;
                break;

            case EventType.EndRealTime:
                receiverState = ReceiverState.Ready;
                isRealTime    = false;
                break;

            case EventType.StartBroker:
                brokerState = BrokerState.Connected;
                isRealTime  = true;
                break;

            case EventType.EndBroker:
                brokerState = BrokerState.Disconnected;
                isRealTime  = false;
                break;

            case EventType.Terminate:
                receiverState = ReceiverState.Stop;
                isRealTime    = false;
                return(true);

            default:
                throw new ApplicationException("Unexpected QueueException: " + ex.EntryType);
            }
            return(false);
        }
示例#10
0
        public bool VerifyState(BrokerState expectedBrokerState, SymbolState expectedSymbolState, int timeout)
        {
            if (debug)
            {
                log.Debug("VerifyState broker " + expectedBrokerState + ", symbol " + expectedSymbolState + ", timeout " + timeout);
            }
            long startTime = Factory.TickCount;

            count = 0;
            TickBinary binary = new TickBinary();

            while (Factory.TickCount - startTime < timeout * 1000)
            {
                if (propagateException != null)
                {
                    throw propagateException;
                }
                try {
                    if (!TryDequeueTick(ref binary))
                    {
                        if (SyncTicks.Enabled && symbolState == SymbolState.RealTime)
                        {
                            tickSync.RemoveTick(ref binary);
                        }
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                } catch (QueueException ex) {
                    if (HandleQueueException(ex))
                    {
                        break;
                    }
                }
                if (brokerState == expectedBrokerState && symbolState == expectedSymbolState)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#11
0
        /// <summary>
        /// Timeout to finish state
        /// </summary>
        /// <param name="state">null object</param>
        private void TimeoutToFinish(object state)
        {
            BrokerTracing.TraceInfo("[BrokerStateManager] Timeout to finish triggered.");
            bool flag = false;

            lock (this.lockState)
            {
                if (this.state == BrokerState.Started)
                {
                    BrokerTracing.TraceInfo("[BrokerStateManager] State: Started ==> Finish");
                    this.state = BrokerState.Finished;
                    flag       = true;
                }
            }

            if (flag)
            {
                this.SyncUnloadBroker(false);
            }
        }
示例#12
0
        /// <summary>
        /// Timeout to suspended state
        /// </summary>
        /// <param name="state">null object</param>
        private void TimeoutToSuspended(object state)
        {
            BrokerTracing.TraceInfo("[BrokerStateManager] Timeout to suspended triggered.");
            bool flag = false;

            lock (this.lockState)
            {
                if (this.state == BrokerState.Idle || this.state == BrokerState.Started)
                {
                    BrokerTracing.TraceInfo("[BrokerStateManager] State: {0} ==> Suspend", this.state);
                    this.state = BrokerState.Suspend;
                    flag       = true;
                }
            }

            if (flag)
            {
                this.SyncUnloadBroker(this.sharedData.BrokerInfo.Durable);
            }
        }
示例#13
0
        protected void UpdateBroker(Scene scene)
        {
            if (String.IsNullOrEmpty(m_brokerURI))
                return;

            string uri = String.Format(m_brokerURI, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID);

            // create XML sniplet
            StringBuilder list = new StringBuilder();
            list.Append(String.Format("<avatars count=\"{0}\" region_name=\"{1}\" region_uuid=\"{2}\" timestamp=\"{3}\">\n",
                                          scene.GetRootAgentCount(), scene.RegionInfo.RegionName,
                                          scene.RegionInfo.RegionID,
                                          DateTime.UtcNow.ToString("s")));
            scene.ForEachRootScenePresence(delegate(ScenePresence sp)
            {
                    list.Append(String.Format("    <avatar name=\"{0}\" uuid=\"{1}\" />\n", sp.Name, sp.UUID));
                    list.Append("</avatars>");
            });
            string payload = list.ToString();

            // post via REST to broker
            HttpWebRequest updatePost = WebRequest.Create(uri) as HttpWebRequest;
            updatePost.Method = "POST";
            updatePost.ContentType = "text/xml";
            updatePost.ContentLength = payload.Length;
            updatePost.UserAgent = "OpenSim.Concierge";


            BrokerState bs = new BrokerState(uri, payload, updatePost);
            bs.Timer = new Timer(delegate(object state)
                                 {
                                     BrokerState b = state as BrokerState;
                                     b.Poster.Abort();
                                     b.Timer.Dispose();
                                     m_log.Debug("[Concierge]: async broker POST abort due to timeout");
                                 }, bs, m_brokerUpdateTimeout * 1000, Timeout.Infinite);

            try
            {
                updatePost.BeginGetRequestStream(UpdateBrokerSend, bs);
                m_log.DebugFormat("[Concierge] async broker POST to {0} started", uri);
            }
            catch (WebException we)
            {
                m_log.ErrorFormat("[Concierge] async broker POST to {0} failed: {1}", uri, we.Status);
            }
        }
示例#14
0
        protected void UpdateBroker(IScene scene)
        {
            if (String.IsNullOrEmpty(m_brokerURI))
                return;

            string uri = String.Format(m_brokerURI, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID);

            // get attendee list for the scene
            List<UUID> attendees;
            lock (m_sceneAttendees)
            {
                if (!m_sceneAttendees.ContainsKey(scene))
                {
                    m_log.DebugFormat("[Concierge]: attendee list missing for region {0}", scene.RegionInfo.RegionName);
                    return;
                }

                attendees = m_sceneAttendees[scene];
            }

            // create XML sniplet
            StringBuilder list = new StringBuilder();
            if (0 == attendees.Count)
            {
                list.Append(String.Format("<avatars count=\"0\" region_name=\"{0}\" region_uuid=\"{1}\" timestamp=\"{2}\" />",
                                          scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, 
                                          DateTime.UtcNow.ToString("s")));
            } 
            else
            {
                list.Append(String.Format("<avatars count=\"{0}\" region_name=\"{1}\" region_uuid=\"{2}\" timestamp=\"{3}\">\n",
                                          attendees.Count, scene.RegionInfo.RegionName, 
                                          scene.RegionInfo.RegionID, 
                                          DateTime.UtcNow.ToString("s")));
                lock (m_sceneAttendees)
                {
                    foreach (UUID uuid in attendees)
                    {
                        if (m_attendeeNames.ContainsKey(uuid))
                        {
                            string name = m_attendeeNames[uuid];
                            list.Append(String.Format("    <avatar name=\"{0}\" uuid=\"{1}\" />\n", name, uuid));
                        }
                    }
                }
                list.Append("</avatars>");
            }
            string payload = list.ToString();

            // post via REST to broker
            HttpWebRequest updatePost = WebRequest.Create(uri) as HttpWebRequest;
            updatePost.Method = "POST";
            updatePost.ContentType = "text/xml";
            updatePost.ContentLength = payload.Length;
            updatePost.UserAgent = "Halcyon.Concierge";


            BrokerState bs = new BrokerState(uri, payload, updatePost);
            bs.Timer = new Timer(delegate(object state)
                                 {
                                     BrokerState b = state as BrokerState;
                                     b.Poster.Abort();
                                     b.Timer.Dispose();
                                     m_log.Debug("[Concierge]: async broker POST abort due to timeout");
                                 }, bs, m_brokerUpdateTimeout * 1000, Timeout.Infinite);

            try
            {
                updatePost.BeginGetRequestStream(UpdateBrokerSend, bs);
                m_log.DebugFormat("[Concierge] async broker POST to {0} started", uri);
            }
            catch (WebException we)
            {
                m_log.ErrorFormat("[Concierge] async broker POST to {0} failed: {1}", uri, we.Status);
            }
        }
示例#15
0
        protected void UpdateBroker(IScene scene)
        {
            if (String.IsNullOrEmpty(m_brokerURI))
            {
                return;
            }

            string uri = String.Format(m_brokerURI, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID);

            // get attendee list for the scene
            List <UUID> attendees;

            lock (m_sceneAttendees)
            {
                if (!m_sceneAttendees.ContainsKey(scene))
                {
                    m_log.DebugFormat("[Concierge]: attendee list missing for region {0}", scene.RegionInfo.RegionName);
                    return;
                }

                attendees = m_sceneAttendees[scene];
            }

            // create XML sniplet
            StringBuilder list = new StringBuilder();

            if (0 == attendees.Count)
            {
                list.Append(String.Format("<avatars count=\"0\" region_name=\"{0}\" region_uuid=\"{1}\" timestamp=\"{2}\" />",
                                          scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
                                          DateTime.UtcNow.ToString("s")));
            }
            else
            {
                list.Append(String.Format("<avatars count=\"{0}\" region_name=\"{1}\" region_uuid=\"{2}\" timestamp=\"{3}\">\n",
                                          attendees.Count, scene.RegionInfo.RegionName,
                                          scene.RegionInfo.RegionID,
                                          DateTime.UtcNow.ToString("s")));
                lock (m_sceneAttendees)
                {
                    foreach (UUID uuid in attendees)
                    {
                        if (m_attendeeNames.ContainsKey(uuid))
                        {
                            string name = m_attendeeNames[uuid];
                            list.Append(String.Format("    <avatar name=\"{0}\" uuid=\"{1}\" />\n", name, uuid));
                        }
                    }
                }
                list.Append("</avatars>");
            }
            string payload = list.ToString();

            // post via REST to broker
            HttpWebRequest updatePost = WebRequest.Create(uri) as HttpWebRequest;

            updatePost.Method        = "POST";
            updatePost.ContentType   = "text/xml";
            updatePost.ContentLength = payload.Length;
            updatePost.UserAgent     = "Halcyon.Concierge";


            BrokerState bs = new BrokerState(uri, payload, updatePost);

            bs.Timer = new Timer(delegate(object state)
            {
                BrokerState b = state as BrokerState;
                b.Poster.Abort();
                b.Timer.Dispose();
                m_log.Debug("[Concierge]: async broker POST abort due to timeout");
            }, bs, m_brokerUpdateTimeout * 1000, Timeout.Infinite);

            try
            {
                updatePost.BeginGetRequestStream(UpdateBrokerSend, bs);
                m_log.DebugFormat("[Concierge] async broker POST to {0} started", uri);
            }
            catch (WebException we)
            {
                m_log.ErrorFormat("[Concierge] async broker POST to {0} failed: {1}", uri, we.Status);
            }
        }