Search in sources :

Example 1 with ManagedContextTimerTask

use of org.apache.cloudstack.managed.context.ManagedContextTimerTask in project cloudstack by apache.

the class AsyncJobMonitor method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    _messageBus.subscribe(AsyncJob.Topics.JOB_HEARTBEAT, MessageDispatcher.getDispatcher(this));
    _timer.scheduleAtFixedRate(new ManagedContextTimerTask() {

        @Override
        protected void runInContext() {
            heartbeat();
        }
    }, _inactivityCheckIntervalMs, _inactivityCheckIntervalMs);
    return true;
}
Also used : ManagedContextTimerTask(org.apache.cloudstack.managed.context.ManagedContextTimerTask)

Example 2 with ManagedContextTimerTask

use of org.apache.cloudstack.managed.context.ManagedContextTimerTask in project cloudstack by apache.

the class SnapshotSchedulerImpl method start.

@Override
@DB
public boolean start() {
    // reschedule all policies after management restart
    final List<SnapshotPolicyVO> policyInstances = _snapshotPolicyDao.listAll();
    for (final SnapshotPolicyVO policyInstance : policyInstances) {
        if (policyInstance.getId() != Snapshot.MANUAL_POLICY_ID) {
            scheduleNextSnapshotJob(policyInstance);
        }
    }
    if (_testTimerTask != null) {
        _testClockTimer = new Timer("TestClock");
        // Run the test clock every 60s. Because every tick is counted as 1 minute.
        // Else it becomes too confusing.
        _testClockTimer.schedule(_testTimerTask, 100 * 1000L, 60 * 1000L);
    } else {
        final TimerTask timerTask = new ManagedContextTimerTask() {

            @Override
            protected void runInContext() {
                try {
                    final Date currentTimestamp = new Date();
                    poll(currentTimestamp);
                } catch (final Throwable t) {
                    s_logger.warn("Catch throwable in snapshot scheduler ", t);
                }
            }
        };
        _testClockTimer = new Timer("SnapshotPollTask");
        _testClockTimer.schedule(timerTask, _snapshotPollInterval * 1000L, _snapshotPollInterval * 1000L);
    }
    return true;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) ManagedContextTimerTask(org.apache.cloudstack.managed.context.ManagedContextTimerTask) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO) ManagedContextTimerTask(org.apache.cloudstack.managed.context.ManagedContextTimerTask) Date(java.util.Date) DB(com.cloud.utils.db.DB)

Aggregations

ManagedContextTimerTask (org.apache.cloudstack.managed.context.ManagedContextTimerTask)2 SnapshotPolicyVO (com.cloud.storage.SnapshotPolicyVO)1 DB (com.cloud.utils.db.DB)1 Date (java.util.Date)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1