コード例 #1
0
ファイル: dbm.py プロジェクト: LucaLanziani/coilmq
def make_dbm():
    """
    Creates a DBM queue store, pulling config values from the CoilMQ configuration.
    """
    try:
        data_dir = config.get('coilmq', 'qstore.dbm.data_dir')
        cp_ops = config.getint('coilmq', 'qstore.dbm.checkpoint_operations')
        cp_timeout = config.getint('coilmq', 'qstore.dbm.checkpoint_timeout')
    except ConfigParser.NoOptionError, e:
        raise ConfigError('Missing configuration parameter: %s' % e)
コード例 #2
0
def make_dbm():
    """
    Creates a DBM queue store, pulling config values from the CoilMQ configuration.
    """
    try:
        data_dir = config.get('coilmq', 'qstore.dbm.data_dir')
        cp_ops = config.getint('coilmq', 'qstore.dbm.checkpoint_operations')
        cp_timeout = config.getint('coilmq', 'qstore.dbm.checkpoint_timeout')
    except ConfigParser.NoOptionError, e:
        raise ConfigError('Missing configuration parameter: %s' % e)
コード例 #3
0
ファイル: simple.py プロジェクト: Liujinan001/ambari-2.7.5
def make_simple():
    """
    Create a L{SimpleAuthenticator} instance using values read from coilmq configuration.

    @return: The configured L{SimpleAuthenticator}
    @rtype: L{SimpleAuthenticator}
    @raise ConfigError: If there is a configuration error.
    """
    authfile = config.get('coilmq', 'auth.simple.file')
    if not authfile:
        raise ConfigError('Missing configuration parameter: auth.simple.file')
    sa = SimpleAuthenticator()
    sa.from_configfile(authfile)
    return sa
コード例 #4
0
ファイル: simple.py プロジェクト: hozn/coilmq
def make_simple():
    """
    Create a L{SimpleAuthenticator} instance using values read from coilmq configuration.

    @return: The configured L{SimpleAuthenticator}
    @rtype: L{SimpleAuthenticator}
    @raise ConfigError: If there is a configuration error.
    """
    authfile = config.get('coilmq', 'auth.simple.file')
    if not authfile:
        raise ConfigError('Missing configuration parameter: auth.simple.file')
    sa = SimpleAuthenticator()
    sa.from_configfile(authfile)
    return sa
コード例 #5
0
ファイル: dbm.py プロジェクト: hozn/coilmq
def make_dbm():
    """
    Creates a DBM queue store, pulling config values from the CoilMQ configuration.
    """
    try:
        data_dir = config.get('coilmq', 'qstore.dbm.data_dir')
        cp_ops = config.getint('coilmq', 'qstore.dbm.checkpoint_operations')
        cp_timeout = config.getint('coilmq', 'qstore.dbm.checkpoint_timeout')
    except ConfigParser.NoOptionError as e:
        raise ConfigError('Missing configuration parameter: %s' % e)

    if not os.path.exists(data_dir):
        raise ConfigError('DBM directory does not exist: %s' % data_dir)
    # FIXME: how do these get applied? Is OR appropriate?
    if not os.access(data_dir, os.W_OK | os.R_OK):
        raise ConfigError('Cannot read and write DBM directory: %s' % data_dir)

    store = DbmQueue(data_dir, checkpoint_operations=cp_ops,
                     checkpoint_timeout=cp_timeout)
    return store
コード例 #6
0
def make_dbm():
    """
    Creates a DBM queue store, pulling config values from the CoilMQ configuration.
    """
    try:
        data_dir = config.get('coilmq', 'qstore.dbm.data_dir')
        cp_ops = config.getint('coilmq', 'qstore.dbm.checkpoint_operations')
        cp_timeout = config.getint('coilmq', 'qstore.dbm.checkpoint_timeout')
    except ConfigParser.NoOptionError as e:
        raise ConfigError('Missing configuration parameter: %s' % e)

    if not os.path.exists(data_dir):
        raise ConfigError('DBM directory does not exist: %s' % data_dir)
    # FIXME: how do these get applied? Is OR appropriate?
    if not os.access(data_dir, os.W_OK | os.R_OK):
        raise ConfigError('Cannot read and write DBM directory: %s' % data_dir)

    store = DbmQueue(data_dir,
                     checkpoint_operations=cp_ops,
                     checkpoint_timeout=cp_timeout)
    return store
