|
17 | 17 | import java.util.concurrent.ExecutorService; |
18 | 18 | import java.util.concurrent.Executors; |
19 | 19 | import java.util.concurrent.TimeUnit; |
20 | | -import java.util.concurrent.locks.Condition; |
21 | | -import java.util.concurrent.locks.Lock; |
22 | | -import java.util.concurrent.locks.ReentrantLock; |
23 | 20 |
|
24 | 21 | import org.tinystruct.AbstractApplication; |
25 | 22 | import org.tinystruct.ApplicationException; |
|
28 | 25 |
|
29 | 26 | public class talk extends AbstractApplication { |
30 | 27 |
|
31 | | - private static final long TIMEOUT = 100; |
32 | 28 | protected static final int DEFAULT_MESSAGE_POOL_SIZE = 10; |
33 | 29 | protected final Map<String, BlockingQueue<Builder>> meetings = new ConcurrentHashMap<String, BlockingQueue<Builder>>(); |
34 | 30 | protected final Map<String, Queue<Builder>> list = new ConcurrentHashMap<String, Queue<Builder>>(); |
35 | 31 | protected final Map<String, List<String>> sessions = new ConcurrentHashMap<String, List<String>>(); |
36 | 32 | private ExecutorService service; |
37 | | - private final Lock lock = new ReentrantLock(); |
38 | | - private final Condition consumer = lock.newCondition(); |
39 | 33 |
|
40 | 34 | @Override |
41 | 35 | public void init() { |
@@ -136,15 +130,9 @@ public final String update(final String sessionId) throws ApplicationException, |
136 | 130 | Queue<Builder> messages = this.list.get(sessionId); |
137 | 131 | // If there is a new message, then return it directly |
138 | 132 | if((message = messages.poll()) != null) return message.toString(); |
139 | | - lock.lock(); |
140 | 133 | while((message = messages.poll()) == null) { |
141 | | - try { |
142 | | - consumer.await(TIMEOUT, TimeUnit.MICROSECONDS); |
143 | | - } catch (InterruptedException e) { |
144 | | - throw new ApplicationException(e.getMessage(), e); |
145 | | - } |
| 134 | + ; |
146 | 135 | } |
147 | | - lock.unlock(); |
148 | 136 | return message.toString(); |
149 | 137 | } |
150 | 138 |
|
@@ -172,18 +160,15 @@ private final void copy(Object meetingCode, Builder builder) { |
172 | 160 | while(iterator.hasNext()) { |
173 | 161 | Entry<String, Queue<Builder>> list = iterator.next(); |
174 | 162 | if(_sessions.contains(list.getKey())) { |
175 | | - lock.lock(); |
176 | 163 | list.getValue().add(builder); |
177 | | - consumer.signalAll(); |
178 | | - lock.unlock(); |
179 | 164 | } |
180 | 165 | } |
181 | 166 | } |
182 | 167 | } |
183 | 168 |
|
184 | 169 | @Override |
185 | 170 | public String version() { |
186 | | - return "Welcome to use tinystruct 2.0"; |
| 171 | + return "Talk core version:1.0 stable; Released on 2017-07-24"; |
187 | 172 | } |
188 | 173 |
|
189 | 174 | /** |
|
0 commit comments