use of org.thingsboard.server.transport.coap.callback.CoapNoOpCallback in project thingsboard by thingsboard.
the class DefaultCoapClientContext method registerFeatureObservation.
private boolean registerFeatureObservation(TbCoapClientState state, String token, CoapExchange exchange, FeatureType featureType) {
state.lock();
try {
boolean newObservation;
if (FeatureType.ATTRIBUTES.equals(featureType)) {
if (state.getAttrs() == null) {
newObservation = true;
state.setAttrs(new TbCoapObservationState(exchange, token));
} else {
newObservation = !state.getAttrs().getToken().equals(token);
if (newObservation) {
TbCoapObservationState old = state.getAttrs();
state.setAttrs(new TbCoapObservationState(exchange, token));
old.getExchange().respond(CoAP.ResponseCode.DELETED);
}
}
} else {
if (state.getRpc() == null) {
newObservation = true;
state.setRpc(new TbCoapObservationState(exchange, token));
} else {
newObservation = !state.getRpc().getToken().equals(token);
if (newObservation) {
TbCoapObservationState old = state.getRpc();
state.setRpc(new TbCoapObservationState(exchange, token));
old.getExchange().respond(CoAP.ResponseCode.DELETED);
}
}
}
if (newObservation) {
clientsByToken.put(token, state);
if (state.getSession() == null) {
TransportProtos.SessionInfoProto session = SessionInfoCreator.create(state.getCredentials(), transportContext, UUID.randomUUID());
state.setSession(session);
CoapSessionListener listener = new CoapSessionListener(state);
state.setListener(listener);
transportService.registerAsyncSession(session, state.getListener());
transportService.process(session, getSessionEventMsg(TransportProtos.SessionEvent.OPEN), null);
}
if (FeatureType.ATTRIBUTES.equals(featureType)) {
transportService.process(state.getSession(), TransportProtos.SubscribeToAttributeUpdatesMsg.getDefaultInstance(), new CoapNoOpCallback(exchange));
transportService.process(state.getSession(), TransportProtos.GetAttributeRequestMsg.newBuilder().setOnlyShared(true).build(), new CoapNoOpCallback(exchange));
} else {
transportService.process(state.getSession(), TransportProtos.SubscribeToRPCMsg.getDefaultInstance(), new CoapOkCallback(exchange, CoAP.ResponseCode.VALID, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
}
}
return newObservation;
} finally {
state.unlock();
}
}
use of org.thingsboard.server.transport.coap.callback.CoapNoOpCallback in project thingsboard by thingsboard.
the class CoapTransportResource method handleToServerRpcRequest.
private void handleToServerRpcRequest(TbCoapClientState clientState, CoapExchange exchange, Request request) throws AdaptorException {
TransportProtos.SessionInfoProto sessionInfo = clients.getNewSyncSession(clientState);
UUID sessionId = toSessionId(sessionInfo);
transportService.registerSyncSession(sessionInfo, new ToServerRpcSyncSessionCallback(clientState, exchange, request), timeout);
transportService.process(sessionInfo, clientState.getAdaptor().convertToServerRpcRequest(sessionId, request), new CoapNoOpCallback(exchange));
}
use of org.thingsboard.server.transport.coap.callback.CoapNoOpCallback in project thingsboard by thingsboard.
the class CoapTransportResource method handleGetAttributesRequest.
private void handleGetAttributesRequest(TbCoapClientState clientState, CoapExchange exchange, Request request) throws AdaptorException {
TransportProtos.SessionInfoProto sessionInfo = clients.getNewSyncSession(clientState);
UUID sessionId = toSessionId(sessionInfo);
transportService.registerSyncSession(sessionInfo, new GetAttributesSyncSessionCallback(clientState, exchange, request), timeout);
transportService.process(sessionInfo, clientState.getAdaptor().convertToGetAttributes(sessionId, request), new CoapNoOpCallback(exchange));
}
Aggregations