use of com.serotonin.m2m2.rt.event.ReturnCause in project ma-core-public by infiniteautomation.
the class EventManagerImpl method deactivateEvents.
/**
* Deactivate a group of similar events, these events should have been removed from the active events list already.
*/
protected void deactivateEvents(List<EventInstance> evts, long time, ReturnCause inactiveCause) {
List<User> activeUsers = usersService.getEnabledUsers();
List<Integer> eventIds = new ArrayList<>();
UserEventListener multicaster = userEventMulticaster;
for (EventInstance evt : evts) {
if (evt.isActive())
eventIds.add(evt.getId());
evt.returnToNormal(time, inactiveCause);
List<Integer> userIdsToNotify = new ArrayList<>();
for (User user : activeUsers) {
// user should be skipped.
if (evt.getEventType().excludeUser(user))
continue;
if (evt.getEventType().hasPermission(user, permissionService)) {
userIdsToNotify.add(user.getId());
}
}
if (multicaster != null)
Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(userIdsToNotify, multicaster, evt, false, false, true, false));
// Call inactiveEvent handlers.
handleInactiveEvent(evt);
}
if (eventIds.size() > 0) {
resetHighestAlarmLevel(time);
eventDao.returnEventsToNormal(eventIds, time, inactiveCause);
}
}
use of com.serotonin.m2m2.rt.event.ReturnCause in project ma-core-public by infiniteautomation.
the class EventInstanceI method getRtnMessage.
public default TranslatableMessage getRtnMessage() {
TranslatableMessage rtnKey = null;
EventType eventType = getEventType();
ReturnCause rtnCause = getRtnCause();
if (rtnCause != null) {
switch(rtnCause) {
case RETURN_TO_NORMAL:
rtnKey = new TranslatableMessage("event.rtn.rtn");
break;
case SOURCE_DISABLED:
if (eventType.getEventType().equals(EventType.EventTypeNames.DATA_POINT))
rtnKey = new TranslatableMessage("event.rtn.pointDisabled");
else if (eventType.getEventType().equals(EventType.EventTypeNames.DATA_SOURCE))
rtnKey = new TranslatableMessage("event.rtn.dsDisabled");
else if (eventType.getEventType().equals(EventType.EventTypeNames.PUBLISHER))
rtnKey = new TranslatableMessage("event.rtn.pubDisabled");
else {
EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(eventType.getEventType());
if (def != null)
rtnKey = def.getSourceDisabledMessage();
if (rtnKey == null)
rtnKey = new TranslatableMessage("event.rtn.shutdown");
}
break;
default:
rtnKey = new TranslatableMessage("event.rtn.unknown");
break;
}
}
return rtnKey;
}
use of com.serotonin.m2m2.rt.event.ReturnCause in project ma-core-public by infiniteautomation.
the class EventManagerImpl method returnToNormal.
@Override
public void returnToNormal(EventType type, long time, ReturnCause cause) {
EventInstance evt = remove(type);
if (evt == null) {
if (log.isDebugEnabled()) {
log.debug("Attempted to return non-existent event to normal! type={}, message={}, now={}, eventTime={}, typeRef1={}, typeRef2={}", type, evt.getMessage().translate(Common.getTranslations()), new Date(Common.timer.currentTimeMillis()), new Date(time), evt.getEventType().getReferenceId1(), evt.getEventType().getReferenceId2());
}
return;
}
long nowTimestamp = Common.timer.currentTimeMillis();
if (time > nowTimestamp) {
log.warn("Returning event to normal in future! type=" + type + ", message='" + evt.getMessage().translate(Common.getTranslations()) + "' now=" + new Date(nowTimestamp) + " event=" + new Date(time) + " deltaMs=" + (time - nowTimestamp));
}
List<User> activeUsers = usersService.getEnabledUsers();
UserEventListener multicaster = userEventMulticaster;
// Loop in case of multiples
while (evt != null) {
evt.returnToNormal(time, cause);
List<Integer> userIdsToNotify = new ArrayList<>();
for (User user : activeUsers) {
// user should be skipped.
if (type.excludeUser(user))
continue;
if (evt.getAlarmLevel() != AlarmLevels.DO_NOT_LOG) {
if (type.hasPermission(user, permissionService)) {
userIdsToNotify.add(user.getId());
}
}
}
if (multicaster != null && Common.backgroundProcessing != null)
Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(userIdsToNotify, multicaster, evt, false, true, false, false));
resetHighestAlarmLevel(time);
if (evt.getAlarmLevel() != AlarmLevels.DO_NOT_LOG)
eventDao.saveEvent(evt);
// Call inactiveEvent handlers.
handleInactiveEvent(evt);
// Check for another
evt = remove(type);
}
if (log.isTraceEnabled())
log.trace("Event returned to normal: type=" + type);
}
Aggregations