public void BroadcastMessage( Message msg ) { if (HandleMessage(msg)) { log.Debug(string.Format("Message handled: {0}", msg.ToString())); return; } log.Debug(string.Format("Broadcasting message: {0}", msg.ToString())); // put to message queue for each client, including the sender (agents rely on that!) lock( clients ) { foreach( var ci in clients.Values ) { ci.MsgQueue.Add( msg ); } } }
public void BroadcastMessage( Message msg ) { if( Monitor.TryEnter( thisLock ) ) // do not block if just trying to connect { try { if (!connected) return; msg.Sender = name; server.BroadcastMessage(msg); } catch( CommunicationException ) { InternalDisconnect( false ); } catch( TimeoutException ) { InternalDisconnect( false ); } finally { Monitor.Exit( thisLock ); } } }
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); } }
public void Send(Net.Message msg) { ProcessIncomingMessageAndHandleExceptions(msg); }
public void Send(Net.Message msg) { _client.Send(msg); }
/// <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; }
public void BroadcastMessage(string sender, Message msg) { msg.Sender = sender; BroadcastMessage(msg); }