March Meeting
From DojoWiki
For this event, we started discussing implementing a simple communication protocol.
This morphed into a discussion of how a distributed system might be architected.
At work, I'm in a position where I might need to write software to run on computer's distributed in a network. Each computer should receive a broadcast message from the other computers and act on it if appropriate; and ignore it otherwise.
However, the system needs to allow each node to "fill-in" for other nodes if they are unavailable.
Consequently, it seems like some kind of concurrency/transaction handling needs to be built.
Other than diagramming the problem, we didn't get that far. The general programming direction was to build objects that could pass a "Message Queue" around that would describe the current state of whole system, by knowing what each individual object was doing.
Here is some C# code I wrote to get started.
[TestFixture]
public class TestHandshaking {
[Test]
public void testConnection() {
Node[] nodes = new Node[] { new Node("CashReg") } ;
Assert.AreEqual("CashReg", nodes[0].Name) ;
}
[Test]
public void testMessage() {
Node[] nodes = new Node[]{ new Node("CashReg") } ;
Message message = new Message(1, "ORDER") ;
nodes[0].Send(message) ;
Assert.AreEqual(States.WAITING, nodes[0].State) ;
}
[Test]
public void testMessageReceived() {
Node[] nodes = new Node[] {
new Node("CashReg"),
new Node("KitchenMonitor")
} ;
Message message = new Message(1, "ORDER") ;
nodes[0].Send(message) ;
//Check State of source node
Assert.AreEqual(States.PEER_RECEIVED, nodes[0].State) ;
//Check State of target node
Assert.AreEqual(States.WAITING, nodes[1].State) ;
}
}
public class Message {
private int m_Id ;
public int Id {
get {return m_Id ; }
}
public Message(int id, string message) {
m_Id = id ;
}
}
public enum States: int
{
WAITING = 0
}
public class Node {
private string m_Name ;
private States m_State ;
public Node(string name) {
this.m_Name = name ;
}
public string Name {
get { return this.m_Name ; }
set { this.m_Name = value ; }
}
public States State {
get { return this.m_State ; }
set { this.m_State = value ; }
}
public void Send(Message message) {
m_Messages.Add(message.Id, message) ;
this.State = States.WAITING ;
}
Dictionary<int, Message> m_Messages = new Dictionary<int, Message>();
public Message MessageStack(int id) {
return m_Messages[id] ;
}
}
