Philosopher Actor classes

The Philosopher Actor classes provide classes with methods for the Dining Philosophers Problem from test 2.

PhilosopherActor class

class PhilosopherActor(*args, **kwargs)

Bases: sphof.philosopher_actors.Philosopher, sphof.actors.Actor

draw()

Called after update

eat()

The eat method makes the philosopher eat. This fills its list of topics for thinking (food for thought)

emit_signal(emitter, value)

Update the value of the emitter and signal all subscribed receivers

Parameters:
  • emitter (str) – name of the emitting variable
  • value – the new value
on_peer_enter(peer, name, headers, *args, **kwargs)

This method is called when a new peer is discovered

Parameters:
  • peer (uuid) – the id of the new peer
  • name (str) – the name of the new peer
  • hdrs – any headers of the peer
register_string(name, value, access='r')

Register a string variable

Parameters:
  • name (str) – the name of the variable as how nodes can refer to it
  • value (str) – the variable value
  • access (str) – set the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
setup()

Called a startup.

Add variables you want to use througout the actor here. I.e.:

self.count = 0

and in the update() method:

self.count += 1
signal_subscribe(recv_peer, receiver, emit_peer, emitter)

Subscribe a receiver to an emitter

Parameters:
  • recv_peer (uuid) – the id of the receiving peer
  • receiver (str) – the name of the receiving variable. If None, no capability on the receiving peer is updated, but a on_peer_signal event is still fired.
  • emit_peer (uuid) – the id of the emitting peer
  • emitter (str) – the name the emitter. If None, all capabilities will emit to the receiver

Note

A third node can instruct two nodes to subscribe to one another by specifying the ids of the peers. The subscription request is then sent to the emitter node which in turn forwards the subscribtion request to the receiver node.

think()

The think methods makes the philospher actor think about something and determine the quality of it. If the quality is good it will return the thought. Otherwise it returns None

If the philospher is out of topics it will say so. He then needs to eat.

update()

Called every loop

LonePhilosopherActor class

class LonePhilosopherActor(*args, **kwargs)

Bases: sphof.philosopher_actors.Philosopher, sphof.actors.LoneActor

draw()

Called after update

eat()

The eat method makes the philosopher eat. This fills its list of topics for thinking (food for thought)

setup()

Called a startup.

Add variables you want to use througout the actor here. I.e.:

self.count = 0

and in the update() method:

self.count += 1
think()

The think methods makes the philospher actor think about something and determine the quality of it. If the quality is good it will return the thought. Otherwise it returns None

If the philospher is out of topics it will say so. He then needs to eat.

update()

Called every loop