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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Unit handle(T t) Handle the received t element.
      abstract R receiver() Return the receiver of the handler.
      abstract Unit onClose() This callback is invoked by Zenoh at the conclusion of the handler's lifecycle.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • handle

         abstract Unit handle(T t)

        Handle the received t element.

        Parameters:
        t - An element of type T.
      • receiver

         abstract R receiver()

        Return the receiver of the handler.

      • 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.