Commit 1a8707f2 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[refactor] Rename clients to applications

Giving the deadlines we have, it's probably a good idea to keep things
simple and keep the application facing protocol exactly as it is, and
restrict it to just applications. This way we can keep using the argobots
tests as valid benchmarks, and at the same start building a decent
communication protocol on a different socket, with a better interface.

To clarify that, the daemon now use the word application to refer to
clients connecting on the "legacy" interface.

We'll add a different socket and start building a real protocol in
future commits.
parent 7532b063
......@@ -7,17 +7,17 @@ import signal
import zmq
from zmq.eventloop import ioloop, zmqstream
client_fsm_table = {'stable': {'i': 's_ask_i', 'd': 's_ask_d'},
's_ask_i': {'done': 'stable', 'max': 'max'},
's_ask_d': {'done': 'stable', 'min': 'min'},
'max': {'d': 'max_ask_d'},
'min': {'i': 'min_ask_i'},
'max_ask_d': {'done': 'stable', 'min': 'nop'},
'min_ask_i': {'done': 'stable', 'max': 'nop'},
'nop': {}}
application_fsm_table = {'stable': {'i': 's_ask_i', 'd': 's_ask_d'},
's_ask_i': {'done': 'stable', 'max': 'max'},
's_ask_d': {'done': 'stable', 'min': 'min'},
'max': {'d': 'max_ask_d'},
'min': {'i': 'min_ask_i'},
'max_ask_d': {'done': 'stable', 'min': 'nop'},
'min_ask_i': {'done': 'stable', 'max': 'nop'},
'nop': {}}
class Client(object):
class Application(object):
def __init__(self, identity):
self.identity = identity
self.buf = ''
......@@ -27,14 +27,14 @@ class Client(object):
self.buf = self.buf + msg
def do_transition(self, msg):
transitions = client_fsm_table[self.state]
transitions = application_fsm_table[self.state]
if msg in transitions:
self.state = transitions[msg]
def get_allowed_requests(self):
return client_fsm_table[self.state].keys()
return application_fsm_table[self.state].keys()
def get_messages(self):
buf = self.buf
......@@ -67,33 +67,34 @@ class Client(object):
class Daemon(object):
def __init__(self):
self.clients = {}
self.applications = {}
self.buf = ''
self.logger = logging.getLogger(__name__)
self.current = 1 = 1
def do_client_receive(self, parts):"receiving client stream: " + repr(parts))
def do_application_receive(self, parts):"receiving application stream: " + repr(parts))
identity = parts[0]
if len(parts[1]) == 0:
# empty frame, indicate connect/disconnect
if identity in self.clients:
if identity in self.applications:"known client disconnected")
del self.clients[identity]
del self.applications[identity]
else:"new client: " + repr(identity))
self.clients[identity] = Client(identity)
self.applications[identity] = Application(identity)
if identity in self.clients:
client = self.clients[identity]
# we need to unpack the stream into client messages
if identity in self.applications:
application = self.applications[identity]
# we need to unpack the stream into application messages
# messages can be: min, max, done (%d), %d
for m in client.get_messages():
client.do_transition(m)"client now in state: " + client.state)
for m in application.get_messages():
application.do_transition(m)"application now in state: " +
def do_sensor(self):
self.current = random.randrange(0, 34)
......@@ -103,18 +104,18 @@ class Daemon(object): = random.randrange(0, 34)"target measure: " + str(
for identity, client in self.clients.iteritems():
for identity, application in self.applications.iteritems():
if self.current <
if 'i' in client.get_allowed_requests():
if 'i' in application.get_allowed_requests():[identity, 'i'])
elif self.current >
if 'd' in client.get_allowed_requests():
if 'd' in application.get_allowed_requests():[identity, 'd'])
pass"client now in state: " + client.state)"application now in state: " + application.state)
def do_signal(self, signum, frame):
......@@ -127,15 +128,14 @@ class Daemon(object):
bind_port = 1234
bind_address = '*'
# setup listening socket
# setup application listening socket
context = zmq.Context()
socket = context.socket(zmq.STREAM)
bind_param = "tcp://%s:%d" % (bind_address, bind_port)
socket.bind(bind_param)"socket bound to: " + bind_param) = zmqstream.ZMQStream(socket)
self.sensor = ioloop.PeriodicCallback(self.do_sensor, 1000)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment