use of com.infiniteautomation.mango.rest.latest.websocket.WebSocketSendException in project ma-modules-public by infiniteautomation.
the class PointValueWebSocketHandler method handleTextMessage.
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
try {
PermissionHolder user = getUser(session);
PointValueRegistrationModel model = this.jacksonMapper.readValue(message.getPayload(), PointValueRegistrationModel.class);
DataPointVO vo;
try {
// This will check for not found and permissions
vo = datapointService.get(model.getDataPointXid());
} catch (NotFoundException e) {
// send not found message back
this.sendErrorMessage(session, MangoWebSocketErrorType.SERVER_ERROR, new TranslatableMessage("rest.error.pointNotFound", model.getDataPointXid()));
return;
} catch (PermissionException e) {
// Send permission denied message here
this.sendErrorMessage(session, MangoWebSocketErrorType.PERMISSION_DENIED, new TranslatableMessage("permission.exception.readDataPoint", user.getPermissionHolderName()));
return;
}
Set<PointValueEventType> eventsTypes = model.getEventTypes();
int dataPointId = vo.getId();
synchronized (pointIdToListenerMap) {
if (this.connectionClosed) {
return;
}
PointValueWebSocketListener publisher = pointIdToListenerMap.get(dataPointId);
if (publisher != null) {
if (eventsTypes.isEmpty()) {
publisher.terminate();
pointIdToListenerMap.remove(dataPointId);
} else {
publisher.setEventTypes(eventsTypes);
}
} else if (!eventsTypes.isEmpty()) {
publisher = new PointValueWebSocketListener(vo, eventsTypes);
publisher.initialize();
// Immediately send the most recent Point Value and the status of the data point
publisher.sendPointStatus();
pointIdToListenerMap.put(dataPointId, publisher);
}
}
} catch (WebSocketSendException e) {
log.warn("Error sending websocket message", e);
} catch (Exception e) {
try {
this.sendErrorMessage(session, MangoWebSocketErrorType.SERVER_ERROR, new TranslatableMessage("rest.error.serverError", e.getMessage()));
} catch (Exception e1) {
log.error("An error occurred", e);
}
}
if (log.isDebugEnabled()) {
log.debug(message.getPayload());
}
}
Aggregations