Packets are generated in a node with a content and a destination. Nodes are linked in a ring and passOn packages unless the package is for themselves.
Next versions to come, with subclassed nodes and more tests.
Syntax highlighted version in http://pastie.org/373095
Future Work is Handling packages in a thread (and learning how to use futures), to be able to block some packages in certain nodes but be able to continue passing nodes along while processing (blocking) a given package.Packet := Object clone do(
content := nil
destinatary := nil
)
Node := Object clone do (
id ::= nil
next ::= nil
generate := (content, dest,
a := Packet clone
a content = content
a destinatary = dest
#a destinatary println
(a)
)
receive := (packet,
("I'm ".. self id .. ". The packet goes to".. packet destinatary .. "") println
if(packet destinatary == self id,
("I've received a package with the message:".. packet content .. "") println ,
#if (packet content asString containsSeq("sleep") and self id == 4, wait(2)) #nonblocking? anyone?
(packet)))
passOn := (packet,
#self id asString println
if(self next != nil, r:= self next (packet), "WTF?! I've no next node!" println))
)
lista := List clone
lista append (Node clone do ( (0)))
for(i,100,1,-1,
lista (Node clone do( (i) (lista (lista size -1)))))
lista (0) next = lista (lista size-1)
l1 := lista (0) ("matat1",45)
#l2 := lista at(0) generate("matatsleep",65)
#l3 := lista at(0) generate("matat3",20)
That would allow having many packages navigating the 'net'.