Skip to content

Commit cf7f6c7

Browse files
authored
Update smalltalk.java
1 parent 27d1250 commit cf7f6c7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/tinystruct/examples/smalltalk.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public talk index() {
6262

6363
List<String> session_ids;
6464
synchronized (this.meetings) {
65+
final String sessionId = request.getSession().getId();
6566
if (this.meetings.get(meetingCode) == null) {
6667
this.meetings.put(meetingCode.toString(), new ConcurrentLinkedQueue<Builder>());
6768
}
@@ -72,8 +73,8 @@ public talk index() {
7273
this.sessions.put(meetingCode.toString(), session_ids = new ArrayList<String>());
7374
}
7475

75-
if(!session_ids.contains(request.getSession().getId()))
76-
session_ids.add(request.getSession().getId());
76+
if(!session_ids.contains(sessionId))
77+
session_ids.add(sessionId);
7778

7879
this.meetings.notifyAll();
7980
}
@@ -83,8 +84,8 @@ public talk index() {
8384
if(!this.list.containsKey(sessionId))
8485
{
8586
this.list.put(sessionId, new ConcurrentLinkedQueue<Builder>());
86-
this.list.notifyAll();
8787
}
88+
this.list.notifyAll();
8889
}
8990

9091
this.setVariable("meeting_code", meetingCode.toString());
@@ -130,7 +131,8 @@ public String join(String meetingCode) throws ApplicationException {
130131
public String start(String name) throws ApplicationException {
131132
final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST");
132133
final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
133-
134+
request.getSession().setAttribute("user", name);
135+
134136
Object meetingCode = request.getSession().getAttribute("meeting_code");
135137
if (meetingCode == null) {
136138
Reforward reforward = new Reforward(request, response);
@@ -139,7 +141,6 @@ public String start(String name) throws ApplicationException {
139141
} else {
140142
this.setVariable("meeting_code", meetingCode.toString());
141143
}
142-
request.getSession().setAttribute("user", name);
143144

144145
return name;
145146
}
@@ -197,15 +198,15 @@ public String update() throws ApplicationException, IOException {
197198
final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST");
198199
final Object meetingCode = request.getSession().getAttribute("meeting_code");
199200
final String sessionId = request.getSession().getId();
200-
if ( meetingCode != null && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) {
201-
return update(sessionId);
201+
if (meetingCode != null) {
202+
return this.update(meetingCode.toString(), sessionId);
202203
}
203204
return "";
204205
}
205206

206207
public String update(String meetingCode, String sessionId) throws ApplicationException, IOException {
207-
if ( meetingCode != null && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) {
208-
return update(sessionId);
208+
if (sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) {
209+
return this.update(sessionId);
209210
}
210211
return "";
211212
}
@@ -297,8 +298,8 @@ public void sessionCreated(HttpSessionEvent arg0) {
297298
if(!this.list.containsKey(sessionId))
298299
{
299300
this.list.put(sessionId, new ConcurrentLinkedQueue<Builder>());
300-
this.list.notifyAll();
301301
}
302+
this.list.notifyAll();
302303
}
303304
}
304305

@@ -315,17 +316,17 @@ public void sessionDestroyed(HttpSessionEvent arg0) {
315316
}
316317
if ((messages = meetings.get(meetingCode)) != null) {
317318
messages.remove(meetingCode);
318-
meetings.notifyAll();
319319
}
320+
meetings.notifyAll();
320321
}
321322

322323
synchronized (this.list) {
323324
final String sessionId = arg0.getSession().getId();
324325
if(this.list.containsKey(sessionId))
325326
{
326327
this.list.remove(sessionId);
327-
this.list.notifyAll();
328328
}
329+
this.list.notifyAll();
329330
}
330331
}
331332
}

0 commit comments

Comments
 (0)