void processIncomingMessage(Message msg) { Type t = msg.GetType(); if( t != typeof(AppsStateMessage)) // do not log frequent messages { log.DebugFormat("Incoming Message {0}", msg.ToString()); } if (t == typeof(AppsStateMessage)) { var m = msg as AppsStateMessage; updateRemoteAppState(m.appsState); } else if (t == typeof(SelectPlanMessage)) { var m = msg as SelectPlanMessage; localOps.SelectPlan(m.plan); } else if (t == typeof(LaunchAppMessage)) { var m = msg as LaunchAppMessage; if (m.appIdTuple.MachineId == machineId) { localOps.LaunchApp(m.appIdTuple); } } else if (t == typeof(KillAppMessage)) { var m = msg as KillAppMessage; if (m.appIdTuple.MachineId == machineId) { localOps.KillApp(m.appIdTuple); } } else if (t == typeof(RestartAppMessage)) { var m = msg as RestartAppMessage; if (m.appIdTuple.MachineId == machineId) { localOps.RestartApp(m.appIdTuple); } } else if (t == typeof(StartPlanMessage)) { var m = msg as StartPlanMessage; localOps.StartPlan(); } else if (t == typeof(StopPlanMessage)) { var m = msg as StopPlanMessage; localOps.StopPlan(); } else if (t == typeof(KillPlanMessage)) { var m = msg as KillPlanMessage; localOps.KillPlan(); } else if (t == typeof(RestartPlanMessage)) { var m = msg as RestartPlanMessage; localOps.RestartPlan(); } else if (t == typeof(CurrentPlanMessage)) { var m = msg as CurrentPlanMessage; // if master's plan is same as ours, do not do anything, othewise load master's plan var localPlan = localOps.GetCurrentPlan(); if (m.plan != null && (localPlan == null || !m.plan.Equals(localPlan))) { localOps.SelectPlan(m.plan); } } else if (t == typeof(PlanRepoMessage)) { var m = msg as PlanRepoMessage; localOps.SetPlanRepo(m.repo); } else if (t == typeof(RemoteOperationErrorMessage)) { var m = msg as RemoteOperationErrorMessage; throw new RemoteOperationErrorException(m.Requestor, m.Message, m.Attributes); } }
/// <summary> /// returns true if the message was fully handled and shall not be further processed /// </summary> /// <param name="clientName"></param> /// <param name="msg"></param> /// <returns></returns> private bool HandleMessage(Message msg) { Type t = msg.GetType(); if (t == typeof(SelectPlanMessage)) { var m = msg as SelectPlanMessage; lock (clients) { CurrentPlan = m.plan; } } else if (t == typeof(CurrentPlanMessage)) { var m = msg as CurrentPlanMessage; lock (clients) { CurrentPlan = m.plan; } } else if (t == typeof(PlanRepoMessage)) { var m = msg as PlanRepoMessage; lock (clients) { PlanRepo = new List<ILaunchPlan>(m.repo); } } return false; }