use of org.magicwerk.brownies.collections.GapList in project swiftmq-ce by iitsoftware.
the class TimerSwiftletImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
traceSpace = traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool");
if (traceSpace.enabled)
traceSpace.trace(getName(), "startup, ...");
Property prop = config.getProperty("min-delay");
minDelay = ((Long) prop.getValue()).longValue();
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
minDelay = ((Long) newValue).longValue();
}
});
prop = config.getProperty("max-delay");
maxDelay = ((Long) prop.getValue()).longValue();
timeChangeThreshold = maxDelay + MAX_DELAY_TIME_CHANGE_ADDITION;
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
maxDelay = ((Long) newValue).longValue();
timeChangeThreshold = maxDelay + MAX_DELAY_TIME_CHANGE_ADDITION;
}
});
taskPool = threadpoolSwiftlet.getPool(TP_TASK);
taskQueue = new GapList();
timerListeners = new HashMap();
sysTimeChangeListeners = new GapList();
dispatcher = new Dispatcher();
threadpoolSwiftlet.dispatchTask(dispatcher);
if (traceSpace.enabled)
traceSpace.trace(getName(), "startup, DONE");
}
use of org.magicwerk.brownies.collections.GapList in project swiftmq-ce by iitsoftware.
the class TimerSwiftletImpl method reorder.
private void reorder(long delta) {
if (traceSpace.enabled)
traceSpace.trace(getName(), "reorder, delta=" + delta + " ...");
logSwiftlet.logInformation(getName(), "System time has changed (delta=" + delta + "), reordering timer task queue");
List backup = (List) ((GapList) taskQueue).clone();
taskQueue.clear();
for (Iterator iter = backup.iterator(); iter.hasNext(); ) {
TimeTask t = (TimeTask) iter.next();
if (!t.doNotApplySystemTimeChanges) {
if (traceSpace.enabled)
traceSpace.trace(getName(), "reorder, before, t=" + t);
t.recalc(delta);
if (traceSpace.enabled)
traceSpace.trace(getName(), "reorder, after, t=" + t);
}
enqueue(t);
}
for (int i = 0; i < sysTimeChangeListeners.size(); i++) {
SystemTimeChangeListener l = null;
try {
l = (SystemTimeChangeListener) sysTimeChangeListeners.get(i);
l.systemTimeChangeDetected(delta);
} catch (Exception e) {
logSwiftlet.logInformation(getName(), "Exception calling SystemTimeChangeListener '" + l + "': " + e);
if (traceSpace.enabled)
traceSpace.trace(getName(), "Exception calling SystemTimeChangeListener '" + l + "': " + e);
}
}
if (traceSpace.enabled)
traceSpace.trace(getName(), "reorder, delta=" + delta + " done");
}
Aggregations