diff --git a/src/Configuration/Configurations/BrokerConfiguration.cs b/src/Configuration/Configurations/BrokerConfiguration.cs index cd51369..12ead4e 100644 --- a/src/Configuration/Configurations/BrokerConfiguration.cs +++ b/src/Configuration/Configurations/BrokerConfiguration.cs @@ -22,6 +22,8 @@ public class BrokerConfiguration : IConfiguration { public string BaseTopic { get; set; } public string PayloadType { get; set; } + public RoutingTable Routing { get; set; } + public BrokerConfiguration() { } diff --git a/src/Configuration/Configurations/SocketConfiguration.cs b/src/Configuration/Configurations/SocketConfiguration.cs index 5d6ea08..bac8fcb 100644 --- a/src/Configuration/Configurations/SocketConfiguration.cs +++ b/src/Configuration/Configurations/SocketConfiguration.cs @@ -32,30 +32,31 @@ public class SocketConfiguration : IConfiguration { public SubscriptionOptions DefaultSubscriptionOptions { get; set; } public RequestOptions DefaultRequestOptions { get; set; } - - public SocketConfiguration() { + public RoutingTable Routing { get; set; } + + public SocketConfiguration() { DefaultPublicationOptions = new PublicationOptions(); DefaultSubscriptionOptions = new SubscriptionOptions(); - DefaultRequestOptions = new RequestOptions(); + DefaultRequestOptions = new RequestOptions(); } public object Clone() { var c = new SocketConfiguration(); - c.Type = Type; + c.Type = Type; c.Url = Url; c.MonitorConfiguration = MonitorConfiguration; - c.MonitorIntervalMilliseconds= MonitorIntervalMilliseconds; - c.Name= Name; - c.Id= Id; - c.SocketType= SocketType; - c.Broker= Broker; - c.BaseTopic= BaseTopic; - c.PayloadType= PayloadType; + c.MonitorIntervalMilliseconds = MonitorIntervalMilliseconds; + c.Name = Name; + c.Id = Id; + c.SocketType = SocketType; + c.Broker = Broker; + c.BaseTopic = BaseTopic; + c.PayloadType = PayloadType; c.DefaultPublicationOptions = (PublicationOptions)DefaultPublicationOptions.Clone(); - c.DefaultSubscriptionOptions= (SubscriptionOptions)DefaultSubscriptionOptions.Clone(); - c.DefaultRequestOptions= (RequestOptions)DefaultRequestOptions.Clone(); + c.DefaultSubscriptionOptions = (SubscriptionOptions)DefaultSubscriptionOptions.Clone(); + c.DefaultRequestOptions = (RequestOptions)DefaultRequestOptions.Clone(); return c; } diff --git a/src/Configuration/DataStructures.cs b/src/Configuration/DataStructures.cs index 6139544..02d1f76 100644 --- a/src/Configuration/DataStructures.cs +++ b/src/Configuration/DataStructures.cs @@ -142,4 +142,106 @@ public SubscriptionOptions GetResponseSubscriptionOptions() { } } + public class RoutingTable : ICloneable { + + private List edges; + private List nodes; + + public List Edges { + get { return edges; } + private set { edges = value; } + } + public List Nodes { + get { return nodes; } + private set { nodes = value; } + } + + public RoutingTable() { + edges = new List(); + nodes = new List(); + } + + public object Clone() { + var t = new RoutingTable(); + t.nodes.AddRange(nodes.Select(x => (Node)x.Clone())); + t.edges.AddRange(edges.Select(x => (Edge)x.Clone())); + + return t; + } + + public RoutingTable ExtractForNode(string id) { + var t = new RoutingTable(); + + t.edges.AddRange(edges.Where(x => x.Source.Id == id || x.Sink.Id == id)); + nodes.AddRange(t.edges.Select(x => x.Source)); + nodes.AddRange(t.edges.Select(x => x.Sink)); + + return t; + } + + public void AddNode(Node n) { + nodes.Add(n); + } + + public void AddEdge(Edge e) { + edges.Add(e); + } + + public void RemoveNode(string id) { + edges.RemoveAll(x => x.Source.Id == id || x.Sink.Id == id); + nodes.RemoveAll(x => x.Id == id); + } + + public void RemoveEdge(string id) { + edges.RemoveAll(x => x.Source.Id == id || x.Sink.Id == id); + } + } + + public class Edge : ICloneable { + + public string Id { get; set; } + public Node Source { get; set; } + public Node Sink { get; set; } + public string Query { get; set; } + + public Edge() { } + public Edge(string id, Node source, Node sink, string query = null) { + Id = id; + Source = source; + Sink = sink; + Query = query; + } + + public object Clone() { + return new Edge(Id, Source, Sink, Query); + } + + public string GetRoutingString(string delimiter) { + return $"{Source.Typename}{delimiter}{Source.Id}"; + } + } + + public class Node : ICloneable { + public string Id { get; set; } + + public string Typename { get; set; } + + public string FullyQualifiedTypename { get; set; } + + public Node() { } + + public Node(string id, string typename, string fullyQualifiedTypename) { + Id = id; + Typename = typename; + FullyQualifiedTypename = fullyQualifiedTypename; + } + + public object Clone() { + return new Node(Id, Typename, FullyQualifiedTypename); + } + + public string GetRoutingString(string delimiter) { + return $"{Typename}{delimiter}{Id}"; + } + } } diff --git a/src/Configuration/Parser/YamlParser.cs b/src/Configuration/Parser/YamlParser.cs index 32146f6..9d2e8fb 100644 --- a/src/Configuration/Parser/YamlParser.cs +++ b/src/Configuration/Parser/YamlParser.cs @@ -33,6 +33,8 @@ public IConfiguration Parse(string uri) { if(config.Type == "Socket") { config = dser.Deserialize(doc); + } else if(config.Type == "Broker") { + config = dser.Deserialize(doc); } config.Url = uri;