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
|
/*******************************************************************************
* Copyright (c) 1997, 2018 by ProSyst Software GmbH
* http://www.prosyst.com
* 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:
* ProSyst Software GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.util.impl.tpt.timer;
import org.eclipse.equinox.internal.util.impl.tpt.ServiceFactoryImpl;
import org.eclipse.equinox.internal.util.impl.tpt.threadpool.ThreadPoolFactoryImpl;
import org.eclipse.equinox.internal.util.ref.Log;
import org.eclipse.equinox.internal.util.timer.Timer;
import org.eclipse.equinox.internal.util.timer.TimerListener;
/**
* @author Pavlin Dobrev
* @version 1.0
*/
public class TimerFactory extends ServiceFactoryImpl implements Timer {
private static TimerImpl timer;
public TimerFactory(String bundleName, ThreadPoolFactoryImpl factory, Log log) {
super(bundleName, log);
timer = new TimerImpl(factory);
}
public TimerFactory(String bundleName) {
super(bundleName);
}
public Object getInstance(String bundleName) {
if (timer == null)
throw new RuntimeException("ServiceFactory is currently off!");
return new TimerFactory(bundleName);
}
@Deprecated
public void notifyAfterMillis(TimerListener listener, long timePeriod, int event) throws IllegalArgumentException {
addNotifyListener(listener, Thread.NORM_PRIORITY, Timer.ONE_SHOT_TIMER, timePeriod, event);
}
@Deprecated
public void notifyAfterMillis(TimerListener listener, int priority, long timePeriod, int event) throws IllegalArgumentException {
addNotifyListener(listener, priority, Timer.ONE_SHOT_TIMER, timePeriod, event);
}
@Deprecated
public void notifyAfter(TimerListener listener, int timePeriod, int event) throws IllegalArgumentException {
addNotifyListener(listener, Thread.NORM_PRIORITY, Timer.ONE_SHOT_TIMER, timePeriod * 1000, event);
}
@Deprecated
public void notifyAfter(TimerListener listener, int priority, int timePeriod, int event) throws IllegalArgumentException {
addNotifyListener(listener, priority, Timer.ONE_SHOT_TIMER, timePeriod * 1000, event);
}
public void addNotifyListener(TimerListener listener, int priority, int timerType, long periodMilis, int event) {
TimerImpl tmp = timer;
if (tmp == null)
throw new RuntimeException("This is a zombie!");
tmp.addNotifyListener(listener, priority, timerType, periodMilis, event, bundleName);
}
public static void stopTimer() {
if (timer != null) {
timer.terminate();
timer = null;
}
}
public void removeListener(TimerListener listener, int event) {
TimerImpl tmp = timer;
if (tmp == null)
throw new RuntimeException("This is a zombie!");
tmp.removeListener(listener, event);
}
}
|