hack args till they work, add ALLOW_CLOSE
the diagram is a lot simpler if the only way to shut things down is to terminate the whole process
This commit is contained in:
parent
d136028fa8
commit
b826e8c73c
|
@ -223,6 +223,7 @@ from automat import MethodicalMachine
|
||||||
|
|
||||||
class _ConnectionMachine(object):
|
class _ConnectionMachine(object):
|
||||||
m = MethodicalMachine()
|
m = MethodicalMachine()
|
||||||
|
ALLOW_CLOSE = True
|
||||||
|
|
||||||
def __init__(self, ws_url):
|
def __init__(self, ws_url):
|
||||||
self._f = f = WSFactory(ws_url)
|
self._f = f = WSFactory(ws_url)
|
||||||
|
@ -238,19 +239,20 @@ class _ConnectionMachine(object):
|
||||||
def first_time_connecting(self): pass
|
def first_time_connecting(self): pass
|
||||||
@m.state()
|
@m.state()
|
||||||
def negotiating(self): pass
|
def negotiating(self): pass
|
||||||
|
@m.state(terminal=True)
|
||||||
|
def failed(self): pass
|
||||||
@m.state()
|
@m.state()
|
||||||
def open(self): pass
|
def open(self): pass
|
||||||
@m.state()
|
@m.state()
|
||||||
def waiting(self): pass
|
def waiting(self): pass
|
||||||
@m.state()
|
@m.state()
|
||||||
def connecting(self): pass
|
def connecting(self): pass
|
||||||
|
if ALLOW_CLOSE:
|
||||||
@m.state()
|
@m.state()
|
||||||
def disconnecting(self): pass
|
def disconnecting(self): pass
|
||||||
@m.state()
|
@m.state()
|
||||||
def disconnecting2(self): pass
|
def disconnecting2(self): pass
|
||||||
@m.state(terminal=True)
|
@m.state(terminal=True)
|
||||||
def failed(self): pass
|
|
||||||
@m.state(terminal=True)
|
|
||||||
def closed(self): pass
|
def closed(self): pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,9 +267,10 @@ class _ConnectionMachine(object):
|
||||||
@m.input()
|
@m.input()
|
||||||
def onOpen(self, ws): pass
|
def onOpen(self, ws): pass
|
||||||
@m.input()
|
@m.input()
|
||||||
def onClose(self): pass
|
def onClose(self, f): pass
|
||||||
@m.input()
|
@m.input()
|
||||||
def expire(self): pass
|
def expire(self): pass
|
||||||
|
if ALLOW_CLOSE:
|
||||||
@m.input()
|
@m.input()
|
||||||
def close(self): pass
|
def close(self): pass
|
||||||
|
|
||||||
|
@ -280,7 +283,7 @@ class _ConnectionMachine(object):
|
||||||
def handle_connection(self, ws):
|
def handle_connection(self, ws):
|
||||||
pass
|
pass
|
||||||
@m.output()
|
@m.output()
|
||||||
def start_timer(self):
|
def start_timer(self, f):
|
||||||
pass
|
pass
|
||||||
@m.output()
|
@m.output()
|
||||||
def cancel_timer(self):
|
def cancel_timer(self):
|
||||||
|
@ -295,20 +298,25 @@ class _ConnectionMachine(object):
|
||||||
initial.upon(start, enter=first_time_connecting, outputs=[ep_connect])
|
initial.upon(start, enter=first_time_connecting, outputs=[ep_connect])
|
||||||
first_time_connecting.upon(d_callback, enter=negotiating, outputs=[])
|
first_time_connecting.upon(d_callback, enter=negotiating, outputs=[])
|
||||||
first_time_connecting.upon(d_errback, enter=failed, outputs=[notify_fail])
|
first_time_connecting.upon(d_errback, enter=failed, outputs=[notify_fail])
|
||||||
|
if ALLOW_CLOSE:
|
||||||
first_time_connecting.upon(close, enter=disconnecting2, outputs=[d_cancel])
|
first_time_connecting.upon(close, enter=disconnecting2, outputs=[d_cancel])
|
||||||
disconnecting2.upon(d_errback, enter=closed, outputs=[])
|
disconnecting2.upon(d_errback, enter=closed, outputs=[])
|
||||||
|
|
||||||
negotiating.upon(onOpen, enter=open, outputs=[handle_connection])
|
negotiating.upon(onOpen, enter=open, outputs=[handle_connection])
|
||||||
|
if ALLOW_CLOSE:
|
||||||
negotiating.upon(close, enter=disconnecting, outputs=[dropConnection])
|
negotiating.upon(close, enter=disconnecting, outputs=[dropConnection])
|
||||||
negotiating.upon(onClose, enter=failed, outputs=[notify_fail])
|
negotiating.upon(onClose, enter=failed, outputs=[notify_fail])
|
||||||
|
|
||||||
open.upon(onClose, enter=waiting, outputs=[start_timer])
|
open.upon(onClose, enter=waiting, outputs=[start_timer])
|
||||||
|
if ALLOW_CLOSE:
|
||||||
open.upon(close, enter=disconnecting, outputs=[dropConnection])
|
open.upon(close, enter=disconnecting, outputs=[dropConnection])
|
||||||
connecting.upon(d_callback, enter=negotiating, outputs=[])
|
connecting.upon(d_callback, enter=negotiating, outputs=[])
|
||||||
connecting.upon(d_errback, enter=waiting, outputs=[start_timer])
|
connecting.upon(d_errback, enter=waiting, outputs=[start_timer])
|
||||||
|
if ALLOW_CLOSE:
|
||||||
connecting.upon(close, enter=disconnecting2, outputs=[d_cancel])
|
connecting.upon(close, enter=disconnecting2, outputs=[d_cancel])
|
||||||
|
|
||||||
waiting.upon(expire, enter=connecting, outputs=[ep_connect])
|
waiting.upon(expire, enter=connecting, outputs=[ep_connect])
|
||||||
|
if ALLOW_CLOSE:
|
||||||
waiting.upon(close, enter=closed, outputs=[cancel_timer])
|
waiting.upon(close, enter=closed, outputs=[cancel_timer])
|
||||||
disconnecting.upon(onClose, enter=closed, outputs=[])
|
disconnecting.upon(onClose, enter=closed, outputs=[])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user