Пример #1
0
        /// <summary>
        /// Handle any additional receiving the node might want to do
        /// in the receiver class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void HandleAdditionalReceiving(object sender, DataReceivedEventArgs e)
        {
            NodeComm receivedData = e as NodeComm;

            if (receivedData != null)
            {
                switch (receivedData.Protocol)
                {
                case NodeComm.MessageType.File:
                    // This will block on the IOStream until the file reading
                    // is over. The next thing sent over the network must be a file.
                    _job = JsonConvert.DeserializeObject <JobRef>(receivedData.Args[1]);
                    FileRead.ReadInWriteOut(Proxy.IOStream, _job.FileName);
                    //job = receivedData;
                    // after we have finished reading the data, let node manager know
                    OnDataReceived(new NodeComm(DataReceivedEventArgs.ConstructMessage("fileread")));
                    break;

                case NodeComm.MessageType.Execute:
                    //TODO, this should be its own task/thread
                    _parent.Logger.Log("Node: executing");
                    JobLauncher j = new JobLauncher(_job, _parent);
                    j.LaunchJob();
                    break;

                case NodeComm.MessageType.Shutdown:
                case NodeComm.MessageType.Quit:
                    // shutting down or quitting, we are done receving
                    DoneReceiving = true;
                    break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handles cleanup and communcation on shutdown
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnUserExit(object sender, ConsoleCancelEventArgs e)
        {
            Logger.Log("Node - Shuting down, user hit ctrl-c");
            // set cancel to true so we can do our own cleanup
            e.Cancel = true;
            // queue up the quitting message to the server
            _proxy.QueueDataEvent(new NodeComm(DataReceivedEventArgs.ConstructMessage("quit")));

            // join on both sending and receiving threads
            _proxy.Join();
        }
Пример #3
0
 /// <summary>
 /// When the user exits the command line
 /// with Ctrl-C tell all connections to shutdown.
 /// Cleanup all threads and stop listening on incoming connections.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void OnUserExit(object sender, ConsoleCancelEventArgs e)
 {
     // set this to true so that we do not exit immediately
     e.Cancel = true;
     // don't allow any more connections while we clean up.
     _acceptingConnections = false;
     // stop the scheduler
     Scheduler.Stop();
     // Queue up the kill message
     // then join on the proxy (which joins on both
     // of its threads) after all have finished.
     // stop listening and quit.
     foreach (Proxy p in Connections)
     {
         p.QueueDataEvent(new NodeManagerComm(
                              DataReceivedEventArgs.ConstructMessage("kill")));
         p.Join();
     }
     // stop listening for incoming connections
     // this exits Main() do this at the end.
     StopListening();
 }