Ejemplo n.º 1
0
    def __init__(
        self,
        flux_handle,
        type_mask,
        callback,
        topic_glob="*",
        match_tag=flux.constants.FLUX_MATCHTAG_NONE,
        args=None,
    ):
        self.flux_handle = flux_handle
        self.callback = callback
        self.args = args
        self.wargs = ffi.new_handle(self)

        if topic_glob is None or topic_glob == ffi.NULL:
            topic_glob = ffi.NULL
        elif isinstance(topic_glob, six.text_type):
            topic_glob = topic_glob.encode("UTF-8")
        elif not isinstance(topic_glob, six.binary_type):
            errmsg = "Topic must be a string, not {}".format(type(topic_glob))
            raise TypeError(errno.EINVAL, errmsg)
        c_topic_glob = ffi.new("char[]", topic_glob)

        match = ffi.new(
            "struct flux_match *",
            {"typemask": type_mask, "matchtag": match_tag, "topic_glob": c_topic_glob},
        )
        super(MessageWatcher, self).__init__(
            raw.flux_msg_handler_create(
                self.flux_handle.handle, match[0], message_handler_wrapper, self.wargs
            )
        )
Ejemplo n.º 2
0
 def __init__(
     self,
     flux_handle,
     type_mask,
     callback,
     topic_glob="*",
     match_tag=flux.constants.FLUX_MATCHTAG_NONE,
     args=None,
 ):
     self.flux_handle = flux_handle
     self.callback = callback
     self.args = args
     self.wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new("char[]", topic_glob)
     match = ffi.new(
         "struct flux_match *",
         {
             "typemask": type_mask,
             "matchtag": match_tag,
             "topic_glob": c_topic_glob
         },
     )
     super(MessageWatcher, self).__init__(
         raw.flux_msg_handler_create(self.flux_handle.handle, match[0],
                                     message_handler_wrapper, self.wargs))
Ejemplo n.º 3
0
    def __init__(
        self,
        flux_handle,
        type_mask,
        callback,
        topic_glob="*",
        match_tag=flux.constants.FLUX_MATCHTAG_NONE,
        args=None,
    ):
        self.callback = callback
        self.args = args
        self.wargs = ffi.new_handle(self)

        if topic_glob is None or topic_glob == ffi.NULL:
            topic_glob = ffi.NULL
        elif isinstance(topic_glob, str):
            topic_glob = topic_glob.encode("UTF-8")
        elif not isinstance(topic_glob, bytes):
            errmsg = "Topic must be a string, not {}".format(type(topic_glob))
            raise TypeError(errno.EINVAL, errmsg)
        c_topic_glob = ffi.new("char[]", topic_glob)

        match = ffi.new(
            "struct flux_match *",
            {"typemask": type_mask, "matchtag": match_tag, "topic_glob": c_topic_glob},
        )
        super(MessageWatcher, self).__init__(
            flux_handle,
            raw.flux_msg_handler_create(
                flux_handle.handle,
                match[0],
                lib.message_handler_wrapper,
                self.wargs,
            ),
        )
Ejemplo n.º 4
0
 def then(self, callback, args):
     def cb_then_wrapper(trash, arg):
         rpc_handle = ffi.from_handle(arg)
         callback(rpc_handle, rpc_handle.then_args)
     # Save the callback to keep it from getting collected
     self.then_cb = ffi.callback('flux_then_f', cb_then_wrapper)
     self.then_args = args
     return self.pimpl.then(self.then_cb, ffi.new_handle(self))
Ejemplo n.º 5
0
    def then(self, callback, args):
        def cb_then_wrapper(trash, arg):
            rpc_handle = ffi.from_handle(arg)
            callback(rpc_handle, rpc_handle.then_args)

        # Save the callback to keep it from getting collected
        self.then_cb = ffi.callback('flux_then_f', cb_then_wrapper)
        self.then_args = args
        return self.pimpl.then(self.then_cb, ffi.new_handle(self))
Ejemplo n.º 6
0
 def __init__(self, flux_handle, after, callback, repeat=0, args=None, ):
     self.fh = flux_handle
     self.after = after
     self.repeat = repeat
     self.cb = callback
     self.args = args
     self.handle = None
     wargs = ffi.new_handle(self)
     self.handle = raw.flux_timer_watcher_create(
         float(after), float(repeat), timeout_handler_wrapper, wargs)
Ejemplo n.º 7
0
 def __init__(self, flux_handle, fd_int, events, callback, args=None):
     self.fh = flux_handle
     self.fd_int = fd_int
     self.events = events
     self.cb = callback
     self.args = args
     self.handle = None
     wargs = ffi.new_handle(self)
     self.handle = raw.flux_fd_watcher_create(
         raw.flux_get_reactor(flux_handle),
         self.fd_int, self.events, fd_handler_wrapper, wargs)
Ejemplo n.º 8
0
 def __init__(self, flux_handle, fd_int, events, callback, args=None):
     self.flux_handle = flux_handle
     self.fd_int = fd_int
     self.events = events
     self.callback = callback
     self.args = args
     self.handle = None
     self.wargs = ffi.new_handle(self)
     super(FDWatcher, self).__init__(
         raw.flux_fd_watcher_create(raw.flux_get_reactor(flux_handle),
                                    self.fd_int, self.events,
                                    fd_handler_wrapper, self.wargs))
