My favorites | Sign in
Project Home Source
Checkout   Browse   Changes    
 
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
package pl.fones.blog.asynctest;

/**
* Sample class which call notification callbacks.
*
* @author Wojciech Grzeskowiak
* @date 2010/05/11
* @version 1.0
* @link http://blog.fones.pl
*/
public class Engine {

// Notification interface.
private EngineNotifications notifier;

/**
* Setting notification interface.
* @param callbacks Notification interface.
*/
public void setNotifier(EngineNotifications notifier) {
this.notifier = notifier;
}

/**
* Start engine. Callback in EngineNotifications.engineStart() callback.
* @return True if conditions true, false in other way.
* @throws Exception when notification interface is not set.
*/
public boolean start() throws IllegalStateException {

// Checking conditions.
if (notifier == null) {
throw new IllegalStateException("Notification interface not set!");
}

// Creating background thread.
final Runnable callbackTask = new Runnable() {
public void run() {

// Do something...
try {
synchronized (this) {
this.wait(1000);
}
}
catch (InterruptedException e) {
// Interrupting engine cannot start.
notifier.engineStart(false);
return;
}

// Engine started.
notifier.engineStart(true);
return;
}
};

// Starting thread.
final Thread engineThread = new Thread(callbackTask);
engineThread.start();

// Finish operation.
return true;
}
}

Change log

r7 by w.grzeskowiak on Sep 20, 2010   Diff
Move Java project
Go to: 

Older revisions

All revisions of this file

File info

Size: 1872 bytes, 65 lines
Powered by Google Project Hosting