Package io.zenoh.query
Class Queryable
-
- All Implemented Interfaces:
-
io.zenoh.session.SessionDeclaration,java.lang.AutoCloseable
public class Queryable implements AutoCloseable, SessionDeclaration
A queryable that allows to perform multiple queries on the specified KeyExpr.
Its main purpose is to keep the queryable active as long as it exists.
The declaring session holds a strong reference to it: dropping your own reference does NOT stop the queryable — it stays active until close (or
undeclare) is called or the session is closed, whichever comes first. Only after that does it become eligible for garbage collection.Example using the default BlockingQueueHandler handler:
try (Session session = Zenoh.open(config)) { var queryable = session.declareQueryable(keyExpr); BlockingQueue<Optional<Query>> receiver = queryable.getReceiver(); assert receiver != null; while (true) { Optional<Query> wrapper = receiver.take(); if (wrapper.isEmpty()) { break; } Query query = wrapper.get(); query.reply(query.getKeyExpr(), "Example reply"); } }Example using a io.zenoh.handlers.Callback:
try (Session session = Zenoh.open(config)) { var queryable = session.declareQueryable(keyExpr, query -> query.reply(query.getKeyExpr(), "Example reply"); }
-
-
Method Summary
-
-
Method Detail
-
getKeyExpr
final KeyExpr getKeyExpr()
The KeyExpr to which the subscriber is associated.
-
-
-
-