public Dispatcher(TcpServer server, Registry registry, MessageArchive messageArchive) { Server = server; Registry = registry; MessageArchive = messageArchive; DispatchQueue = new BlockingCollection<Command>(new ConcurrentQueue<Command>()); DispatchPreemptStack = new BlockingCollection<Command>(new ConcurrentStack<Command>()); Log = Logger.GetInstance(); }
public override void VisitRegistry(Registry registry) { //get all the recipenats foreach (var cap in FromInstance.Capabilities) { sendto.AddRange(registry.GetDependents(cap)); } //send to all the recipenats foreach (var appinstance in sendto) { appinstance.Send(msg); } }
/// <summary> /// Notify dependencies that the app has gone down /// </summary> /// <param name="registry"></param> public override void VisitRegistry(Registry registry) { Log.Info(String.Format( "{0} {1} is now \"{2}\"", instance.DisplayName, instance.InstanceId, instance.AppStatus.ToString() )); var capabilities = instance.Capabilities; // apps that depend on this, mapped to the capabilities they expect it to use var apps = new Dictionary<AppInstance, List<string>>(); // Build the list of things that depend on this foreach (var capability in capabilities) { foreach (var app in registry.GetDependents(capability)) { if(!apps.ContainsKey(app)) { apps[app] = new List<string>(); } apps[app].Add(capability.Name); } } // Assemble the message that gets sent for each app foreach (var app in apps) { var message = new AppDependency(); message.Dependencies = new Dictionary<string, Dictionary<string, string>>(); foreach(var capability in app.Value) { message.Dependencies[capability] = new Dictionary<string, string>() { { instance.InstanceId, instance.AppStatus.ToString() } }; } if (message.Dependencies.Count > 0) { app.Key.Send("APP_DEPENDENCY " + message.Serialize()); } } }
public override void VisitRegistry(Registry registry) { if (!HasValidGuid) { System.Diagnostics.Debug.WriteLine("Guid was invalid: " + guid); return; } foreach (string instanceId in this.query.InstanceId) { AppInstance toInstance; if (registry.TryGetInstance(instanceId, out toInstance)) { sendQueryTo(toInstance); ShouldArchive = true; } } }
// Generate the dependency list public override void VisitRegistry(Registry registry) { var dependencies = instance.Dependencies; var message = new AppDependency(); foreach (var capability in dependencies) { var capabilityList = new Dictionary<string, string>(); foreach(var appInstance in registry.GetProviders(capability)) { capabilityList.Add(appInstance.InstanceId, appInstance.AppStatus.ToString()); } message.Dependencies[capability.Name] = capabilityList; } instance.Send("APP_DEPENDENCY " + message.Serialize()); }
/// <summary> /// Copy all information from the manifest into the new app instance /// and add it to the registry /// </summary> /// <param name="registry">the registry being visited</param> public override void VisitRegistry(Registry registry) { // Drop the connection if the instance ID is a duplicate if (registry.HasInstance(manifest.InstanceId)) { failure = new ManifestFail("Instance ID " + manifest.InstanceId + " already in use", instance); return; } if (manifest.InstanceId != null) { instance.InstanceId = manifest.InstanceId; } instance.Name = manifest.Name; instance.Version = new Version(manifest.Version); instance.ApiVersion = (uint) manifest.API; instance.Description = manifest.Description; instance.DisplayName = manifest.DisplayName; foreach (string capability in manifest.Capabilities.Keys) { var c = new Capability( capability, new Version(manifest.Capabilities[capability]) ); instance.AddCapability(c); } foreach (string capability in manifest.Dependencies.Keys) { var c = new Capability( capability, new Version(manifest.Dependencies[capability]) ); instance.AddDependency(c); } registry.Register(instance); // We have to send the message to the instance on our own instance.AppStatus = Status.down; instance.Send("APP_MANIFEST_OK " + okMsg.Serialize()); Log.Info(instance.DisplayName + " created with instance ID " + instance.InstanceId); }
static void Main(string[] args) { Log = Logger.GetInstance(); Log.Info("Starting up"); TcpServer server = null; if(UsingTls(args)) { Log.Info("Using TLS"); X509Certificate2 cert = null; var foundCert = TryGetX509Certificate(args, out cert); // We have a certificate, so create the server if (foundCert) { server = new TlsServer(IPAddress.Any, DEFAULT_PORT, cert); } } else { Log.Warning("Not using TLS"); //insecure version server = new TcpServer(IPAddress.Any, DEFAULT_PORT); } // If we can't start the server, we can't run anything if(server == null) { Log.Error("Could not start the server"); Environment.Exit(1); } // All systems go, start the server var registry = new Registry(); var MessageArchive = new MessageArchive(); var dispatcher = new Dispatcher(server, registry, MessageArchive); dispatcher.Run(); }
public override void VisitRegistry(Registry registry) { if (!HasValidGuid) { Debug.WriteLine("GUID " + this.guid + " is invalid, not sending query"); return; } var cap = GetCapability(); var msg = "MSG_QUERY " + query.Serialize(); if (cap != null) { foreach (AppInstance other in registry.GetProviders(cap)) { other.Send(msg); ShouldArchive = true; } } else { Debug.WriteLine("Warning: App did not declare a " + query.Capability + " dependency, not sending message"); } }
public virtual void VisitRegistry(Registry registry) { }
/// <summary> /// Removes an app instance from the registry /// </summary> /// <param name="registry"></param> public override void VisitRegistry(Registry registry) { registry.Remove(instance); Log.Info(String.Format("{0} {1} has disconnected", instance.DisplayName, instance.InstanceId)); }