summaryrefslogtreecommitdiff
path: root/distbuild
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-06-11 15:33:40 (GMT)
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-06-11 15:33:40 (GMT)
commit3fa8e6fe62b897b90b8a6c3ab518ef702eeda47e (patch)
tree616e26f86cde1436407a5476ed218fc27fe9df2b /distbuild
parent33bef5a71770b25fe22053267551a10c95c71f7b (diff)
downloadmorph-3fa8e6fe62b897b90b8a6c3ab518ef702eeda47e.tar.gz
Add InitiatorConnectionMachine
The InitiatorConnectionMachine wraps the ConnectionMachine, so we can continue to use ConnectionMachine without providing it with an app.
Diffstat (limited to 'distbuild')
-rw-r--r--distbuild/connection_machine.py41
1 files changed, 36 insertions, 5 deletions
diff --git a/distbuild/connection_machine.py b/distbuild/connection_machine.py
index cce83a4..0faa763 100644
--- a/distbuild/connection_machine.py
+++ b/distbuild/connection_machine.py
@@ -30,12 +30,13 @@ class Reconnect(object):
class StopConnecting(object):
- pass
-
+ def __init__(self, exception=None):
+ self.exception = exception
class ConnectError(object):
- pass
+ def __init__(self, exception):
+ self.exception = exception
class ProxyEventSource(object):
@@ -123,9 +124,9 @@ class ConnectionMachine(distbuild.StateMachine):
(self._addr, self._port, str(e)))
if self._numof_retries < self._max_retries:
- self.mainloop.queue_event(self, ConnectError())
+ self.mainloop.queue_event(self, ConnectError(e))
else:
- self.mainloop.queue_event(self, StopConnecting())
+ self.mainloop.queue_event(self, StopConnecting(e))
return
self._sock_proxy.event_source = None
@@ -156,3 +157,33 @@ class ConnectionMachine(distbuild.StateMachine):
self._sock_proxy.event_source.close()
self._sock_proxy.event_source = None
+
+class InitiatorConnectionMachine(ConnectionMachine):
+
+ def __init__(self, app, addr, port, machine, extra_args,
+ reconnect_interval, max_retries):
+
+ self.cm = super(InitiatorConnectionMachine, self)
+ self.cm.__init__(addr, port, machine, extra_args,
+ reconnect_interval, max_retries)
+
+ self.app = app
+
+ def _connect(self, event_source, event):
+ self.app.status(msg='Connecting to %s:%s' % (self._addr, self._port))
+ self.cm._connect(event_source, event)
+
+ def _stop(self, event_source, event):
+ if event.exception:
+ self.app.status(msg="Couldn't connect to %s:%s: %s" %
+ (self._addr, self._port, event.exception.strerror))
+
+ self.cm._stop(event_source, event)
+
+ def _start_timer(self, event_source, event):
+ self.app.status(msg="Couldn't connect to %s:%s: %s" %
+ (self._addr, self._port, event.exception.strerror))
+ self.app.status(msg="Retrying in %d seconds" %
+ self._reconnect_interval)
+
+ self.cm._start_timer(event_source, event)