Exemplo n.º 1
0
        private void initializeRender(ToRenderMessage message)
        {
            string sceneBlobUri = message.SceneName;

            m_sceneID       = message.SceneId;
            m_sceneUri      = message.SceneName;
            m_mergerHandler = new MessageQueue <MergerMessage>(message.SceneId.ToString());
            m_breaker       = new Breaker(message.WriteInterval, message.HaltTime,
                                          message.RequiredSpp, m_engine, m_log);

            m_log.Info("Scene start." + DateTime.Now);
            m_scene = new Scene(sceneBlobUri, m_localDirectory);
            m_log.Info("Scene finish." + DateTime.Now);
            m_log.Info("Scene created");
            m_log.Info(m_scene.SceneDirectory);
            m_log.Info(m_scene.ScenePath);
        }
Exemplo n.º 2
0
        public override void Run()
        {
            try
            {
                Trace.TraceInformation("Listening for queue messages...");
                m_log.Info("Worker is started.\nListening for queue messages...");
                MessageQueue <RenderMessage> localQueue = null;
                while (true)
                {
                    //check if worker is allocated and ready to work
                    RenderMessage rendMes = m_renderHandler.WaitForMessage(typeof(IsFreeMessage));
                    m_log.Info("IsFreeMessage");
                    IsFreeMessage isFreeMessage = rendMes as IsFreeMessage;
                    MessageQueue <DispetcherMessage> dispHandler = new MessageQueue <DispetcherMessage>(isFreeMessage.SceneId.ToString()); //create queue to dispatcher thread
                    localQueue = new MessageQueue <RenderMessage>(isFreeMessage.SceneId.ToString());
                    m_log.Info("sending 'I am ready' message");
                    dispHandler.AddMessage(new WorkerIsReady(isFreeMessage.SessionId)); //signal to dispatcher: "Ready to work!"
                    m_aborted = false;
                    m_log.Info("/IsFreeMessage");

                    rendMes = localQueue.WaitForMessage(typeof(ToRenderMessage));
                    m_log.Info("Got messege: " + rendMes.GetType().Name);
                    m_log.Info("ToRenderMessage start");
                    ToRenderMessage message = rendMes as ToRenderMessage;
                    initializeRender(message);
                    startRender();
                    m_log.Info("Abort queue name suffix: " + message.AbortQueueSuffix);
                    startWaitingProcess(message.AbortQueueSuffix);
                    renderFinished();
                    m_log.Info("/ToRenderMessage");
                }
            }
            catch (Exception e)
            {
                interruptRender(e.Message);
            }
        }
Exemplo n.º 3
0
        private void processingScene(NetMessageHandler handler, SceneMessage message, byte[] sceneFile, string sessionGuid,
                                     MessageQueue <DispetcherMessage> dispatcherHandler)
        {
            string sceneName      = null;
            int    threadID       = m_threadsID[sessionGuid];
            string uniqueBlobName = string.Format("{0}_{1}", BlobName.UNIQUE_BLOB + threadID.ToString(), sessionGuid);

            try
            {
                lock (m_BlobLock)
                {
                    CloudBlockBlob blob = renderStorage.Get().CreateBlob(BlobName.SCENE_BLOB, uniqueBlobName);//sceneContainer.GetBlockBlobReference(uniqueBlobName);
                    Utils.UpploadBlobByteArray(blob, sceneFile);
                    sceneName = blob.Uri.ToString();
                }
            }
            catch (Exception e)
            {
                m_log.Error("Error saving scene to blob: " + e.Message);
                m_instanceManager.IncreaseFreeMergerCount(); //if no blob created than mark requested instances as free
                                                             //and kill thread
                m_instanceManager.IncreaseFreeWorkerCount(message.InstanceCnt);
                Thread.CurrentThread.Abort();
            }

            StartMergeMessage mergerMessage = new StartMergeMessage(message.InstanceCnt, message.TotalTime,
                                                                    message.UpdateTime, sessionGuid, threadID, message.RequiredSpp);

            m_mergerHandler.AddMessage(mergerMessage);
            m_log.Info("IsMergerReady message sent");
            WaitForWorkerAction action = new WaitForWorkerAction(sendClientMessage, handler);

            lock (m_waitMergerLock)
            {
                //wait for merger allocating
                InstanceManager.Get(m_log).WaitForMerger(dispatcherHandler, m_threadsID[sessionGuid], action);
            }
            lock (m_waitWorkerLock)
            {
                //check if workers has been already allocated, if no wait for it
                InstanceManager.Get(m_log).WaitForWorkers(message.InstanceCnt, dispatcherHandler, sessionGuid, threadID, action);
            }
            sendClientMessage(handler, StatusMessage.StatusEnum.Allocated);

            m_log.Info("StartMergeMessage sent to merger. ID: " + threadID);
            m_log.Info("Scene GUID: " + sessionGuid + "Scene ID: " + threadID);
            m_renderAbortHandlers.Add(threadID, new List <MessageQueue <RenderMessage> >()); //each m_renderAbortHandlers contains list of worker queues
            MessageQueue <RenderMessage> toRenderQueue = new MessageQueue <RenderMessage>(threadID.ToString());
            double sppPerOneWorker = 0;                                                      //how much spp is required from each worker

            for (int i = 0; i < message.InstanceCnt; i++)
            {
                //adding new renderqueue for list that correspond to ID of scene which is connected with m_threadsID[sessionGuid]
                try
                {
                    MessageQueue <RenderMessage> newAbortQueue = new MessageQueue <RenderMessage>(threadID.ToString() + m_renderAbortHandlers[threadID].Count.ToString());
                    newAbortQueue.Clear();
                    m_renderAbortHandlers[threadID].Add(newAbortQueue);
                }
                catch (Exception e)
                {
                    m_log.Error("Error creating queue: " + e.Message + ". ID: " + threadID);
                }
                sppPerOneWorker = message.RequiredSpp / message.InstanceCnt;
                ToRenderMessage msg = new ToRenderMessage(sceneName, message.TotalTime,
                                                          message.UpdateTime, threadID, threadID.ToString() +
                                                          (m_renderAbortHandlers[threadID].Count - 1).ToString(), //scene ID + number of worker that is rendering this scene
                                                          sppPerOneWorker);
                m_log.Info("Abort queue name suffix: " + (threadID.ToString() + (m_renderAbortHandlers[threadID].Count - 1)).ToString());
                toRenderQueue.AddMessage(msg);
                m_log.Info("ToRenderMessage sent to worker: " + i);
            }
            m_log.Info("ToRenderMessage sent to workers. ID: " + threadID);
        }