initial work on new protocol

This commit is contained in:
Stephen Diehl
2012-04-25 19:52:14 -04:00
parent 1f04ee4ece
commit 0bf425a8dc
2 changed files with 17 additions and 21 deletions
+13 -4
View File
@@ -163,6 +163,7 @@ class Controller(object):
self.ctime = 0
self.tic = time.time()
self.freeform = False
self._state = -1
self.associated = []
@@ -218,17 +219,25 @@ class Controller(object):
self.topology = frozenset(topology)
default_states = [
CONTROL_STATES.INIT,
CONTROL_STATES.SOURCES_READY,
CONTROL_STATES.RUNNING,
CONTROL_STATES.SHUTDOWN,
CONTROL_STATES.TERMINATE,
]
self.states = states or default_states
self.polling = True
# Start off in RUNNING, state
self.state = self.states[0]
@property
def state(self):
return self._state
@state.setter
def state(self, new):
old, self._state = self._state, new
self.logging.info("[Controller] State Transition : %s -> %s" %(old, new))
def run(self):
self.init_zmq(self.zmq_flavor)
@@ -472,7 +481,7 @@ class Controller(object):
assert hard or soft, """ Must specify kill hard or soft """
if hard:
self.state = CONTROL_STATES.SHUTDOWN
self.state = CONTROL_STATES.TERMINATE
self.logging.info('[Controller] Hard Shutdown')
+4 -17
View File
@@ -126,9 +126,6 @@ from collections import namedtuple
from protocol_utils import Enum, FrameExceptionFactory, namedict
from date_utils import EPOCH, UN_EPOCH
#import ujson
#import ultrajson_numpy
# -----------------------
# Control Protocol
# -----------------------
@@ -136,9 +133,10 @@ from date_utils import EPOCH, UN_EPOCH
INVALID_CONTROL_FRAME = FrameExceptionFactory('CONTROL')
CONTROL_STATES = Enum(
'INIT',
'SOURCES_READY',
'RUNNING',
'SHUTDOWN', # a soft kill
'TERMINATE', # a hard kill
'TERMINATE',
)
CONTROL_PROTOCOL = Enum(
@@ -149,6 +147,7 @@ CONTROL_PROTOCOL = Enum(
'OK' , # 3 - rep
'DONE' , # 4 - rep
'EXCEPTION' , # 5 - rep
'SIGNAL' , # 6 - rep
)
def CONTROL_FRAME(event, payload):
@@ -174,18 +173,6 @@ def CONTROL_UNFRAME(msg):
except ValueError:
raise INVALID_CONTROL_FRAME(msg)
# -----------------------
# Heartbeat Protocol
# -----------------------
# These encode the msgpack equivelant of 1 and 2. The heartbeat
# frame should only be 1 byte on the wire.
HEARTBEAT_PROTOCOL = namedict({
'REQ' : b'\x01',
'REP' : b'\x02',
})
# -----------------------
# Component State
# -----------------------