Package io.zenoh.handlers
Interface Handler
-
- All Implemented Interfaces:
public interface Handler<T extends ZenohType, R extends Object>
Handler interface for classes implementing behavior to handle the incoming T elements.
Example: In this example we implement a handler that stores the received elements into an ArrayDeque, which can then be retrieved:
public class QueueHandler<T extends ZenohType> implements Handler<T, ArrayDeque<T>> { private final ArrayDeque<T> queue = new ArrayDeque<>(); @Override public void handle(T t) { System.out.println("Received " + t + ", enqueuing..."); queue.add(t); } @Override public ArrayDeque<T> receiver() { return queue; } @Override public void onClose() { System.out.println("Received in total " + queue.size() + " elements."); } }
That
QueueHandler
could then be used as follows, for instance for a subscriber:var queue = session.declareSubscriber(keyExpr, new QueueHandler<Sample>()); ...
where the
queue
returned is the receiver from the handler.
-
-
Method Summary
-
-
Method Detail
-
handle
abstract Unit handle(T t)
Handle the received t element.
- Parameters:
t
- An element of type T.
-
onClose
abstract Unit onClose()
This callback is invoked by Zenoh at the conclusion of the handler's lifecycle.
For instances of io.zenoh.queryable.Queryable and io.zenoh.subscriber.Subscriber, Zenoh triggers this callback when they are closed or undeclared. In the case of a Get query (see io.zenoh.query.Get), it is invoked when no more elements of type T are expected to be received.
-
-
-
-