コード例 #1
0
        public DSDPSNode()
        {
            GlobalRabbitMQConnection.Instance.GetConnection().ConnectionShutdown += DSDPSNode_ConnectionShutdown;
            jobListDictionary = new Dictionary<int, List<Job>>();
            jobProcessorManager = new JobProcessorkManager();
            jobProcessorManager.OnJobCompleted += JobProcessorManager_OnJobCompleted;
            jobProcessorManager.OnJobProgress += JobProcessorManager_OnJobProgress;
            updateManager = new UpdateManager();

            syncServerComm = new SyncMessageSender("DSDPS_SYNC", "NODE", "SERVER");
            asyncServerCommSender = null;

        }
コード例 #2
0
 public DSDPSClient(Action<string, int> ServerClientJobSubmitCallback, Action<string, int> ServerClientJobCancelCallback
     , Action<string, List<JobStatus>> ServerClientJobStatusCallback)
 {
     GlobalRabbitMQConnection.Instance.GetConnection().ConnectionShutdown += DSDPSClient_ConnectionShutdown;
     jobListDictionary = new Dictionary<int, List<Job>>();
     //serverMessageSender = new MessageSender("DPSClientToServer");
     syncServerComm = new SyncMessageSender("DSDPS_SYNC", "CLIENT", "SERVER");
     asyncServerCommSender = null;
     this.ServerClientJobSubmitCallback = ServerClientJobSubmitCallback;
     this.ServerClientJobCancelCallback = ServerClientJobCancelCallback;
     this.ServerClientJobStatusCallback = ServerClientJobStatusCallback;
     
 }
