litesoft
@ 804
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 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.GWT.client.widgets.nonpublic; import org.litesoft.GWT.client.*; import org.litesoft.core.delayed.*; import org.litesoft.core.typeutils.*; public class EscalatingProcess implements TimedRunnable { private long mDelay = 0; private DelayedProcess mProcess; public EscalatingProcess( DelayedProcess pProcess ) { Objects.assertNotNull( "Process", mProcess = pProcess ); } private synchronized long initDelay() { return mDelay = 125; } private synchronized long escalateDelay() { return (1000 <= (mDelay += mDelay)) ? mDelay : (mDelay = 1000); } public synchronized void cancel() { mDelay = 0; } public synchronized boolean isLive() { return (mDelay != 0); } public void schedule() { TimedRunnableManager.INSTANCE.cancel( this ); TimedRunnableManager.INSTANCE.runIn( this, initDelay() ); } @Override public Again runOnce() { if ( isLive() ) { if ( !mProcess.process() ) { return new RunAgainIn( escalateDelay() ); } cancel(); } return null; } } |