blob: 1c0a7fd59a9e44f9e2714c4544795ba46c0c1c07 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*******************************************************************************
* Copyright (c) 2004 - 2006 University Of British Columbia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* University Of British Columbia - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.util;
import org.eclipse.mylyn.internal.monitor.core.util.StatusManager;
import org.eclipse.mylyn.monitor.core.ActivityTimerThread;
import org.eclipse.mylyn.monitor.core.IActivityTimerListener;
/**
* Timer that periodically runs saveRequested() on its client as a job
*
* @author Wesley Coelho
*/
public class BackgroundSaveTimer implements IActivityTimerListener {
private final static int DEFAULT_SAVE_INTERVAL = 60 * 1000;
private int saveInterval = DEFAULT_SAVE_INTERVAL;
private IBackgroundSaveListener listener = null;
private ActivityTimerThread timer = null;
// private boolean forceSyncExec = false;
public BackgroundSaveTimer(IBackgroundSaveListener listener) {
this.listener = listener;
timer = new ActivityTimerThread(saveInterval);
timer.addListener(this);
}
public void start() {
timer.start();
}
public void stop() {
timer.kill();
}
public void setSaveIntervalMillis(int saveIntervalMillis) {
this.saveInterval = saveIntervalMillis;
timer.setTimeoutMillis(saveIntervalMillis);
}
public int getSaveIntervalMillis() {
return saveInterval;
}
// /**
// * For testing
// */
// public void setForceSyncExec(boolean forceSyncExec) {
// this.forceSyncExec = forceSyncExec;
// }
/**
* Called by the ActivityTimerThread Calls save in a new job
*/
public void fireInactive() {
try {
// if (!forceSyncExec) {
// final SaveJob job = new SaveJob("Saving Task Data", listener);
// job.schedule();
// } else {
listener.saveRequested();
// }
} catch (RuntimeException e) {
StatusManager.log("Could not schedule save job", this);
}
}
// /** Job that makes the save call */
// private class SaveJob extends Job {
// private IBackgroundSaveListener listener = null;
//
// public SaveJob(String name, IBackgroundSaveListener listener) {
// super(name);
// this.listener = listener;
// }
//
// @Override
// protected IStatus run(IProgressMonitor monitor) {
// listener.saveRequested();
// return Status.OK_STATUS;
// }
// }
public void fireActive(long start, long end) {
// ignore
}
}
|