Search in sources :

Example 1 with LtRestriction

use of org.opennms.core.criteria.restrictions.LtRestriction in project opennms by OpenNMS.

the class DefaultPollerBackEnd method checkForDisconnectedMonitors.

/**
     * <p>checkForDisconnectedMonitors</p>
     */
@Override
public void checkForDisconnectedMonitors() {
    LOG.debug("Checking for disconnected monitors: disconnectedTimeout = {}", m_disconnectedTimeout);
    try {
        final Date now = m_timeKeeper.getCurrentDate();
        final Date earliestAcceptable = new Date(now.getTime() - m_disconnectedTimeout);
        final Criteria criteria = new Criteria(OnmsLocationMonitor.class);
        criteria.addRestriction(new EqRestriction("status", MonitorStatus.STARTED));
        criteria.addRestriction(new NotNullRestriction("lastUpdated"));
        criteria.addRestriction(new LtRestriction("lastUpdated", earliestAcceptable));
        // Lock all of the records for update since we will be marking them as DISCONNECTED
        criteria.setLockType(LockType.PESSIMISTIC_READ);
        final Collection<OnmsLocationMonitor> monitors = m_locMonDao.findMatching(criteria);
        LOG.debug("Found {} monitor(s) that are transitioning to disconnected state", monitors.size());
        for (final OnmsLocationMonitor monitor : monitors) {
            LOG.debug("Monitor {} has stopped responding", monitor.getName());
            monitor.setStatus(MonitorStatus.DISCONNECTED);
            m_locMonDao.update(monitor);
            sendDisconnectedEvent(monitor);
        }
    } catch (final Throwable e) {
        LOG.warn("An error occurred checking for disconnected monitors.", e);
    }
}
Also used : NotNullRestriction(org.opennms.core.criteria.restrictions.NotNullRestriction) LtRestriction(org.opennms.core.criteria.restrictions.LtRestriction) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 Criteria (org.opennms.core.criteria.Criteria)1 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)1 LtRestriction (org.opennms.core.criteria.restrictions.LtRestriction)1 NotNullRestriction (org.opennms.core.criteria.restrictions.NotNullRestriction)1 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)1