Пример #1
0
def client_actor(ctx, pipe, address):
    'An actor function talking to a broker on given address'
    pipe.signal()
    
    port = zio.Port("client", zmq.CLIENT,'')
    port.connect(address)
    port.online(None)       # peer not needed if port only direct connects
    log.debug ("made flow")

    direction='extract'
    credit=2
    cflow = Flow(port, direction, credit)

    bot = cflow.bot()
    log.debug (f'client did BOT: {bot}')
    assert(bot)
    cflow.begin()

    msg = zio.Message(form='FLOW', label_object={'flow':'DAT'})
    log.debug (f'client put DAT with {cflow.credit}/{cflow.total_credit} {msg}')
    cflow.put(msg)
    log.debug (f'client did DAT')
    cflow.eot()
    log.debug (f'client did EOT')

    pipe.recv()                 # wait for signal to exit
Пример #2
0
def handler(ctx, pipe, bot, rule_object, filename, broker_addr, *rargs):

    log.debug(f'actor: reader "{filename}"')
    fp = h5py.File(filename, 'r')

    mattr = message_to_dict(bot)
    rattr = dict(rule_object.get("attr", {}), **mattr)
    base_path = rule_object.get("grouppat", "/").format(**rattr)
    log.debug(f'reader(msg, "{base_path}", "{broker_addr}")')
    log.debug(bot)
    pipe.signal()

    sock = ctx.socket(CLIENT)
    port = Port("read-handler", sock)
    port.connect(broker_addr)
    port.online(None)

    direction = mattr["direction"]
    if direction != "extract":
        raise RuntimeError(f'zio.flow.hdf.reader bad direction: "{direction}"')
    credit = mattr["credit"]
    flow = Flow(port, direction, credit)
    log.debug(f'reader({base_path}) send BOT to {broker_addr}')

    sg = fp.get(base_path)
    if not sg:
        log.error(f'reader failed to get {base_path} from {filename}')
        return
    fr = TensReader(sg, *rargs)

    bot = flow.bot(bot)  # this introduces us to the server
    log.debug(f'reader({base_path}) got response: {bot}')
    flow.begin()

    while True:
        msg = fr.read()
        log.debug(f'reader: {msg}')
        if not msg:
            break
        flow.put(msg)
    flow.eot()