def _run(self): while True: try: id, name, args = self._conn.recv_frame().wait() except rtjp.errors.ConnectionLost: print "Connection Lost" self._implementation._connection_lost() break print 'read', id, name, args if name == 'REQUEST': try: method_name, constructed_args = core.parse_request(self._protocol, self._direction, args) except core.PijoInvocationError, e: print 'ivocation error?', e self._error_response(id, str(e)) continue eventlet.spawn(self._dispatch_request, id, method_name, constructed_args) continue if name == 'RESPONSE': request_id = args.get('requestId', None) if request_id not in self._requests: # Invalid response... error? continue response = self._requests[request_id] result = args.get('result', {}) partial = args.get('partial', False) success = args.get('success', False) complete = args.get('complete', False) # TODO: figure out request/multi-response if not partial: del self._requests[request_id] response._received_response(success, result, partial, complete) continue
def connect(impl_class, port, hostname, protocol=None): ev = eventlet.event.Event() if not protocol: pijo_file = pijo.compiler.parse(impl_class.__source_file__) protocol = pijo_file.protocols[impl_class.__protocol_name__] eventlet.spawn(_connect, ev, impl_class, protocol, port, hostname) return ev
def serve(server, port=None, interface='', protocol=None, sock=None): ev = eventlet.event.Event() if not protocol: pijo_file = compiler.parse(server.__protocol__.__source_file__) protocol = pijo_file.protocols[server.__protocol__.__protocol_name__] def impl_class(conn): p = server.create_protocol(conn) p.server = server return p eventlet.spawn(_serve, ev, impl_class, protocol, port, interface, sock) return ev
def read_response(self): # if not self._active: # raise Exception("Response already completed") ev = eventlet.event.Event() eventlet.spawn(self._read_response, ev) return ev
def _make_connection(self, conn): self._conn = conn self._implementation._connection_made() eventlet.spawn(self._run)
def _event(self, name, args): ev = eventlet.event.wait() eventlet.spawn(self._event, ev, name, args) return ev
def _request(self, response, name, args): ev = eventlet.event.Event() eventlet.spawn(self.__request, ev, response, name, args) return ev