Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/tinystruct/examples/smalltalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,18 @@ public String update() throws ApplicationException, IOException {
}

public String update(String meetingCode, String sessionId) throws ApplicationException, IOException {
String error = "{ \"error\": \"expired\" }";
if (this.meetings.containsKey(meetingCode)) {
if(sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) {
return this.update(sessionId);
}
final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
response.setContentType("application/json");
response.setStatus(403);
return "{ \"error\": \"session-timeout\" }";
error = "{ \"error\": \"session-timeout\" }";
}

final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
response.setContentType("application/json");
response.setStatus(403);
return "{ \"error\": \"expired\" }";
return error;
}

public String upload() throws ApplicationException {
Expand Down Expand Up @@ -329,19 +327,19 @@ public void sessionDestroyed(HttpSessionEvent arg0) {
builder.put("time", format.format(new Date()));
builder.put("cmd", "expired");
this.save(meetingCode, builder);

Queue<Builder> messages;
List<String> session_ids;
synchronized (meetings) {
synchronized (this.meetings) {
if((session_ids = this.sessions.get(meetingCode)) != null) {
session_ids.remove(arg0.getSession().getId());
}
if ((messages = meetings.get(meetingCode)) != null) {

if ((messages = this.meetings.get(meetingCode)) != null) {
messages.remove(meetingCode);
}
meetings.notifyAll();

this.meetings.notifyAll();
}

synchronized (this.list) {
Expand Down
6 changes: 3 additions & 3 deletions src/tinystruct/examples/talk.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ public void run() {
* @throws IOException
*/
public final String update(final String sessionId) throws ApplicationException, IOException {
Builder message;
Builder message = null;
Queue<Builder> messages;
synchronized (this.list) {
messages = this.list.get(sessionId);
while((message = messages.poll()) == null) {
while(messages != null && (message = messages.poll()) == null) {
try {
this.list.wait(TIMEOUT);
} catch (InterruptedException e) {
throw new ApplicationException(e.getMessage(), e);
}
}

return message.toString();
return message != null ? message.toString() : "";
}
}

Expand Down