summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-16 15:10:34 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-16 15:10:34 +0100
commit9444d8b16c93581bbab7928304cb14622050f691 (patch)
treeedb35293ed0880dfdb8a8b7639b76383f97c8fe7 /same/src/main/java/com
parent9742d69c56ef0866ca8b22696746b756e0670c81 (diff)
Start new Master implementation.
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;
+ }
+}