summaryrefslogtreecommitdiff
path: root/jsonrpc/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/src/main')
-rw-r--r--jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java2
-rw-r--r--jsonrpc/src/main/java/com/orbekk/same/SameState.java38
2 files changed, 34 insertions, 6 deletions
diff --git a/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java b/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java
index a946c61..27579b5 100644
--- a/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java
+++ b/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java
@@ -55,6 +55,6 @@ public class SameServiceImpl implements SameService {
@Override
public void setState(String newState) {
- logger.error("setState not implemented.");
+ sameState.setState(newState);
}
}
diff --git a/jsonrpc/src/main/java/com/orbekk/same/SameState.java b/jsonrpc/src/main/java/com/orbekk/same/SameState.java
index d44cc1d..7cc8940 100644
--- a/jsonrpc/src/main/java/com/orbekk/same/SameState.java
+++ b/jsonrpc/src/main/java/com/orbekk/same/SameState.java
@@ -16,6 +16,8 @@ public class SameState extends Thread implements UrlReceiver {
private Logger logger = LoggerFactory.getLogger(getClass());
private ConnectionManager connections;
private String currentState = "";
+ private String _setState = null;
+
private String networkName;
/**
@@ -23,11 +25,8 @@ public class SameState extends Thread implements UrlReceiver {
*/
private String masterId;
- /**
- * TODO: Remove.
- */
- public void setMasterId(String masterId) {
- this.masterId = masterId;
+ public String getMasterId() {
+ return this.masterId;
}
/**
@@ -106,6 +105,14 @@ public class SameState extends Thread implements UrlReceiver {
return currentState;
}
+ /**
+ * TODO: Move to a separate library.
+ */
+ public void librarySetNewState(String newState) {
+ connections.getConnection(participants.get(masterId))
+ .setState(newState);
+ }
+
public String getUrl() {
return participants.get(clientId);
}
@@ -128,6 +135,12 @@ public class SameState extends Thread implements UrlReceiver {
notifyAll();
}
+ public synchronized void setState(String newState) {
+ logger.info("Pending operation: _setState");
+ _setState = newState;
+ notifyAll();
+ }
+
private synchronized void handleSetParticipants() {
if (_setParticipants != null) {
if (isMaster()) {
@@ -140,6 +153,20 @@ public class SameState extends Thread implements UrlReceiver {
_setParticipants = null;
}
+ public synchronized void handleSetState() {
+ if (_setState != null) {
+ if (isMaster()) {
+ broadcast(new ServiceOperation() {
+ @Override void run(SameService service) {
+ service.setState(_setState);
+ }
+ });
+ }
+ currentState = _setState;
+ _setState = null;
+ }
+ }
+
private boolean isMaster() {
return masterId.equals(clientId);
}
@@ -181,6 +208,7 @@ public class SameState extends Thread implements UrlReceiver {
*/
synchronized void internalRun() {
handleNewParticipants();
+ handleSetState();
handleSetParticipants();
}