def __init__(self, port): url = 'http://localhost:' + port self.ready = False self.deferred = None self.queue = [] #self.client = RPCClient(url) self.client = Client(url)
class EngineClient(object): """Client is initialized with host and port of engine server. The initial connection of the client should be made when the engine manager knows the engine process started. The initial connection could be: - instantiate interpreter (import namespace) """ def __init__(self, port): url = 'http://localhost:' + port self.ready = False self.deferred = None self.queue = [] #self.client = RPCClient(url) self.client = Client(url) def __call__(self, method, *args): return self.client.callRemote(method, *args) def initialize(self): return self.client.callRemote('interpreter_go').addCallbacks( self._engine_ready, self._engine_notready, None, None, None, None) def _engine_ready(self, result): self.ready = True return self.check_queue() def _engine_notready(self, reason): self.ready = False def call(self, method, *args): """try remote call if fail - queue for next good state """ d = defer.Deferred() self.client.callRemote(method, *args).addCallbacks( self._callRemoteSucess, self._callRemoteErr, (d,), None, (d, method, args), None) return d def _callRemoteSucess(self, result, d): d.callback(result) def _callRemoteErr(self, reason, d, method, *args): self.ready = False self.queue.append((method, args)) def check_queue(self): """eval requests that can't go because of a bad connection get saved in the queue. If the queue is checked, then the connection should be ready """ if self.queue: pass