コード例 #7
0
ファイル: start.py プロジェクト: hozn/coilmq
def context_serve(context, configfile, listen_addr, listen_port, logfile,
                  debug, daemon, uid, gid, pidfile, umask, rundir):
    """
    Takes a context object, which implements the __enter__/__exit__ "with" interface 
    and starts a server within that context.

    This method is a refactored single-place for handling the server-run code whether
    running in daemon or non-daemon mode.  It is invoked with a dummy (passthrough) 
    context object for the non-daemon use case. 

    @param options: The compiled collection of options that need to be parsed. 
    @type options: C{ConfigParser}

    @param context: The context object that implements __enter__/__exit__ "with" methods.
    @type context: C{object}

    @raise Exception: Any underlying exception will be logged but then re-raised.
    @see: server_from_config()
    """
    global global_config

    server = None
    try:
        with context:
            # There's a possibility here that init_logging() will throw an exception.  If it does,
            # AND we're in a daemon context, then we're not going to be able to do anything with it.
            # We've got no stderr/stdout here; and so (to my knowledge) no reliable (& cross-platform),
            # way to display errors.
            level = logging.DEBUG if debug else logging.INFO
            init_logging(logfile=logfile, loglevel=level,
                         configfile=configfile)

            server = server_from_config()
            logger.info("Stomp server listening on %s:%s" % server.server_address)

            if debug:
                poll_interval = float(global_config.get(
                        'coilmq', 'debug.stats_poll_interval'))
                if poll_interval:  # Setting poll_interval to 0 effectively disables it.
                    def diagnostic_loop(server):
                        log = logger
                        while True:
                            log.debug(
                                    "Stats heartbeat -------------------------------")
                            store = server.queue_manager.store
                            for dest in store.destinations():
                                log.debug("Queue %s: size=%s, subscribers=%s" % (
                                    dest, store.size(dest), server.queue_manager.subscriber_count(dest)))

                            # TODO: Add number of subscribers?

                            time.sleep(poll_interval)

                    diagnostic_thread = threading.Thread(
                            target=diagnostic_loop, name='DiagnosticThread', args=(server,))
                    diagnostic_thread.daemon = True
                    diagnostic_thread.start()

            server.serve_forever()

    except (KeyboardInterrupt, SystemExit):
        logger.info("Stomp server stopped by user interrupt.")
        raise SystemExit()
    except Exception as e:
        logger.error("Stomp server stopped due to error: %s" % e)
        logger.exception(e)
        raise SystemExit()
    finally:
        if server:
            server.server_close()
コード例 #8
0
def context_serve(options, context):
    """
    Takes a context object, which implements the __enter__/__exit__ "with" interface 
    and starts a server within that context.
    
    This method is a refactored single-place for handling the server-run code whether
    running in daemon or non-daemon mode.  It is invoked with a dummy (passthrough) 
    context object for the non-daemon use case. 
    
    @param options: The compiled collection of options that need to be parsed. 
    @type options: C{ConfigParser}
    
    @param context: The context object that implements __enter__/__exit__ "with" methods.
    @type context: C{object}
    
    @raise Exception: Any underlying exception will be logged but then re-raised.
    @see: server_from_config()
    """
    global global_config

    server = None
    try:
        with context:
            # There's a possibility here that init_logging() will throw an exception.  If it does,
            # AND we're in a daemon context, then we're not going to be able to do anything with it.
            # We've got no stderr/stdout here; and so (to my knowledge) no reliable (& cross-platform),
            # way to display errors.
            level = logging.DEBUG if options.debug else logging.INFO
            init_logging(logfile=options.logfile,
                         loglevel=level,
                         configfile=options.configfile)

            server = server_from_config()
            logger().info("Stomp server listening on %s:%s" %
                          server.server_address)

            if options.debug:
                poll_interval = float(
                    global_config.get('coilmq', 'debug.stats_poll_interval'))
                if poll_interval:  # Setting poll_interval to 0 effectively disables it.

                    def diagnostic_loop(server):
                        log = logger()
                        while True:
                            log.debug(
                                "Stats heartbeat -------------------------------"
                            )
                            store = server.queue_manager.store
                            for dest in store.destinations():
                                log.debug(
                                    "Queue %s: size=%s, subscribers=%s" %
                                    (dest, store.size(dest),
                                     server.queue_manager.subscriber_count(
                                         dest)))

                            # TODO: Add number of subscribers?

                            time.sleep(poll_interval)

                    diagnostic_thread = threading.Thread(
                        target=diagnostic_loop,
                        name='DiagnosticThread',
                        args=(server, ))
                    diagnostic_thread.daemon = True
                    diagnostic_thread.start()

            server.serve_forever()

    except (KeyboardInterrupt, SystemExit):
        logger().info("Stomp server stopped by user interrupt.")
        raise SystemExit()
    except Exception, e:
        logger().error("Stomp server stopped due to error: %s" % e)
        logger().exception(e)
        raise SystemExit()