예제 #1
0
파일: managers.py 프로젝트: maduhu/HDP-hue
    def __init__(self, registry, address, authkey):
        assert type(authkey) is str
        self.registry = registry
        self.authkey = authkey

        # do authentication later
        self.listener = Listener(address=address, backlog=5)

        self.address = self.listener.address
        if type(self.address) is tuple:
            self.address = (socket.getfqdn(self.address[0]), self.address[1])

        self.id_to_obj = {0: (None, ())}
        self.id_to_refcount = {}
        self.mutex = threading.RLock()
        self.stop = 0
예제 #2
0
파일: managers.py 프로젝트: ConduitTeam/hue
    def __init__(self, registry, address, authkey):
        assert type(authkey) is str
        self.registry = registry
        self.authkey = authkey

        # do authentication later
        self.listener = Listener(address=address, backlog=5)

        self.address = self.listener.address
        if type(self.address) is tuple:
            self.address = (socket.getfqdn(self.address[0]), self.address[1])

        self.id_to_obj = {0: (None, ())}
        self.id_to_refcount = {}
        self.mutex = threading.RLock()
        self.stop = 0
예제 #3
0
def _getListener():
    global _listener

    if _listener is None:
        _lock.acquire()
        try:
            if _listener is None:
                from processing.connection import Listener
                debug('starting listener and thread for sending handles')
                _listener = Listener(authenticate=True)
                t = threading.Thread(target=_serve)
                t.setDaemon(True)
                t.start()
        finally:
            _lock.release()

    return _listener
예제 #4
0
파일: managers.py 프로젝트: maduhu/HDP-hue
class Server(object):
    '''
    Server class which runs in a process controlled by a manager object
    '''
    public = [
        'shutdown', 'create', 'acceptConnection', 'getMethods', 'debugInfo',
        'dummy', 'incref', 'decref'
    ]

    def __init__(self, registry, address, authkey):
        assert type(authkey) is str
        self.registry = registry
        self.authkey = authkey

        # do authentication later
        self.listener = Listener(address=address, backlog=5)

        self.address = self.listener.address
        if type(self.address) is tuple:
            self.address = (socket.getfqdn(self.address[0]), self.address[1])

        self.id_to_obj = {0: (None, ())}
        self.id_to_refcount = {}
        self.mutex = threading.RLock()
        self.stop = 0

    def serveForever(self):
        '''
        Run the server forever
        '''
        try:
            try:
                while 1:
                    c = self.listener.accept()
                    t = threading.Thread(target=self.handleRequest, args=(c, ))
                    t.setDaemon(True)
                    t.start()
            except (KeyboardInterrupt, SystemExit):
                return
        finally:
            self.stop = 999
            self.listener.close()

    def handleRequest(self, c):
        '''
        Handle a new connection
        '''
        funcname = result = request = None
        try:
            deliverChallenge(c, self.authkey)
            answerChallenge(c, self.authkey)
            request = c.recv()
            ignore, funcname, args, kwds = request
            assert funcname in self.public, '%r unrecognized' % funcname
            func = getattr(self, funcname)
        except (SystemExit, KeyboardInterrupt):
            raise
        except Exception:
            msg = ('#ERROR', RemoteError())
        else:
            try:
                result = func(c, *args, **kwds)
                msg = ('#RETURN', result)
            except (SystemExit, KeyboardInterrupt):
                raise
            except Exception:
                msg = ('#ERROR', RemoteError())

        try:
            c.send(msg)
        except (SystemExit, KeyboardInterrupt):
            raise
        except Exception, e:
            if msg[0] == '#ERROR':
                subWarning('Failure to send exception: %r', msg[1])
            else:
                subWarning('Failure to send result: %r', msg[1])
            subWarning(' ... request was %r', request)
            subWarning(' ... exception was %r', e)

        c.close()
예제 #5
0
파일: managers.py 프로젝트: ConduitTeam/hue
class Server(object):
    '''
    Server class which runs in a process controlled by a manager object
    '''
    public = ['shutdown', 'create', 'acceptConnection',
              'getMethods', 'debugInfo', 'dummy', 'incref', 'decref']

    def __init__(self, registry, address, authkey):
        assert type(authkey) is str
        self.registry = registry
        self.authkey = authkey

        # do authentication later
        self.listener = Listener(address=address, backlog=5)

        self.address = self.listener.address
        if type(self.address) is tuple:
            self.address = (socket.getfqdn(self.address[0]), self.address[1])

        self.id_to_obj = {0: (None, ())}
        self.id_to_refcount = {}
        self.mutex = threading.RLock()
        self.stop = 0

    def serveForever(self):
        '''
        Run the server forever
        '''
        try:
            try:
                while 1:
                    c = self.listener.accept()
                    t = threading.Thread(target=self.handleRequest, args=(c,))
                    t.setDaemon(True)
                    t.start()
            except (KeyboardInterrupt, SystemExit):
                return
        finally:
            self.stop = 999
            self.listener.close()

    def handleRequest(self, c):
        '''
        Handle a new connection
        '''
        funcname = result = request = None
        try:
            deliverChallenge(c, self.authkey)
            answerChallenge(c, self.authkey)
            request = c.recv()
            ignore, funcname, args, kwds = request
            assert funcname in self.public, '%r unrecognized' % funcname
            func = getattr(self, funcname)
        except (SystemExit, KeyboardInterrupt):
            raise
        except Exception:
            msg = ('#ERROR', RemoteError())
        else:
            try:
                result = func(c, *args, **kwds)
                msg = ('#RETURN', result)
            except (SystemExit, KeyboardInterrupt):
                raise
            except Exception:
                msg = ('#ERROR', RemoteError())

        try:
            c.send(msg)
        except (SystemExit, KeyboardInterrupt):
            raise
        except Exception, e:
            if msg[0] == '#ERROR':
                subWarning('Failure to send exception: %r', msg[1])
            else:
                subWarning('Failure to send result: %r', msg[1])
            subWarning(' ... request was %r', request)
            subWarning(' ... exception was %r', e)

        c.close()