admin管理员组文章数量:1410705
During the registration of a device to the leshan server i go through the code of the EventServlet:
private final RegistrationListener registrationListener = new RegistrationListener() {
@Override
public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObservations) {
LOG.info("Creating instance to save in DB and register {}. Located at: {}", registration.getEndpoint(), ((IpPeer) registration.getClientTransportData()).getSocketAddress());
scheduler.schedule(() -> executeBackgroundTask(registration), 1, TimeUnit.SECONDS);
}
@Override
public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) {
LOG.info("Fetching instance to save in DB and update {}", updatedRegistration.getEndpoint());
}
@Override
public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
try {
saveEventLogToDB(registration.getEndpoint(), EventType.fromString(EVENT_DEREGISTRATION))
.doOnSuccess(res -> LOG.info("{} is deregistered", registration.getEndpoint()))
.doOnError(error -> LOG.error("Error saving event log: {}", error.getMessage()))
.subscribe();
String jReg = EventServlet.this.mapper.writeValueAsString(registration);
sendEvent(EVENT_DEREGISTRATION, jReg, registration.getEndpoint());
} catch (JsonProcessingException e) {
LOG.error(e.getMessage());
throw new RuntimeException(e);
}
}
};
The executeBackgroundTask
function is fetching the version of the device by sending a request to the device with 3/0/3 flag. The issue is that apparently during the registered phase, the connection to the device is still occupied by the registration thread, thus the executeBackgroundTask
function is failing to fetch the version.
If I give it some delay it sometimes work possibly due to the fact that the connection sometimes closes before the call to the device from server.
I am looking to get like an event from the leshan server that can help me understand when the connection between device and leshan server is over and I can safely send requests to the device.
Also, it works when I run everything on local machine but when the device is on local machine and the leshan is on k8s the issue occurs.
本文标签: iotRequest from server to client during registrationStack Overflow
版权声明:本文标题:iot - Request from server to client during registration - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744870302a2629588.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论