use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventEventTypeEnum in project ma-modules-public by infiniteautomation.
the class EventsWebSocketHandler method handleTextMessage.
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
try {
User user = this.getUser(session);
if (user == null) {
return;
}
EventRegistrationModel model = this.jacksonMapper.readValue(message.getPayload(), EventRegistrationModel.class);
Set<String> levels = model.getLevels();
if (levels == null) {
levels = Collections.emptySet();
}
Set<EventEventTypeEnum> events = model.getEventTypes();
if (events == null) {
events = EnumSet.noneOf(EventEventTypeEnum.class);
}
boolean emptySubscriptions = levels.isEmpty() || events.isEmpty();
synchronized (this.lock) {
if (!this.connectionClosed) {
if (this.listener != null) {
if (emptySubscriptions) {
this.listener.terminate();
this.listener = null;
} else {
this.listener.changeLevels(levels);
this.listener.changeEvents(events);
}
} else if (!emptySubscriptions) {
this.listener = new EventsWebSocketListener(user, levels, events);
this.listener.initialize();
}
}
}
} catch (Exception e) {
try {
this.sendErrorMessage(session, MangoWebSocketErrorType.SERVER_ERROR, new TranslatableMessage("rest.error.serverError", e.getMessage()));
} catch (Exception e1) {
log.error(e.getMessage(), e);
}
}
if (log.isDebugEnabled())
log.debug(message.getPayload());
}
Aggregations