コード例 #3
0
        public void AsyncMessageProcessor(string incomingMsgStr,object orgMsg)
        {
            try
            {
                AsyncServerNodeRequestMessage incomingMsgBase = JsonConvert.DeserializeObject<AsyncServerNodeRequestMessage>(incomingMsgStr);

                switch (incomingMsgBase.messageType)
                {
                    case AsyncMessageType.SERVER_NODE_JOB_SUBMIT:
                        {
                            AsyncServerNodeJobSubmitRequestMessage reqMsg = JsonConvert.DeserializeObject<AsyncServerNodeJobSubmitRequestMessage>(incomingMsgStr);
                            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[S->N][JOB_SUBMIT]" + reqMsg.GetJson(true));

                            List<Job> jobList = reqMsg.jobList;
                            bool result = false;
                            foreach (Job job in jobList)
                            {
                                lock (lockObj)
                                {
                                    result |= jobProcessorManager.StartJobProcessor(job);
                                }
                            }

                            AsyncServerNodeJobSubmitResponseMessage respMsg = new AsyncServerNodeJobSubmitResponseMessage();
                            if (result)
                            {
                                respMsg.returnCode = 0;
                                respMsg.returnMessage = "Job submit request accepted.";
                            }
                            else
                            {
                                respMsg.returnCode = -1;
                                respMsg.returnMessage = "Job submit request failed.";
                            }
                            respMsg.orgMsgID = reqMsg.msgID;
                            asyncServerCommSender.SendResponse(respMsg);
                            break;
                        }
                    case AsyncMessageType.SERVER_NODE_JOB_CANCEL:
                        lock (lockObj)
                        {
                            AsyncServerNodeJobCancelRequestMessage reqMsg = JsonConvert.DeserializeObject<AsyncServerNodeJobCancelRequestMessage>(incomingMsgStr);
                            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[S->N][JOB_CANCEL]" + reqMsg.GetJson(true));
                            //ret will be true if at least one cancel request succeed
                            List<int> jobIDList = reqMsg.jobIDList;
                            bool result = false;
                            foreach (int jobID in jobIDList)
                            {
                                result |= jobProcessorManager.TryCancelTask(jobID);
                            }
                            AsyncServerNodeJobCancelResponseMessage respMsg = new AsyncServerNodeJobCancelResponseMessage();
                            respMsg.orgMsgID = reqMsg.msgID;
                            if (result == true)
                            {
                                respMsg.returnCode = 0;
                                respMsg.returnMessage = "Job cancel request accepted.";
                            }
                            else
                            {
                                respMsg.returnCode = -1;
                                respMsg.returnMessage = "Job cancel request failed.";
                            }

                            if (!asyncServerCommSender.SendResponse(respMsg))
                                Console.WriteLine("[Error] SendResponse failed!");
                            break;
                        }
                    case AsyncMessageType.SERVER_NODE_JOB_STATUS:
                        lock (lockObj)
                        {
                            AsyncServerNodeJobStatusRequestMessage reqMsg = JsonConvert.DeserializeObject<AsyncServerNodeJobStatusRequestMessage>(incomingMsgStr);
                            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[S->N][JOB_STATUS]" + reqMsg.GetJson(true));

                            AsyncServerNodeJobStatusResponseMessage respMsg = new AsyncServerNodeJobStatusResponseMessage();
                            respMsg.orgMsgID = reqMsg.msgID;
                            if (reqMsg.jobIDList.Count > 0)
                            {

                                foreach (int jobID in reqMsg.jobIDList)
                                {
                                    JobStatus jobStatus = jobProcessorManager.GetJobStatusClone(jobID);
                                    respMsg.jobStatusList.Add(jobStatus);
                                }
                                respMsg.returnCode = 0;
                                respMsg.returnMessage = "Job status returned.";
                            }
                            else
                            {
                                respMsg.returnCode = -1;
                                respMsg.returnMessage = "Job status request failed.";
                            }
                            if (!asyncServerCommSender.SendResponse(respMsg))
                                Console.WriteLine("[Error] SendResponse failed!");
                            break;
                        }
                    case AsyncMessageType.SERVER_NODE_NODE_PROC_UPDATE:
                        int updateProcVersion = 0;
                        lock (lockObj)
                        {
                            AsyncServerNodeProcUpdateCastMessage reqMsg = JsonConvert.DeserializeObject<AsyncServerNodeProcUpdateCastMessage>(incomingMsgStr);
                            updateProcVersion = reqMsg.updateVersion;
                            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[S->N][NODE_PROC_UPDATE]" + reqMsg.GetJson(true));
                        }
                        Task.Factory.StartNew(() =>
                        {
                            using (SyncMessageSender sender = new SyncMessageSender("DSDPS_UPDATE", "NODE", "SERVER"))
                            {
                                sender.Init(60000 * 5, true);
                                SyncNodeServerGetProcBinaryRequest req = new SyncNodeServerGetProcBinaryRequest();
                                req.updateVersion = updateProcVersion;
                                Console.WriteLine("[SERVER_NODE_NODE_PROC_UPDATE] requesting file...");
                                updateManager.StartBlocking();
                                string ret = sender.Call(req.GetJson());
                                Console.WriteLine("[SERVER_NODE_NODE_PROC_UPDATE] done!");
                                SyncNodeServerGetProcBinaryResponse resp = JsonConvert.DeserializeObject<SyncNodeServerGetProcBinaryResponse>(ret);
                                lock (lockObj)
                                {
                                    Console.WriteLine("Stop heartbeat task");
                                    hbManager.Stop();
                                    updateManager.UpdateJobProcessor(updateProcVersion, resp.compressedFile);
                                }
                            }
                        });
                        break;
                    case AsyncMessageType.SERVER_NODE_NODE_UPDATE:
                        int updateNodeVersion = 0;
                        lock (lockObj)
                        {
                            AsyncServerNodeNodeBinUpdateCastMessage reqMsg = JsonConvert.DeserializeObject<AsyncServerNodeNodeBinUpdateCastMessage>(incomingMsgStr);
                            updateNodeVersion = reqMsg.updateVersion;
                            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[S->N][NODE_UPDATE]" + reqMsg.GetJson(true));
                            DSDPSNode.Instance.Logout();
                            Task.Factory.StartNew(() =>
                            {
                                using (SyncMessageSender sender = new SyncMessageSender("DSDPS_UPDATE", "NODE", "SERVER"))
                                {
                                    sender.Init(60000 * 5, true);
                                    SyncNodeServerGetNodeBinaryRequest req = new SyncNodeServerGetNodeBinaryRequest();
                                    req.updateVersion = updateNodeVersion;
                                    Console.WriteLine("[SERVER_NODE_NODE_PROC_UPDATE] requesting file...");
                                    req.nodeKey = NodeKey;
                                    updateManager.StartBlocking();
                                    string ret = sender.Call(req.GetJson());
                                    Console.WriteLine("[SERVER_NODE_NODE_PROC_UPDATE] done!");
                                    SyncNodeServerGetProcBinaryResponse resp = JsonConvert.DeserializeObject<SyncNodeServerGetProcBinaryResponse>(ret);
                                    lock (lockObj)
                                    {
                                        Console.WriteLine("Stop heartbeat task");
                                        hbManager.Stop();
                                        if (!updateManager.UpdateNode(updateNodeVersion, resp.compressedFile))
                                            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[Error][AsyncMessageProcessor] Node update failed." + incomingMsgBase.messageType);
                                    }
                                }
                            });
                        }
                        break;
                    default:
                        Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[Error][AsyncMessageProcessor] Not supported type of message." + incomingMsgBase.messageType);
                        break;
                }

            }
            catch (Exception e)
            {
                var st = new StackTrace(e, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]") + "[Error][ServerSideRPCRequestProcessor][" + line + "] " + e.Message);
            }
        }