use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.
the class MiscDwr method acknowledgeAllPendingEvents.
@DwrPermission(anonymous = true)
public void acknowledgeAllPendingEvents() {
User user = Common.getHttpUser();
if (user != null) {
EventDao eventDao = EventDao.instance;
long now = Common.timer.currentTimeMillis();
for (EventInstance evt : eventDao.getPendingEvents(user.getId())) Common.eventManager.acknowledgeEventById(evt.getId(), now, user, null);
resetLastAlarmLevelChange();
}
}
use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.
the class MiscDwr method silenceAll.
@DwrPermission(anonymous = true)
public ProcessResult silenceAll() {
List<Integer> silenced = new ArrayList<Integer>();
User user = Common.getHttpUser();
if (user != null) {
EventDao eventDao = EventDao.instance;
for (EventInstance evt : eventDao.getPendingEvents(user.getId())) {
if (!evt.isSilenced()) {
eventDao.toggleSilence(evt.getId(), user.getId());
silenced.add(evt.getId());
}
}
resetLastAlarmLevelChange();
}
ProcessResult response = new ProcessResult();
response.addData("silenced", silenced);
return response;
}
use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.
the class EventManagerImpl method returnToNormal.
public void returnToNormal(EventType type, long time, int alarmLevel, int cause) {
if (alarmLevel == AlarmLevels.IGNORE)
return;
EventInstance evt = remove(type);
if (evt == null)
return;
List<User> activeUsers = userDao.getActiveUsers();
// Loop in case of multiples
while (evt != null) {
evt.returnToNormal(time, cause);
for (User user : activeUsers) {
// user should be skipped.
if (type.excludeUser(user))
continue;
if (evt.getAlarmLevel() != AlarmLevels.DO_NOT_LOG) {
if (Permissions.hasEventTypePermission(user, type)) {
// Notify All User Event Listeners of the new event
for (UserEventListener l : this.userEventListeners) {
if ((l.getUserId() == user.getId())) {
Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(user, l, evt, false, true, false, false));
}
}
// Only alarms make it into the cache
this.userEventCache.updateEvent(user.getId(), evt);
}
}
}
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);
}
use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.
the class EventManagerImpl method acknowledgeEventById.
/**
* Acknowledges an event given an event ID.
*
* The returned EventInstance is a copy from the database, never the cached instance. If the returned instance
* has a different time, userId or alternateAckSource to what was provided then the event must have been already acknowledged.
*
* @param eventId
* @param time
* @param userId
* @param alternateAckSource
* @return the EventInstance for the ID if found, null otherwise
*/
public EventInstance acknowledgeEventById(int eventId, long time, User user, TranslatableMessage alternateAckSource) {
EventInstance dbEvent;
EventInstance cachedEvent = getById(eventId);
if (cachedEvent != null) {
acknowledgeEvent(cachedEvent, time, user, alternateAckSource);
// we don't want to return the cached event, user might change it
// return a copy from the database
dbEvent = eventDao.get(eventId);
} else {
dbEvent = eventDao.get(eventId);
// only ack the event if it exists and is not already acknowledged
if (dbEvent != null && !dbEvent.isAcknowledged()) {
boolean acked = acknowledgeEvent(dbEvent, time, user, alternateAckSource);
// unlikely case that someone else ackd the event at the same time
if (!acked) {
// fetch the updated event from the db again
dbEvent = eventDao.get(eventId);
}
}
}
return dbEvent;
}
use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.
the class EventManagerImpl method cancelEventsForDataSource.
/**
* Cancel active events for a Data Source
* @param dataSourceId
*/
public void cancelEventsForDataSource(int dataSourceId) {
List<EventInstance> dataSourceEvents = new ArrayList<EventInstance>();
activeEventsLock.writeLock().lock();
try {
ListIterator<EventInstance> it = activeEvents.listIterator();
while (it.hasNext()) {
EventInstance e = it.next();
if (e.getEventType().getDataSourceId() == dataSourceId) {
it.remove();
dataSourceEvents.add(e);
}
}
} finally {
activeEventsLock.writeLock().unlock();
}
deactivateEvents(dataSourceEvents, Common.timer.currentTimeMillis(), EventInstance.RtnCauses.SOURCE_DISABLED);
recentEventsLock.writeLock().lock();
try {
ListIterator<EventInstance> it = recentEvents.listIterator();
while (it.hasNext()) {
EventInstance e = it.next();
if (e.getEventType().getDataSourceId() == dataSourceId)
it.remove();
}
} finally {
recentEventsLock.writeLock().unlock();
}
}
Aggregations