meddlists are dead; messages are gray now

This commit is contained in:
Adam R Grey 2022-11-30 17:43:43 -05:00
parent fdc4db1a07
commit 8b78707667
12 changed files with 43 additions and 43 deletions

View File

@ -11,17 +11,17 @@ namespace franz.tests
Console.WriteLine("Hello World, Im' " + Dns.GetHostName());
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);
});
Telefranz.Instance.addHandler<silver_messages.directorial.execute_command>((ec) => {
Telefranz.Instance.addHandler<gray_messages.directorial.execute_command>((ec) => {
if(ec.command == "a!"){
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);
Telefranz.Instance.ProduceMessage(new silver_messages.directorial.execute_command(){
Telefranz.Instance.ProduceMessage(new gray_messages.directorial.execute_command(){
command= "a!",
args= new List<string>(){"param 1", "param 2"}
});

View File

@ -16,13 +16,13 @@ namespace franz
private static Telefranz instance = null;
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
= new Dictionary<Action<T>, Action<KafkaRecord<string, string>>>();
}
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 Dictionary<string, KafkaConsumer<string, string>> topicConsumers { get; set; }
= new Dictionary<string, KafkaConsumer<string, string>>();
@ -47,7 +47,7 @@ namespace franz
this.clusterClient = new ClusterClient(clusterClientConfig, consoleLogger);
handling_group = name;
this.howToReport = new silver_messages.global.report()
this.howToReport = new gray_messages.global.report()
{
name = name,
host = Dns.GetHostName(),
@ -63,11 +63,11 @@ namespace franz
howToReport.capabilites.checks = checks;
}
addHandler<silver_messages.global.sound_off>((m) =>
addHandler<gray_messages.global.sound_off>((m) =>
{
ProduceMessage(this.howToReport);
});
addHandler<silver_messages.global.stop>((m) =>
addHandler<gray_messages.global.stop>((m) =>
{
if (m.name == handling_group)
{
@ -103,7 +103,7 @@ namespace franz
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();
@ -133,7 +133,7 @@ namespace franz
_TelefranzConsumers<T>.wrappings[theAction] = wrapped;
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];
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());
clusterClient.Produce(typeof(T).ToString(), message.ToString());

View File

@ -1,10 +1,10 @@
using System;
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
public string command { get; set; }

View File

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using silver_messages;
namespace silver_messages.directorial
using gray_messages;
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
public string command { get; set; }

View File

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using silver_messages;
namespace silver_messages.directorial
using gray_messages;
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
public string command { get; set; }

View File

@ -1,8 +1,8 @@
using System;
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.
@ -12,7 +12,7 @@ namespace silver_messages.directorial
* command_error as you get them, and if it ends some other way, send command_completed
* 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 List<string> args { get; set; } = new List<string>();

View File

@ -1,8 +1,8 @@
using System;
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
public string name { get; set; }

View File

@ -1,10 +1,10 @@
using System;
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.
public string name { get; set; }

View 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 { }
}

View File

@ -1,10 +1,10 @@
using System;
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.
public string name { get; set; }

View File

@ -4,7 +4,7 @@ using System.IO;
using Kafka.Public;
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
public abstract class message : IMemorySerializable

View File

@ -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 { }
}