25
25
26
26
public class talk extends AbstractApplication {
27
27
28
- private static final long TIMEOUT = 10 ;
28
+ private static final long TIMEOUT = 1 ;
29
29
private static final int DEFAULT_POOL_SIZE = 3 ;
30
30
protected static final int DEFAULT_MESSAGE_POOL_SIZE = 10 ;
31
31
protected final Map <String , BlockingQueue <Builder >> meetings = new ConcurrentHashMap <String , BlockingQueue <Builder >>();
@@ -94,8 +94,7 @@ public String save(Object meetingCode, String sessionId, String message) {
94
94
public final String save (final Object meetingCode , final Builder builder ) {
95
95
BlockingQueue <Builder > messages ;
96
96
if ((messages = this .meetings .get (meetingCode )) == null ) {
97
- messages = new ArrayBlockingQueue <Builder >(DEFAULT_MESSAGE_POOL_SIZE );
98
- this .meetings .put (meetingCode .toString (), messages );
97
+ this .meetings .put (meetingCode .toString (), messages = new ArrayBlockingQueue <Builder >(DEFAULT_MESSAGE_POOL_SIZE ));
99
98
}
100
99
101
100
try {
@@ -115,7 +114,6 @@ public void run() {
115
114
e .printStackTrace ();
116
115
}
117
116
} while (talk .this .meetings .get (meetingCode ) == null || (message = talk .this .meetings .get (meetingCode ).poll ()) == null );
118
-
119
117
talk .this .copy (meetingCode , message );
120
118
}
121
119
});
@@ -135,19 +133,16 @@ private ExecutorService getService() {
135
133
*/
136
134
public final String update (final String sessionId ) throws ApplicationException , IOException {
137
135
Builder message ;
138
- Queue <Builder > messages ;
139
- synchronized (this .list ) {
140
- messages = this .list .get (sessionId );
141
- while ((message = messages .poll ()) == null ) {
142
- try {
143
- this .list .wait (TIMEOUT );
144
- } catch (InterruptedException e ) {
145
- throw new ApplicationException (e .getMessage (), e );
146
- }
136
+ Queue <Builder > messages = this .list .get (sessionId );
137
+ while ((message = messages .poll ()) == null ) {
138
+ try {
139
+ Thread .sleep (TIMEOUT );
140
+ } catch (InterruptedException e ) {
141
+ throw new ApplicationException (e .getMessage (), e );
147
142
}
148
-
149
- return message .toString ();
150
143
}
144
+
145
+ return message .toString ();
151
146
}
152
147
153
148
/**
@@ -165,22 +160,17 @@ protected String filter(String text) {
165
160
* @param builder
166
161
*/
167
162
private final void copy (Object meetingCode , Builder builder ) {
168
- synchronized (this .list ) {
169
- final Collection <Entry <String , Queue <Builder >>> set = list .entrySet ();
163
+ final Collection <Entry <String , Queue <Builder >>> set = this .list .entrySet ();
170
164
final Iterator <Entry <String , Queue <Builder >>> iterator = set .iterator ();
171
- final List <String > meeting_session ;
172
- if ((meeting_session = this .sessions .get (meetingCode )) != null ) {
165
+ final List <String > _sessions ;
166
+ if ((_sessions = this .sessions .get (meetingCode )) != null ) {
173
167
while (iterator .hasNext ()) {
174
- Entry <String , Queue <Builder >> e = iterator .next ();
175
- if (meeting_session .contains (e .getKey ())) {
176
- e .getValue ().add (builder );
177
- this .list .notifyAll ();
168
+ Entry <String , Queue <Builder >> list = iterator .next ();
169
+ if (_sessions .contains (list .getKey ())) {
170
+ list .getValue ().add (builder );
178
171
}
179
172
}
180
173
}
181
- else
182
- this .list .notifyAll ();
183
- }
184
174
}
185
175
186
176
@ Override
0 commit comments