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);
}
}
Aggregations