meddlists are dead; messages are gray now
This commit is contained in:
parent
fdc4db1a07
commit
8b78707667
@ -11,17 +11,17 @@ namespace franz.tests
|
|||||||
Console.WriteLine("Hello World, Im' " + Dns.GetHostName());
|
Console.WriteLine("Hello World, Im' " + Dns.GetHostName());
|
||||||
Telefranz.Configure("tester", "alloces:9092", new System.Collections.Generic.List<string>(){"a!"});
|
Telefranz.Configure("tester", "alloces:9092", new System.Collections.Generic.List<string>(){"a!"});
|
||||||
|
|
||||||
Telefranz.Instance.addHandler<silver_messages.global.report>(r => {
|
Telefranz.Instance.addHandler<gray_messages.global.report>(r => {
|
||||||
Console.WriteLine(r);
|
Console.WriteLine(r);
|
||||||
});
|
});
|
||||||
Telefranz.Instance.addHandler<silver_messages.directorial.execute_command>((ec) => {
|
Telefranz.Instance.addHandler<gray_messages.directorial.execute_command>((ec) => {
|
||||||
if(ec.command == "a!"){
|
if(ec.command == "a!"){
|
||||||
Console.WriteLine($"a! command executing! {string.Join("; ", ec.args)}");
|
Console.WriteLine($"a! command executing! {string.Join("; ", ec.args)}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off());
|
Telefranz.Instance.ProduceMessage(new gray_messages.global.sound_off());
|
||||||
System.Threading.Thread.Sleep(15000);
|
System.Threading.Thread.Sleep(15000);
|
||||||
Telefranz.Instance.ProduceMessage(new silver_messages.directorial.execute_command(){
|
Telefranz.Instance.ProduceMessage(new gray_messages.directorial.execute_command(){
|
||||||
command= "a!",
|
command= "a!",
|
||||||
args= new List<string>(){"param 1", "param 2"}
|
args= new List<string>(){"param 1", "param 2"}
|
||||||
});
|
});
|
||||||
|
@ -16,13 +16,13 @@ namespace franz
|
|||||||
private static Telefranz instance = null;
|
private static Telefranz instance = null;
|
||||||
private static readonly object createLock = new object();
|
private static readonly object createLock = new object();
|
||||||
|
|
||||||
static class _TelefranzConsumers<T> where T : silver_messages.message
|
static class _TelefranzConsumers<T> where T : gray_messages.message
|
||||||
{
|
{
|
||||||
internal static readonly Dictionary<Action<T>, Action<KafkaRecord<string, string>>> wrappings
|
internal static readonly Dictionary<Action<T>, Action<KafkaRecord<string, string>>> wrappings
|
||||||
= new Dictionary<Action<T>, Action<KafkaRecord<string, string>>>();
|
= new Dictionary<Action<T>, Action<KafkaRecord<string, string>>>();
|
||||||
}
|
}
|
||||||
private string handling_group { get; set; } = "Liszt";
|
private string handling_group { get; set; } = "Liszt";
|
||||||
private silver_messages.global.report howToReport { get; set; }
|
private gray_messages.global.report howToReport { get; set; }
|
||||||
private ClusterClient clusterClient;
|
private ClusterClient clusterClient;
|
||||||
private Dictionary<string, KafkaConsumer<string, string>> topicConsumers { get; set; }
|
private Dictionary<string, KafkaConsumer<string, string>> topicConsumers { get; set; }
|
||||||
= new Dictionary<string, KafkaConsumer<string, string>>();
|
= new Dictionary<string, KafkaConsumer<string, string>>();
|
||||||
@ -47,7 +47,7 @@ namespace franz
|
|||||||
this.clusterClient = new ClusterClient(clusterClientConfig, consoleLogger);
|
this.clusterClient = new ClusterClient(clusterClientConfig, consoleLogger);
|
||||||
|
|
||||||
handling_group = name;
|
handling_group = name;
|
||||||
this.howToReport = new silver_messages.global.report()
|
this.howToReport = new gray_messages.global.report()
|
||||||
{
|
{
|
||||||
name = name,
|
name = name,
|
||||||
host = Dns.GetHostName(),
|
host = Dns.GetHostName(),
|
||||||
@ -63,11 +63,11 @@ namespace franz
|
|||||||
howToReport.capabilites.checks = checks;
|
howToReport.capabilites.checks = checks;
|
||||||
}
|
}
|
||||||
|
|
||||||
addHandler<silver_messages.global.sound_off>((m) =>
|
addHandler<gray_messages.global.sound_off>((m) =>
|
||||||
{
|
{
|
||||||
ProduceMessage(this.howToReport);
|
ProduceMessage(this.howToReport);
|
||||||
});
|
});
|
||||||
addHandler<silver_messages.global.stop>((m) =>
|
addHandler<gray_messages.global.stop>((m) =>
|
||||||
{
|
{
|
||||||
if (m.name == handling_group)
|
if (m.name == handling_group)
|
||||||
{
|
{
|
||||||
@ -103,7 +103,7 @@ namespace franz
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void addHandler<T>(Action<T> theAction) where T : silver_messages.message
|
public void addHandler<T>(Action<T> theAction) where T : gray_messages.message
|
||||||
{
|
{
|
||||||
var topic = typeof(T).ToString();
|
var topic = typeof(T).ToString();
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ namespace franz
|
|||||||
_TelefranzConsumers<T>.wrappings[theAction] = wrapped;
|
_TelefranzConsumers<T>.wrappings[theAction] = wrapped;
|
||||||
topicSubscribers[topic]++;
|
topicSubscribers[topic]++;
|
||||||
}
|
}
|
||||||
public bool removeHandler<T>(Action<T> theAction) where T : silver_messages.message
|
public bool removeHandler<T>(Action<T> theAction) where T : gray_messages.message
|
||||||
{
|
{
|
||||||
topicConsumers[typeof(T).ToString()].MessageReceived -= _TelefranzConsumers<T>.wrappings[theAction];
|
topicConsumers[typeof(T).ToString()].MessageReceived -= _TelefranzConsumers<T>.wrappings[theAction];
|
||||||
if (_TelefranzConsumers<T>.wrappings.ContainsKey(theAction))
|
if (_TelefranzConsumers<T>.wrappings.ContainsKey(theAction))
|
||||||
@ -152,7 +152,7 @@ namespace franz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProduceMessage<T>(T message) where T : silver_messages.message
|
public void ProduceMessage<T>(T message) where T : gray_messages.message
|
||||||
{
|
{
|
||||||
Console.WriteLine(message.ToString());
|
Console.WriteLine(message.ToString());
|
||||||
clusterClient.Produce(typeof(T).ToString(), message.ToString());
|
clusterClient.Produce(typeof(T).ToString(), message.ToString());
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using silver_messages;
|
using gray_messages;
|
||||||
|
|
||||||
namespace silver_messages.directorial
|
namespace gray_messages.directorial
|
||||||
{
|
{
|
||||||
public abstract class command_ended : silver_messages.message
|
public abstract class command_ended : gray_messages.message
|
||||||
{
|
{
|
||||||
//name of the command that was called
|
//name of the command that was called
|
||||||
public string command { get; set; }
|
public string command { get; set; }
|
@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using silver_messages;
|
using gray_messages;
|
||||||
namespace silver_messages.directorial
|
namespace gray_messages.directorial
|
||||||
{
|
{
|
||||||
public class command_error : silver_messages.message
|
public class command_error : gray_messages.message
|
||||||
{
|
{
|
||||||
//name of the command that was called
|
//name of the command that was called
|
||||||
public string command { get; set; }
|
public string command { get; set; }
|
@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using silver_messages;
|
using gray_messages;
|
||||||
namespace silver_messages.directorial
|
namespace gray_messages.directorial
|
||||||
{
|
{
|
||||||
public class command_output : silver_messages.message
|
public class command_output : gray_messages.message
|
||||||
{
|
{
|
||||||
//name of the command that was called
|
//name of the command that was called
|
||||||
public string command { get; set; }
|
public string command { get; set; }
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using silver_messages;
|
using gray_messages;
|
||||||
|
|
||||||
namespace silver_messages.directorial
|
namespace gray_messages.directorial
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* if this is the name of one of your capabilities, pass args to it and execute it.
|
* if this is the name of one of your capabilities, pass args to it and execute it.
|
||||||
@ -12,7 +12,7 @@ namespace silver_messages.directorial
|
|||||||
* command_error as you get them, and if it ends some other way, send command_completed
|
* command_error as you get them, and if it ends some other way, send command_completed
|
||||||
* with empty stdout and stderr.
|
* with empty stdout and stderr.
|
||||||
*/
|
*/
|
||||||
public class execute_command : silver_messages.message
|
public class execute_command : gray_messages.message
|
||||||
{
|
{
|
||||||
public string command { get; set; }
|
public string command { get; set; }
|
||||||
public List<string> args { get; set; } = new List<string>();
|
public List<string> args { get; set; } = new List<string>();
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
namespace silver_messages.global
|
namespace gray_messages.global
|
||||||
{
|
{
|
||||||
public class report : silver_messages.message
|
public class report : gray_messages.message
|
||||||
{
|
{
|
||||||
//your name
|
//your name
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using silver_messages;
|
using gray_messages;
|
||||||
|
|
||||||
namespace silver_messages.global
|
namespace gray_messages.global
|
||||||
{
|
{
|
||||||
public class restart : silver_messages.message
|
public class restart : gray_messages.message
|
||||||
{
|
{
|
||||||
//check if this is you (i.e., your handling group). If so, restart. Yourself, not the hardware.
|
//check if this is you (i.e., your handling group). If so, restart. Yourself, not the hardware.
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
10
franz/gray_messages/global/sound_off.cs
Normal file
10
franz/gray_messages/global/sound_off.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using gray_messages;
|
||||||
|
|
||||||
|
namespace gray_messages.global
|
||||||
|
{
|
||||||
|
//if you receive this, respond with a report
|
||||||
|
public class sound_off : gray_messages.message { }
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using silver_messages;
|
using gray_messages;
|
||||||
|
|
||||||
namespace silver_messages.global
|
namespace gray_messages.global
|
||||||
{
|
{
|
||||||
public class stop : silver_messages.message
|
public class stop : gray_messages.message
|
||||||
{
|
{
|
||||||
//check if this is you (i.e., your handling group). If so, stop. Yourself, not the hardware.
|
//check if this is you (i.e., your handling group). If so, stop. Yourself, not the hardware.
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
@ -4,7 +4,7 @@ using System.IO;
|
|||||||
using Kafka.Public;
|
using Kafka.Public;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace silver_messages
|
namespace gray_messages
|
||||||
{
|
{
|
||||||
//protip: you can derive from message and I'll dispatch it back to you just as you would expect
|
//protip: you can derive from message and I'll dispatch it back to you just as you would expect
|
||||||
public abstract class message : IMemorySerializable
|
public abstract class message : IMemorySerializable
|
@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using silver_messages;
|
|
||||||
|
|
||||||
namespace silver_messages.global
|
|
||||||
{
|
|
||||||
//if you receive this, respond with a report
|
|
||||||
public class sound_off : silver_messages.message { }
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user