Search in sources :

Example 26 with EventInstance

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();
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) EventDao(com.serotonin.m2m2.db.dao.EventDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 27 with EventInstance

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;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) EventDao(com.serotonin.m2m2.db.dao.EventDao) ArrayList(java.util.ArrayList) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 28 with EventInstance

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);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) UserEventListener(com.serotonin.m2m2.rt.event.UserEventListener)

Example 29 with EventInstance

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;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance)

Example 30 with EventInstance

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();
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

EventInstance (com.serotonin.m2m2.rt.event.EventInstance)30 ArrayList (java.util.ArrayList)14 User (com.serotonin.m2m2.vo.User)12 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)7 HashMap (java.util.HashMap)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 EventDao (com.serotonin.m2m2.db.dao.EventDao)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 UserEventListener (com.serotonin.m2m2.rt.event.UserEventListener)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 Translations (com.serotonin.m2m2.i18n.Translations)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)3 ScriptLog (com.serotonin.m2m2.rt.script.ScriptLog)3 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)3 EventInstanceBean (com.serotonin.m2m2.web.dwr.beans.EventInstanceBean)3 ScriptException (javax.script.ScriptException)3