def __init__(self, communicator, name, params, client_request_class=None): Listener.__init__(self, communicator, name, params, client_request_class=client_request_class) if not params.has_key('service_name'): params['service_name'] = self.get_name() host = params.get('host') port = int(params.get('port')) protocol = params.get('protocol') if protocol is None: protocol = 'tcp' ice_url = "%s -h %s -p %d" % (protocol, host, port) properties = Ice.createProperties() for property_name, property_value in params.iteritems(): #Passing configs to Ice as properties. Ice will pick its #own configs and ignore others. properties.setProperty(property_name, property_value) data = Ice.InitializationData() data.properties = properties self._proxy = Ice.initialize(sys.argv, data) self._adapter = self._proxy.createObjectAdapterWithEndpoints( get_app().get_name(), ice_url) self.add_service(IceJsonDispatcher(self), name=params['service_name'])
def __init__(self, communicator, name, params): Listener.__init__(self, communicator, name, params) self._auth_key = get_uuid() self._manager = BaseManager(address=(self.host, self.port), authkey=self._auth_key) self._server = self._manager.get_server() self._dispatcher = PympDispatcher(self) self._manager.register('dispatcher', callable=lambda: self._dispatcher)
def execute_ex(self, request, **options): ''' Executes the command by the given command key. @param request: client request @return: Response ''' try: start = time.time() result = Listener.execute_ex(self, request, **options) end = time.time() time_span = end - start PyroListener.communicator_logger.info( "Pyro [{0}] executed [{1}]".format(result['request_id'], time_span)) return result except DeltaException, error: message = str(error) ex = Exception(message) ex.code = error.get_code() ex.data = error.get_data() ex.traceback = error.get_traceback() if ex.traceback is None: ex.traceback = traceback.format_exc() PyroListener.logger.exception(ex) self._exception_manager.raise_exception(ex)
def execute(self, ip_address, ticket, user_name, command_key, *args, **kargs): ''' Executes the command by the given command key. @param ip_address: client IP address @param ticket: security ticket @param user_name: user name @param command_key: command key ''' try: result = Listener.execute(self, ip_address, ticket, user_name, command_key, *args, **kargs) return result except DeltaException, error: message = str(error) ex = Exception(message) ex.code = error.get_code() ex.data = error.get_data() ex.traceback = error.get_traceback() if ex.traceback is None: ex.traceback = traceback.format_exc() PyroListener.logger.exception(ex) self._exception_manager.raise_exception(ex)
def __init__(self, communicator, name, params, client_request_class=None): Listener.__init__(self, communicator, name, params, client_request_class=client_request_class) if not params.has_key('service_name'): params['service_name'] = self.get_name() Pyro.config.PYRO_MULTITHREADED = 1 Pyro.core.initServer() self._daemon = Pyro.core.Daemon(host=self.host, port=self.port) #self.__daemon.setNewConnectionValidator(ConnectionValidator()) self.add_service(PyroDispatcher(self), name=params['service_name']) self._exception_manager = PyroExceptionManager()
def __init__(self, communicator, name, params, client_request_class=None): Listener.__init__(self, communicator, name, params, client_request_class=client_request_class) if not params.has_key('service_name'): params['service_name'] = self.get_name() host = params.get('host') port = int(params.get('port')) self._server = DocXMLRPCServer(addr=(host, port), allow_none=1, logRequests=0) self.add_service(XmlrpcDispatcher(self), name=params['service_name'])
def login(self, ip, user_name, password, **options): ''' Logins in application. @param ip: client IP address @param user_name: user name @param password: user password ''' return Listener.login(self, ip, user_name, password, **options)
def login_ex(self, ip, user_name, password, **options): ''' Logins in application. @param ip: client IP address @param user_name: user name @param password: user password ''' try: return Listener.login_ex(self,ip, user_name, password, **options) except Exception, error: return make_error_result(self.get_type_convertor(), error)
def __init__(self, communicator, name, params, client_request_class=None): ''' ''' Listener.__init__(self, communicator, name, params, client_request_class=client_request_class) # Configuring Zmq workers_count = params.get('workers') if workers_count is not None: workers_count = int(workers_count) else: workers_count = 16 if not params.has_key('service_name'): params['service_name'] = self.get_name() router_url = 'tcp://{0}:{1}'.format(params.get('host'), params.get('port')) dealer_url = 'inproc://workers' # Creating zmq context io_threads = multiprocessing.cpu_count() - 1 if io_threads < 2: io_threads = 2; self._context = zmq.Context(io_threads) # Creating router socket self._router = self._context.socket(zmq.ROUTER) self._router.setsockopt(zmq.LINGER, 0) self._router.bind(router_url) # Creating dealer socket self._dealer = self._context.socket(zmq.DEALER) self._dealer.setsockopt(zmq.LINGER, 0) self._dealer.bind(dealer_url) self._dispatchers = [] for index in xrange(workers_count): dispatcher = ZmqDispatcher(self, self._context, dealer_url) self._dispatchers.append(dispatcher)
def __init__(self, communicator, name, params, client_request_class=None): Listener.__init__(self, communicator, name, params, client_request_class=client_request_class) if 'service_name' not in params: params['service_name'] = self.get_name() host = params.get('host') port = int(params.get('port')) self._handler = ThriftDispatcher(self) self._processor = Processor(self._handler) self._transport = TSocket.TServerSocket(host=host, port=port) self._transport_factory = TTransport.TBufferedTransportFactory() self._protocol_factory = TBinaryProtocol.TBinaryProtocolFactory() self._server = TServer.TThreadedServer(self._processor, self._transport, self._transport_factory, self._protocol_factory)
def login(self, ip, user_name, password, **options): ''' Logins in application. @param ip: client IP address @param user_name: user name @param password: user password ''' try: return Listener.login(self, ip, user_name, password, **options) except DeltaException, error: # As login method calls login_ex method of the communicator, the raised # exception is already formatted when it reaches this method; hence, no # reformatting is needed. raise error
def execute_ex(self, request, **options): ''' Executes the command by the given command key. @param request: client request @return: Response ''' try: result = Listener.execute_ex(self, request, **options) return result except Exception, error: return make_error_result(self.get_type_convertor(), error)
def login_ex(self, ip, user_name, password, **options): ''' Logins in application. @param ip: client IP address @param user_name: user name @param password: user password ''' try: start = time.time() login_result = \ Listener.login_ex(self, ip, user_name, password, **options) end = time.time() time_span = end - start PyroListener.communicator_logger.info( "Pyro [{0}] login [{1}]".format(login_result["ticket"], time_span)) return login_result except DeltaException, error: self._exception_manager.raise_exception(error)