Line | |
---|
1 | package com.framsticks.core; |
---|
2 | |
---|
3 | import com.framsticks.util.*; |
---|
4 | import com.framsticks.util.Thread; |
---|
5 | import org.apache.log4j.Logger; |
---|
6 | |
---|
7 | import java.util.HashSet; |
---|
8 | import java.util.Set; |
---|
9 | |
---|
10 | /** |
---|
11 | * @author Piotr Sniegowski |
---|
12 | */ |
---|
13 | public abstract class Entity extends Parameters implements Dispatcher { |
---|
14 | |
---|
15 | private final static Logger LOGGER = Logger.getLogger(Entity.class.getName()); |
---|
16 | |
---|
17 | public Entity(Parameters parameters) { |
---|
18 | super(parameters); |
---|
19 | if (dispatcher == null) { |
---|
20 | dispatcher = new Thread(name); |
---|
21 | } |
---|
22 | } |
---|
23 | |
---|
24 | @Override |
---|
25 | public final boolean isActive() { |
---|
26 | return dispatcher.isActive(); |
---|
27 | } |
---|
28 | |
---|
29 | @Override |
---|
30 | public final void invokeLater(Runnable runnable) { |
---|
31 | dispatcher.invokeLater(runnable); |
---|
32 | } |
---|
33 | |
---|
34 | protected void run() { |
---|
35 | assert isActive(); |
---|
36 | LOGGER.info("running: " + this); |
---|
37 | } |
---|
38 | |
---|
39 | public final void configurePublic() { |
---|
40 | configure(); |
---|
41 | } |
---|
42 | |
---|
43 | protected void configure() { |
---|
44 | |
---|
45 | } |
---|
46 | |
---|
47 | public Dispatcher getDispatcher() { |
---|
48 | return dispatcher; |
---|
49 | } |
---|
50 | |
---|
51 | public final void start() { |
---|
52 | invokeLater(new Runnable() { |
---|
53 | @Override |
---|
54 | public void run() { |
---|
55 | Entity.this.run(); |
---|
56 | } |
---|
57 | }); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.