Class Publisher
-
- All Implemented Interfaces:
-
io.zenoh.session.SessionDeclaration,java.lang.AutoCloseable
public final class Publisher implements SessionDeclaration, AutoCloseable
A Zenoh Publisher.
A publisher is automatically dropped when using it with the 'try-with-resources' statement (i.e. 'use' in Kotlin). The session keeps only a weak reference to it: a publisher whose last reference is dropped is undeclared by the garbage-collection backstop (non-deterministic — call close for prompt effect), and closing the session undeclares any publisher still reachable.
In order to declare a publisher, Session.declarePublisher must be called.
Example:
try (Session session = Session.open()) { try (KeyExpr keyExpr = KeyExpr.tryFrom("demo/java/greeting")) { System.out.println("Declaring publisher on '" + keyExpr + "'..."); try (Publisher publisher = session.declarePublisher(keyExpr)) { int i = 0; while (true) { publisher.put("Hello for the " + i + "th time!"); Thread.sleep(1000); i++; } } } } catch (ZError | InterruptedException e) { System.out.println("Error: " + e); }The publisher configuration parameters can be later changed using the setter functions.
-
-
Method Summary
Modifier and Type Method Description final KeyExprgetKeyExpr()The key expression the publisher will be associated to. final EncodinggetEncoding()The encoding user by the publisher. final CongestionControlcongestionControl()Get the congestion control applied when routing the data. final Prioritypriority()Get the priority of the written data. final Unitput(IntoZBytes payload)Performs a PUT operation on the specified keyExpr with the specified payload. final Unitput(IntoZBytes payload, PutOptions options)Performs a PUT operation on the specified keyExpr with the specified payload. final Unitput(String payload)Performs a PUT operation on the specified keyExpr with the specified payload. final Unitput(String payload, PutOptions options)Performs a PUT operation on the specified keyExpr with the specified payload. final Unitdelete(DeleteOptions options)Performs a DELETE operation on the specified keyExpr final BooleanisValid()Returns trueif the publisher is still running.Unitclose()Unitundeclare()Undeclare a declaration. -
-
Method Detail
-
getKeyExpr
final KeyExpr getKeyExpr()
The key expression the publisher will be associated to.
-
getEncoding
final Encoding getEncoding()
The encoding user by the publisher.
-
congestionControl
final CongestionControl congestionControl()
Get the congestion control applied when routing the data.
-
put
final Unit put(IntoZBytes payload)
-
put
final Unit put(IntoZBytes payload, PutOptions options)
-
put
final Unit put(String payload, PutOptions options)
-
delete
final Unit delete(DeleteOptions options)
Performs a DELETE operation on the specified keyExpr
-
-
-
-