Revision 3bbe4d67
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/library/main/InternalMaster.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.main; |
21 | 21 |
|
22 |
import java.util.ArrayList;
|
|
22 |
import java.util.Set;
|
|
23 | 23 |
|
24 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
/** |
... | ... | |
32 | 32 |
*/ |
33 | 33 |
public class InternalMaster |
34 | 34 |
{ |
35 |
private static ArrayList<Slave> mSlaves = new ArrayList<>(); |
|
36 |
|
|
37 | 35 |
public interface Slave |
38 | 36 |
{ |
39 | 37 |
void doWork(); |
... | ... | |
50 | 48 |
|
51 | 49 |
static boolean toDo() |
52 | 50 |
{ |
53 |
Slave slave;
|
|
54 |
int num = mSlaves.size();
|
|
51 |
Set<Slave> set = InternalStackFrameList.getSet();
|
|
52 |
int numSlaves = set.size();
|
|
55 | 53 |
|
56 |
try
|
|
54 |
if( numSlaves>0 )
|
|
57 | 55 |
{ |
58 |
for(int i=0; i<num; i++)
|
|
56 |
for(Slave slave: set)
|
|
59 | 57 |
{ |
60 |
slave = mSlaves.remove(0); |
|
61 |
|
|
62 |
if( slave!=null ) slave.doWork(); |
|
63 |
} |
|
64 |
} |
|
65 |
catch(IndexOutOfBoundsException ie) |
|
66 |
{ |
|
67 |
// onDestroy must have been called, ignore |
|
58 |
if( slave!=null ) slave.doWork(); |
|
59 |
} |
|
60 |
return true; |
|
68 | 61 |
} |
69 | 62 |
|
70 |
return ( num>0 );
|
|
63 |
return false;
|
|
71 | 64 |
} |
72 | 65 |
|
73 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
74 | 67 |
|
75 | 68 |
public static void newSlave(Slave s) |
76 | 69 |
{ |
77 |
int num = mSlaves.size(); |
|
78 |
boolean found = false; |
|
79 |
Slave tmp; |
|
80 |
|
|
81 |
try |
|
82 |
{ |
|
83 |
for(int i=0; i<num; i++) |
|
84 |
{ |
|
85 |
tmp = mSlaves.get(i); |
|
86 |
|
|
87 |
if( tmp==s ) |
|
88 |
{ |
|
89 |
found = true; |
|
90 |
break; |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
catch(IndexOutOfBoundsException ie) |
|
95 |
{ |
|
96 |
// onDestroy must have been called, ignore |
|
97 |
} |
|
98 |
|
|
99 |
if( !found ) mSlaves.add(s); |
|
100 |
} |
|
101 |
|
|
102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
|
104 |
static void onDestroy() |
|
105 |
{ |
|
106 |
mSlaves.clear(); |
|
70 |
InternalStackFrameList.getSet().add(s); |
|
107 | 71 |
} |
108 | 72 |
} |
Also available in: Unified diff
Put new things to the StackFrame.