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