public class Requester extends Object implements Consumer<IPacket>
Active mode remote configuration. Application has no local config storage and requests config items on each start. Alternatively it has local config storage but updates it from time to time from central node.
Remote configuration requester.
See also Provider class.
Keeps set of topics, requests them from network, keeps replies. Usage:
IPacketMultiSource ms = new PacketSourceMultiServer();
ms.start();
Requester r = Requester(ms);
r.addTopic("$SYS/myinstancename/param"); // will request it from net
r.startBackgroundRequests(); // start asking for topic values in loop
if( !waitForAll(10*1000*1000) )
{
print("Can't get config from net"); System.Exit(1);
}
| Constructor and Description |
|---|
Requester(IPacketMultiSource ms)
Construct.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(IPacket t)
Implementation of Consumer<IPacket> interface.
|
void |
addTopic(String topicName)
Add topic, which value is to be requested from MQTT/UDP network,
|
Set<String> |
getAllEmpty()
Get list of topics for which we do not have data yet.
|
long |
getCheckLoopTime() |
String |
getValue(String topic)
Get value for topic
|
boolean |
isDone()
Check if all items got values.
|
protected void |
loop() |
void |
setCheckLoopTime(long checkLoopTime)
Set time between repeated requests for items.
|
void |
startBackgroundRequests()
Start background process to poll net for topics we need.
|
boolean |
waitForAll(long timeoutMsec)
Wait for all topics to get content.
|
public Requester(IPacketMultiSource ms)
ms - MQTT/UDP network listener which is able to serve multiple consumers.public void addTopic(String topicName) throws IOException
topicName - name of topic to requestIOException - if network send is failedpublic String getValue(String topic)
topic - to get value forpublic void accept(IPacket t)
public void startBackgroundRequests()
public void setCheckLoopTime(long checkLoopTime)
checkLoopTime - Time in milliseconds.public long getCheckLoopTime()
protected void loop()
throws IOException
IOExceptionpublic Set<String> getAllEmpty()
public boolean isDone()
public boolean waitForAll(long timeoutMsec)
timeoutMsec - Max time to wait.Copyright © 2019. All rights reserved.