summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/NewMaster.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/NewMaster.java b/same/src/main/java/com/orbekk/same/NewMaster.java
new file mode 100644
index 0000000..161586f
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/NewMaster.java
@@ -0,0 +1,64 @@
+package com.orbekk.same;
+
+import java.util.List;
+import com.orbekk.util.WorkQueue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NewMaster {
+ private Logger logger = LoggerFactory.getLogger(getClass());
+ private final ConnectionManager connections;
+ private State state;
+ private Broadcaster broadcaster;
+
+ public static NewMaster create(ConnectionManager connections,
+ Broadcaster broadcaster, String myUrl, String networkName) {
+ State state = new State(networkName);
+ state.update(".masterUrl", myUrl, 1);
+ return new NewMaster(state, connections, broadcaster);
+ }
+
+ NewMaster(State initialState, ConnectionManager connections,
+ Broadcaster broadcaster) {
+ this.state = initialState;
+ this.connections = connections;
+ this.broadcaster = broadcaster;
+ }
+
+ private MasterService serviceImpl = new MasterService() {
+ @Override
+ public boolean updateStateRequest(String component,
+ String newData, long revision) {
+ return false;
+ }
+
+ @Override
+ public void joinNetworkRequest(String clientUrl) {
+ }
+ };
+
+ WorkQueue<String> updateStateRequestThread = new WorkQueue<String>() {
+ @Override protected void onChange() {
+ List<String> pending = getAndClear();
+ for (String componentName : pending) {
+ logger.info("Component updated: {}", componentName);
+ }
+ }
+ };
+
+ void performWork() {
+ updateStateRequestThread.performWork();
+ }
+
+ public void start() {
+ updateStateRequestThread.start();
+ }
+
+ public void interrupt() {
+ updateStateRequestThread.interrupt();
+ }
+
+ public MasterService getService() {
+ return serviceImpl;
+ }
+}