litesoft
Diff Revisions
949
vs
950
for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/EscalatingProcess.java
|
@@ -1,47 +1,47 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.*; |
5 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
6 |
|
- |
import org.litesoft.core.delayed.*; |
7 |
|
- |
|
8 |
|
- |
public class EscalatingProcess implements TimedRunnable { |
9 |
|
- |
private long mDelay = 0; |
10 |
|
- |
private DelayedProcess mProcess; |
11 |
|
- |
|
12 |
|
- |
public EscalatingProcess( DelayedProcess pProcess ) { |
13 |
|
- |
Objects.assertNotNull( "Process", mProcess = pProcess ); |
14 |
|
- |
} |
15 |
|
- |
|
16 |
|
- |
private synchronized long initDelay() { |
17 |
|
- |
return mDelay = 125; |
18 |
|
- |
} |
19 |
|
- |
|
20 |
|
- |
private synchronized long escalateDelay() { |
21 |
|
- |
return (1000 <= (mDelay += mDelay)) ? mDelay : (mDelay = 1000); |
22 |
|
- |
} |
23 |
|
- |
|
24 |
|
- |
public synchronized void cancel() { |
25 |
|
- |
mDelay = 0; |
26 |
|
- |
} |
27 |
|
- |
|
28 |
|
- |
public synchronized boolean isLive() { |
29 |
|
- |
return (mDelay != 0); |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
public void schedule() { |
33 |
|
- |
TimedRunnableManager.INSTANCE.cancel( this ); |
34 |
|
- |
TimedRunnableManager.INSTANCE.runIn( this, initDelay() ); |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
@Override |
38 |
|
- |
public Again runOnce() { |
39 |
|
- |
if ( isLive() ) { |
40 |
|
- |
if ( !mProcess.process() ) { |
41 |
|
- |
return new RunAgainIn( escalateDelay() ); |
42 |
|
- |
} |
43 |
|
- |
cancel(); |
44 |
|
- |
} |
45 |
|
- |
return null; |
46 |
|
- |
} |
47 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
6 |
+ |
import org.litesoft.core.delayed.*; |
|
7 |
+ |
|
|
8 |
+ |
public class EscalatingProcess implements TimedRunnable { |
|
9 |
+ |
private long mDelay = 0; |
|
10 |
+ |
private DelayedProcess mProcess; |
|
11 |
+ |
|
|
12 |
+ |
public EscalatingProcess( DelayedProcess pProcess ) { |
|
13 |
+ |
Confirm.isNotNull( "Process", mProcess = pProcess ); |
|
14 |
+ |
} |
|
15 |
+ |
|
|
16 |
+ |
private synchronized long initDelay() { |
|
17 |
+ |
return mDelay = 125; |
|
18 |
+ |
} |
|
19 |
+ |
|
|
20 |
+ |
private synchronized long escalateDelay() { |
|
21 |
+ |
return (1000 <= (mDelay += mDelay)) ? mDelay : (mDelay = 1000); |
|
22 |
+ |
} |
|
23 |
+ |
|
|
24 |
+ |
public synchronized void cancel() { |
|
25 |
+ |
mDelay = 0; |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
public synchronized boolean isLive() { |
|
29 |
+ |
return (mDelay != 0); |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
public void schedule() { |
|
33 |
+ |
TimedRunnableManager.INSTANCE.cancel( this ); |
|
34 |
+ |
TimedRunnableManager.INSTANCE.runIn( this, initDelay() ); |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
@Override |
|
38 |
+ |
public Again runOnce() { |
|
39 |
+ |
if ( isLive() ) { |
|
40 |
+ |
if ( !mProcess.process() ) { |
|
41 |
+ |
return new RunAgainIn( escalateDelay() ); |
|
42 |
+ |
} |
|
43 |
+ |
cancel(); |
|
44 |
+ |
} |
|
45 |
+ |
return null; |
|
46 |
+ |
} |
|
47 |
+ |
} |