diff options
-rw-r--r-- | same-android/src/main/java/com/orbekk/HelloAndroidActivity.java | 14 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/MasterServiceImpl.java | 17 |
2 files changed, 15 insertions, 16 deletions
diff --git a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java index 653a870..cc90a3a 100644 --- a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java +++ b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java @@ -25,16 +25,16 @@ public class HelloAndroidActivity extends Activity { System.setProperty("java.net.preferIPv6Addresses", "false"); Log.i(TAG, "onCreate"); - setContentView(R.layout.main); - + // setContentView(R.layout.main); + setContentView(new GameView(this)); // Broadcast broadcast = new Broadcast(this); // broadcast.sendBroadcast("Broadcast test".getBytes(), 10010); - Broadcaster broadcaster = new Broadcaster(); - Log.i(TAG, "Broadcast success: " + broadcaster.sendBroadcast(10010, "Broadcast test from Android".getBytes())); - - ClientApp client = new ClientApp(); - client.run(10015, "ClientNetwork", "http://10.0.0.6:10010/"); +// Broadcaster broadcaster = new Broadcaster(); +// Log.i(TAG, "Broadcast success: " + broadcaster.sendBroadcast(10010, "Broadcast test from Android".getBytes())); +// +// ClientApp client = new ClientApp(); +// client.run(10015, "ClientNetwork", "http://10.0.0.6:10010/"); } @Override diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java index ced0dba..dc5eed3 100644 --- a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java +++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java @@ -24,24 +24,22 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable { } @Override - public void joinNetworkRequest(String clientUrl) { + public synchronized void joinNetworkRequest(String clientUrl) { logger.info("JoinNetworkRequest({})", clientUrl); List<String> participants = participants(); if (!participants.contains(clientUrl)) { participants.add(clientUrl); _fullStateReceivers.add(clientUrl); - synchronized(this) { - state.updateFromObject(".participants", participants, - state.getRevision(".participants") + 1); - notifyAll(); - } + state.updateFromObject(".participants", participants, + state.getRevision(".participants") + 1); + notifyAll(); } else { logger.warn("Client {} already part of network. " + "Ignoring participation request", clientUrl); } } - public boolean _sendUpdatedComponents() { + boolean _sendUpdatedComponents() { boolean worked = false; for (final Component component : state.getAndClearUpdatedComponents()) { logger.info("Broadcasting new component {}", component); @@ -57,11 +55,12 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable { return list; } - public synchronized boolean _sendFullState() { + synchronized boolean _sendFullState() { boolean hasWork = _fullStateReceivers.size() != 0; if (hasWork) { + logger.info("Sending full state to new participants."); final List<State.Component> components = state.getComponents(); - broadcastNewComponents(participants(), components); + broadcastNewComponents(_fullStateReceivers, components); _fullStateReceivers.clear(); } return hasWork; |