Beispiel #1
0
        public void threadStartMethod()
        {
            stopwatch.Start();

            while (true)
            {
                processControlMessages();

                switch (state)
                {
                case NodeExecutionState.WaitForStart:
                    /*                        // broadcast isready signal to directorNode every second
                     *                     if (stopwatch.ElapsedMilliseconds - lastStatusMessageToCoordinator > 1000){
                     *                         proxyProvider.getProxy(settings.directorNodeName).ReceiveDCEPControlMessageFork(new NodeIsReadyToStartMessage(nodeName));
                     *                         //Console.WriteLine(TAG + "sending ready to start message to director node "+settings.directorNodeName.ToString());
                     *                         lastStatusMessageToCoordinator = stopwatch.ElapsedMilliseconds;
                     *                     } */

                    if (!sentReadyToStartMessage)
                    {
                        proxyProvider.getProxy(settings.directorNodeName).ReceiveDCEPControlMessageFork(new NodeIsReadyToStartMessage(nodeName));
                        sentReadyToStartMessage = true;
                    }

                    break;

                case NodeExecutionState.DoStartInputGeneration:
                    // TODO: check if this is not already running and throw an error if it is
                    primitiveEventSourceService.start();
                    state = NodeExecutionState.Running;
                    processingStep();
                    break;

                case NodeExecutionState.Running:
                    processingStep();
                    break;

                case NodeExecutionState.DoStopInputGeneration:
                    primitiveEventSourceService.stop();
                    state = NodeExecutionState.ProcessingRemainder;

                    break;

                case NodeExecutionState.ProcessingRemainder:
                    processingStep();

                    // when queues are empty, send isReadyToTerminate message every second
                    if (getQueuedEventCount() == 0)
                    {
                        if (stopwatch.ElapsedMilliseconds - lastStatusMessageToCoordinator > 1000)
                        {
                            proxyProvider.getProxy(settings.directorNodeName)
                            .ReceiveDCEPControlMessageFork(new NodeIsReadyToTerminateMessage(nodeName));
                            lastStatusMessageToCoordinator = stopwatch.ElapsedMilliseconds;
                        }
                    }

                    break;

                case NodeExecutionState.DoSendExperimentDataAndTerminate:

                    var data = new ExperimentRunData(
                        locallyGeneratedComplexEventCount,
                        receivedEventCount,
                        locallyGeneratedPrimitiveEventCount,
                        locallyDroppedComplexEvents);

                    proxyProvider.getProxy(settings.directorNodeName).ReceiveDCEPControlMessageFork(new ExperimentRunNodeDataMessage(nodeName, data));
                    Console.WriteLine(TAG + "Sent experiment data. Update loop is terminating.");
                    Thread.Sleep(500);
                    if (getQueuedEventCount() > 0)
                    {
                        Console.WriteLine(TAG + String.Format("WARNING: requested to terminate with {0} events left in queue.", getQueuedEventCount()));
                    }

                    if (directorNodeService != null)
                    {
                        while (!directorNodeService.localNodeCanTerminate)
                        {
                            processControlMessages();
                        }
                    }
                    return;



                case NodeExecutionState.DoTerminate:
                    if (getQueuedEventCount() > 0)
                    {
                        Console.WriteLine(TAG + String.Format("WARNING: requested to terminate with {0} events left in queue.", getQueuedEventCount()));
                    }
                    return;
                }
            }
        }
 public ExperimentRunNodeDataMessage(NodeName sendingNode, ExperimentRunData nodeData) : base(sendingNode)
 {
     this.nodeData = nodeData;
 }