Revision 2f40484b
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/library/message/EffectMessageSender.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import org.distorted.library.effect.Effect; |
23 | 23 |
|
24 |
import java.util.Vector;
|
|
24 |
import java.util.ArrayList;
|
|
25 | 25 |
|
26 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 | 27 |
/** |
... | ... | |
43 | 43 |
} |
44 | 44 |
} |
45 | 45 |
|
46 |
private static final Object mArrayLock = new Object(); |
|
46 | 47 |
private static final Object mLock = new Object(); |
47 |
private static Vector<Message> mList = null;
|
|
48 |
private static ArrayList<Message> mList = null;
|
|
48 | 49 |
private static EffectMessageSender mThis = null; |
49 | 50 |
private static volatile boolean mNotify = false; |
50 |
private static int mNumStarts = 0; |
|
51 | 51 |
|
52 |
// debug only, to be removed later |
|
53 |
private static int mNumStarts = 0; |
|
52 | 54 |
private static long mStartTime, mStopTime; |
53 | 55 |
|
54 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
69 | 71 |
|
70 | 72 |
if( mThis==null ) |
71 | 73 |
{ |
72 |
mList = new Vector<>();
|
|
74 |
mList = new ArrayList<>();
|
|
73 | 75 |
mThis = new EffectMessageSender(); |
74 | 76 |
mThis.start(); |
75 | 77 |
} |
... | ... | |
101 | 103 |
|
102 | 104 |
while(mThis!=null) |
103 | 105 |
{ |
104 |
while( mList.size()>0 )
|
|
106 |
synchronized(mArrayLock)
|
|
105 | 107 |
{ |
106 |
tmp = mList.remove(0); |
|
107 |
tmp.mListener.effectFinished(tmp.mEffectID); |
|
108 |
int size = mList.size(); |
|
109 |
|
|
110 |
for(int i=0; i<size; i++) |
|
111 |
{ |
|
112 |
tmp = mList.remove(0); |
|
113 |
tmp.mListener.effectFinished(tmp.mEffectID); |
|
114 |
} |
|
108 | 115 |
} |
109 | 116 |
|
110 | 117 |
synchronized(mLock) |
... | ... | |
131 | 138 |
{ |
132 | 139 |
long id = effect.getID(); |
133 | 140 |
|
134 |
for(int i=0; i<numListeners; i++)
|
|
141 |
synchronized(mArrayLock)
|
|
135 | 142 |
{ |
136 |
EffectListener listener = effect.removeFirstListener(); |
|
137 |
Message msg = new Message(listener,id); |
|
138 |
mList.add(msg); |
|
143 |
for(int i=0; i<numListeners; i++) |
|
144 |
{ |
|
145 |
EffectListener listener = effect.removeFirstListener(); |
|
146 |
Message msg = new Message(listener,id); |
|
147 |
mList.add(msg); |
|
148 |
} |
|
139 | 149 |
} |
140 | 150 |
|
141 | 151 |
synchronized(mLock) |
... | ... | |
161 | 171 |
{ |
162 | 172 |
if( mThis==null ) |
163 | 173 |
{ |
164 |
if( mList==null ) mList = new Vector<>();
|
|
174 |
if( mList==null ) mList = new ArrayList<>();
|
|
165 | 175 |
mThis = new EffectMessageSender(); |
166 | 176 |
mThis.start(); |
167 | 177 |
} |
Also available in: Unified diff
Improve EffectMessageSender: ArrayList with explicit locking in place of a Vector.