Package io.zenoh.scouting
Class Scout
-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public class Scout implements AutoCloseable
Scout for routers and/or peers.
Scout spawns a task that periodically sends scout messages and waits for Hello replies. Drop the returned Scout to stop the scouting task.
To launch a scout, use io.zenoh.Zenoh.scout:
Example using the default blocking queue handler:
var scoutOptions = new ScoutOptions(); scoutOptions.setWhatAmI(Set.of(WhatAmI.Peer, WhatAmI.Router)); var scout = Zenoh.scout(scoutOptions); BlockingQueue<Optional<Hello>> receiver = scout.getReceiver(); try { while (true) { Optional<Hello> wrapper = receiver.take(); if (wrapper.isEmpty()) { break; } Hello hello = wrapper.get(); System.out.println(hello); } } finally { scout.stop(); }
Example using a callback:
var scoutOptions = new ScoutOptions(); scoutOptions.setWhatAmI(Set.of(WhatAmI.Peer, WhatAmI.Router)); Zenoh.scout(hello -> { //... System.out.println(hello); }, scoutOptions);