コード例 #1
0
def create_publisher():
    global publisher
    import stomputil
    server, port = config.MSG_SERVER.split(':')
    port = int(port)
    #MSGUtil.SERVER, MSGUtil.PORT = server, int(port)
    log.debug('Creating publisher...')
    publisher = stomputil.createPublisher(diane.BaseThread.BaseThread, server, port, config.MSG_USERNAME, config.MSG_PASSWORD, logger=log)
    publisher.start()
    publisher.addExitHandler(config.MSG_EXIT_TIMEOUT)
コード例 #2
0
ファイル: MSGUtil.py プロジェクト: chrisburr/ganga
def createPublisher(server, port, user='******', password='******', idle_timeout=IDLE_TIMEOUT, exit_timeout=EXIT_TIMEOUT):
    """Create a new publisher thread which extends GangaThread where available
    (i.e. on the client) or Thread otherwise (i.e. on the worker node).

    N.B. If GangaThread is not available then an exit handler is added, with the
    given timeout.

    @param server: The server host name.
    @param user: The user name.
    @param password: The password.
    @param logger: The logger instance.
    @param idle_timeout: Maximum seconds to idle before closing connection.
            Negative value indicates never close connection.
    @param exit_timeout: Maximum seconds to clear message queue on exit.
            Negative value indicates clear queue without timeout.

    Usage::
        from Ganga.Lib.MonitoringServices.MSG import MSGUtil
        p = MSGUTIL.createPublisher('dashb-mb.cern.ch', 61113)
        p.start()
        p.send('/topic/ganga.dashboard.test', 'Hello World!')

    See also stomputil.publisher
    """
    # use GangaThread class on client or Thread class otherwise
    try:
        from Ganga.Core.GangaThread import GangaThread as Thread
        managed_thread = True
    except ImportError:
        from threading import Thread
        managed_thread = False
    # use Ganga logger class on client or None otherwise
    try:
        import Ganga.Utility.logging
        logger = Ganga.Utility.logging.getLogger()
    except ImportError:
        logger = None
    # create and start _publisher
    import stomputil
    publisher = stomputil.createPublisher(
        Thread, server, port, user, password, logger, idle_timeout)
    if managed_thread:
        # set GangaThread as non-critical
        publisher.setCritical(False)
    else:
        # add exit handler if not GangaThread
        publisher.addExitHandler(exit_timeout)
    return publisher