def run(window):
    try:
        dispatcher = netsvc.Dispatcher()

        dispatcher.disableWarnings()

        dispatcher.monitor(signal.SIGINT)

        root = Pmw.initialise()
        root.withdraw()

        main = window(root)

        root.update()

        target = sys.argv[1]

        try:
            group = ""
            group, address = string.splitfields(target, '@')
        except:
            host, port = string.splitfields(target, ':')
        else:
            host, port = string.splitfields(address, ':')

        exchange = netsvc.Exchange(netsvc.EXCHANGE_CLIENT, group)
        exchange.connect(host, int(port), 5)

        reaper = Reaper(root)

        dispatcher.task().start()

        root.deiconify()
        root.update_idletasks()

        root.mainloop()

    finally:
        dispatcher.task().stop()
        dispatcher.task().wait()
Exemplo n.º 2
0
# The exchange process which everything connects to.

import netsvc
import signal

dispatcher = netsvc.Dispatcher()
dispatcher.monitor(signal.SIGINT)

exchange = netsvc.Exchange(netsvc.EXCHANGE_SERVER)
exchange.listen(11111)

dispatcher.run()

# Service which periodically publishes information.

import netsvc
import signal
import random


class Publisher(netsvc.Service):
    def __init__(self):
        netsvc.Service.__init__(self, "SEED")
        self._count = 0
        time = netsvc.DateTime()
        data = {"time": time}
        self.publishReport("init", data, -1)
        self.startTimer(self.publish, 1, "1")

    def publish(self, name):
        self._count = self._count + 1
Exemplo n.º 3
0

class Database(netsvc.Service):
    def __init__(self, name):
        netsvc.Service.__init__(self, "simple-database")
        self._db = dbm.open(name, 'c')
        self.exportMethod(self.get)
        self.exportMethod(self.put)
        self.exportMethod(self.keys)

    def get(self, key):
        return self._db[key]

    def put(self, key, value):
        self._db[key] = value

    def keys(self):
        return self._db.keys()


dispatcher = netsvc.Dispatcher()
dispatcher.monitor(signal.SIGINT)

exchange = netsvc.Exchange(netsvc.EXCHANGE_SERVER)
exchange.listen(11111)

logger = Logger()
database = Database("database")

dispatcher.run()
Exemplo n.º 4
0
    msg = "netsvc: Starting dispatcher (%d)" % os.getpid()
    apache.log_error(msg, apache.APLOG_NOTICE)

    _dispatcher = netsvc.Dispatcher()

    config = vampire.loadConfig(__req__, ".vampire")

    _host = config.get("Exchange", "host")
    _port = int(config.get("Exchange", "port"))
    _delay = float(config.get("Exchange", "delay"))

    msg = "netsvc: Exchange (%s:%d)" % (_host, _port)
    apache.log_error(msg, apache.APLOG_NOTICE)

    _exchange = netsvc.Exchange(netsvc.EXCHANGE_CLIENT)
    _exchange.connect(_host, _port, _delay)

    del config

    # We want to try and shutdown the dispatcher when
    # Apache is being shutdown or Apache may not shutdown
    # promptly and it may decide to just kill the
    # processes rather than allow them to shutdown
    # gracefully.


    def _shutdown():
        msg = "netsvc: Stopping dispatcher (%d)" % os.getpid()
        apache.log_error(msg, apache.APLOG_NOTICE)
        _dispatcher.task().stop()