Ejemplo n.º 9
0
    def then(self, callback, arg=None, timeout=-1.0):
        if self in _THEN_HANDLES:
            raise EnvironmentError(
                errno.EEXIST, "then callback already exists for this future")

        self.then_cb = callback
        self.then_arg = arg
        self.cb_handle = ffi.new_handle(self)
        self.pimpl.then(timeout, lib.continuation_callback, self.cb_handle)

        # ensure that this future object is not garbage collected with a
        # callback outstanding. Particularly important for anonymous calls.
        # For example, `f.rpc.('topic').then(cb)`
        _THEN_HANDLES.add(self)
Ejemplo n.º 10
0
 def __init__(self, flux_handle, after, callback, repeat=0, args=None, ):
     self.flux_handle = flux_handle
     self.after = after
     self.repeat = repeat
     self.callback = callback
     self.args = args
     self.handle = None
     self.wargs = ffi.new_handle(self)
     super(TimerWatcher, self).__init__(
         raw.flux_timer_watcher_create(
             raw.flux_get_reactor(flux_handle),
             float(after),
             float(repeat),
             timeout_handler_wrapper,
             self.wargs))
Ejemplo n.º 11
0
    def then(self, callback, arg=None, timeout=-1.0):
        if self in _THEN_HANDLES:
            raise EnvironmentError(
                errno.EEXIST, "then callback already exists for this future"
            )

        self.then_cb = callback
        self.then_arg = arg
        self.cb_handle = ffi.new_handle(self)
        self.pimpl.then(timeout, lib.continuation_callback, self.cb_handle)

        # ensure that this future object is not garbage collected with a
        # callback outstanding. Particularly important for anonymous calls.
        # For example, `f.rpc.('topic').then(cb)`
        _THEN_HANDLES.add(self)
Ejemplo n.º 12
0
 def __init__(self, flux_handle, after, callback, repeat=0, args=None):
     self.flux_handle = flux_handle
     self.after = after
     self.repeat = repeat
     self.callback = callback
     self.args = args
     self.handle = None
     self.wargs = ffi.new_handle(self)
     super(TimerWatcher, self).__init__(
         raw.flux_timer_watcher_create(
             raw.flux_get_reactor(flux_handle),
             float(after),
             float(repeat),
             lib.timeout_handler_wrapper,
             self.wargs,
         ))
Ejemplo n.º 13
0
 def __init__(self, flux_handle, type_mask, callback,
              topic_glob='*',
              match_tag=flux.FLUX_MATCHTAG_NONE,
              args=None):
     self.handle = None
     self.fh = flux_handle
     self.cb = callback
     self.args = args
     self.wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new('char[]', topic_glob)
     match = ffi.new('struct flux_match *', {
         'typemask': type_mask,
         'matchtag': match_tag,
         'topic_glob': c_topic_glob,
     })
     self.handle = raw.flux_msg_handler_create(self.fh.handle, match[0],
                                               message_handler_wrapper,
                                               self.wargs)
Ejemplo n.º 14
0
 def __init__(self, flux_handle, signal_int, callback, args=None):
     self.flux_handle = flux_handle
     self.signal_int = signal_int
     self.callback = callback
     self.args = args
     self.handle = None
     self.wargs = ffi.new_handle(self)
     super(SignalWatcher, self).__init__(
         raw.flux_signal_watcher_create(
             raw.flux_get_reactor(flux_handle),
             self.signal_int,
             lib.signal_handler_wrapper,
             self.wargs,
         ))
     # N.B.: check for error only after SignalWatcher object fully
     #  initialized to avoid 'no attribute self.handle' in __del__
     #  method.
     if signal_int < 1 or signal_int >= signal.NSIG:
         raise OSError(errno.EINVAL, "invalid signal number")
Ejemplo n.º 15
0
 def __init__(self, flux_handle, type_mask, callback,
              topic_glob='*',
              match_tag=flux.constants.FLUX_MATCHTAG_NONE,
              args=None):
     self.flux_handle = flux_handle
     self.callback = callback
     self.args = args
     self.wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new('char[]', topic_glob)
     match = ffi.new('struct flux_match *', {
         'typemask': type_mask,
         'matchtag': match_tag,
         'topic_glob': c_topic_glob,
     })
     super(MessageWatcher, self).__init__(
         raw.flux_msg_handler_create(
             self.flux_handle.handle,
             match[0],
             message_handler_wrapper,
             self.wargs))
Ejemplo n.º 16
0
 def __init__(self, flux_handle, type_mask, callback,
              topic_glob='*',
              match_tag=flux.FLUX_MATCHTAG_NONE,
              bsize=0,
              args=None):
     self.handle = None
     self.fh = flux_handle
     self.cb = callback
     self.args = args
     wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new('char[]', topic_glob)
     match = ffi.new('struct flux_match *', {
         'typemask': type_mask,
         'matchtag': match_tag,
         'bsize': bsize,
         'topic_glob': c_topic_glob,
     })
     self.handle = raw.flux_msg_watcher_create(match[0],
                                               message_handler_wrapper,
                                               wargs)
Ejemplo n.º 17
0
    def then(self, callback, arg=None, timeout=-1.0):
        if self in _THEN_HANDLES:
            raise EnvironmentError(
                errno.EEXIST, "then callback already exists for this future")
        if callback is None:
            raise ValueError("Callback cannot be None")

        self.then_cb = callback
        self.then_arg = arg
        self.cb_handle = ffi.new_handle(self)
        self.pimpl.then(timeout, lib.continuation_callback, self.cb_handle)

        # ensure that this future object is not garbage collected with a
        # callback outstanding. Particularly important for anonymous calls and
        # streaming RPCs.  For example, `f.rpc('topic').then(cb)`
        _THEN_HANDLES[self] = 1

        # return self to enable further chaining of the future.
        # For example `f.rpc('topic').then(cb).wait_for(-1)
        return self