Esempio n. 1
0
 def broadcast(self, message, exceptions=None):
     SocketIOProtocol.broadcast(self, message, exceptions)
     # XXX this is were we want to broadcast to other servers
     # via ZMQ
     # XXX TODO : be able to pass exceptions (which should be augmented with
     # all local sesssion ids)
     logger.debug('broadcasting socketio')
 def broadcast(self, message, exceptions=None):
     SocketIOProtocol.broadcast(self, message, exceptions)
     # XXX this is were we want to broadcast to other servers
     # via ZMQ
     # XXX TODO : be able to pass exceptions (which should be augmented with
     # all local sesssion ids)
     logger.debug('broadcasting socketio')
Esempio n. 3
0
 def send(self, message, destination=None):
     SocketIOProtocol.send(self, message, destination)
     # XXX this is were we want to broadcast to other servers if destination
     # is located somewhere else
     # via ZMQ
     if destination is not None:
         logger.debug('sending socketio to %s' % destination)
 def send(self, message, destination=None):
     SocketIOProtocol.send(self, message, destination)
     # XXX this is were we want to broadcast to other servers if destination
     # is located somewhere else
     # via ZMQ
     if destination is not None:
         logger.debug('sending socketio to %s' % destination)
Esempio n. 5
0
class RedBarrelWSGIWorker(TcpSyncWorker):
    def on_init(self, conf):
        super(RedBarrelWSGIWorker, self).on_init(conf)
        self.conf = conf
        self.worker_connections = conf.get('worker_connections')

    def on_init_process(self):
        if 'sock' not in self.conf:
            return
        super(RedBarrelWSGIWorker, self).on_init_process()

    def _on_socket_error(self, err):
        raise err

    def run(self):
        if 'sock' in self.conf:
            self.socket.setblocking(1)

            # loading the wsgi app    / XXX in which worker ?
            from redbarrel.wsgiapp import WebApp
            self.application = WebApp(self.conf['path'], worker=self)

        # creating and starting the server
        server = self._get_server()
        try:
            server.start()
            running = True
        except socket.error, err:
            self._on_socket_error(err)
            running = False

        self._after_start()
        try:
            while self.alive:
                self.notify()
                if self.ppid != os.getppid():
                    logger.debug("Parent changed, shutting down: %s", self)
                    break
                gevent.sleep(1.0)
        except KeyboardInterrupt:
            pass

        # try to stop the connections
        try:
            self.notify()
            if running:
                server.stop(timeout=self.timeout)
                self._after_stop()
        except Exception, err:
            logger.error(str(err))
Esempio n. 6
0
    def recv(self):
        logger.debug('Wait for incoming messages')

        msg = self.session.get_server_msg()

        logger.debug(str(self.session))
        if msg is None:
            return []
        else:
            logger.debug('Received %s' % msg)

            return msg
    def recv(self):
        logger.debug('Wait for incoming messages')

        msg = self.session.get_server_msg()

        logger.debug(str(self.session))
        if msg is None:
            return []
        else:
            logger.debug('Received %s' % msg)

            return msg
Esempio n. 8
0
 def queue_exists(queue_id, server='localhost'):
     r = redis.Redis(server)
     logger.debug("checking if %s exists in redis" % queue_id)
     return r.sismember('redbarrelqueues', queue_id)
Esempio n. 9
0
    def get_session(self, session_id=''):
        """Return an existing or new client Session."""
        logger.debug("LOOKING FOR SESSION %s" % session_id)
        exists = self.sessions.session_exists(session_id)
        if exists:
            logger.debug('session exists')
        else:
            logger.debug('session does not exist')
            logger.debug('existing sessions are %s' \
                    % self.sessions.get_session_ids())

        session = self.sessions.get(session_id)

        if session is None:
            logger.debug("session doesn't exist locally")
            session = self.sessions.add_session(self)
            logger.debug("Thread %s - created session %s" % (get_ident(),
                                                      str(session)))
            if exists:
                session.incr_hits()
        else:
            logger.debug("Thread %s - reusing same session %s" % (get_ident(),
                                                           str(session)))
            session.incr_hits()

        return session
 def heartbeat(self):
     logger.debug('heartbeat %s incremented' % self._heartbeat.name)
     return self._heartbeat.incr()
Esempio n. 11
0
 def queue_exists(queue_id, server='localhost'):
     r = redis.Redis(server)
     logger.debug("checking if %s exists in redis" % queue_id)
     return r.sismember('redbarrelqueues', queue_id)
    def get_session(self, session_id=''):
        """Return an existing or new client Session."""
        logger.debug("LOOKING FOR SESSION %s" % session_id)
        exists = self.sessions.session_exists(session_id)
        if exists:
            logger.debug('session exists')
        else:
            logger.debug('session does not exist')
            logger.debug('existing sessions are %s' \
                    % self.sessions.get_session_ids())

        session = self.sessions.get(session_id)

        if session is None:
            logger.debug("session doesn't exist locally")
            session = self.sessions.add_session(self)
            logger.debug("Thread %s - created session %s" %
                         (get_ident(), str(session)))
            if exists:
                session.incr_hits()
        else:
            logger.debug("Thread %s - reusing same session %s" %
                         (get_ident(), str(session)))
            session.incr_hits()

        return session
Esempio n. 13
0
 def delete(self):
     logger.debug('removing %s from redis' % self.id_name)
     self.redis.srem('redbarrelqueues', self.id_name)
     self.redis.delete(self.id_name)
Esempio n. 14
0
 def __init__(self, session_id, server='localhost'):
     self.redis = redis.Redis(server)
     self.id_name = session_id
     logger.debug("register %s in the list of queues" % session_id)
     self.redis.sadd('redbarrelqueues', session_id)
Esempio n. 15
0
 def __init__(self, session_id, server='localhost'):
     self.redis = redis.Redis(server)
     self.id_name = session_id
     logger.debug("register %s in the list of queues" % session_id)
     self.redis.sadd('redbarrelqueues', session_id)
Esempio n. 16
0
 def delete(self):
     logger.debug('removing %s from redis' % self.id_name)
     self.redis.srem('redbarrelqueues', self.id_name)
     self.redis.delete(self.id_name)
 def incr_hits(self):
     logger.debug('hit %s incremented' % self._hits.name)
     self._hits.incr()