Skip to content

Commit

Permalink
Update for play 2.0.2 - make it thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
dbathily committed Jul 14, 2012
1 parent 848255f commit 3f1bd59
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions java/app/models/PaintRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

public class PaintRoom {

public String name;
// The list of all connected painters (identified by ids)
public Map<Integer, Painter> painters = new HashMap<Integer, Painter>(); // FIXME not thread safe, use ConcurrentMap
public int counter = 0; // FIXME not thread safe, use AtomicInteger
public int connections = 0; // FIXME not thread safe, use AtomicInteger
public Map<Integer, Painter> painters = new ConcurrentHashMap<Integer, models.Painter>();
public AtomicInteger counter = new AtomicInteger(0);
public AtomicInteger connections = new AtomicInteger(0);

public PaintRoom(String name) {
this.name = name;
}

public void createPainter(final WebSocket.In<JsonNode> in, final WebSocket.Out<JsonNode> out) {
counter++;
connections++;
final int pid = counter; // the painter id
counter.incrementAndGet();
connections.incrementAndGet();
final int pid = counter.intValue(); // the painter id

// in: handle messages from the painter
in.onMessage(new F.Callback<JsonNode>() {
Expand Down Expand Up @@ -67,7 +69,7 @@ public void invoke(JsonNode json) throws Throwable {
@Override
public void invoke() throws Throwable {
painters.remove(pid);
connections--;
connections.decrementAndGet();

ObjectNode json = Json.newObject();
json.put("type", "disconnect");
Expand Down
2 changes: 1 addition & 1 deletion java/project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PlayProject._
object ApplicationBuild extends Build {

val appName = "Play Painter"
val appVersion = "1.0-SNAPSHOT"
val appVersion = "1.0.1"

val appDependencies = Seq(
// Add your project dependencies here,
Expand Down
2 changes: 1 addition & 1 deletion java/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.11.2
sbt.version=0.11.3
2 changes: 1 addition & 1 deletion java/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.0")
addSbtPlugin("play" % "sbt-plugin" % "2.0.2")

0 comments on commit 3f1bd59

Please sign in to comment.