summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java7
-rw-r--r--same/src/main/java/com/orbekk/same/Master.java26
-rw-r--r--same/src/main/java/com/orbekk/same/MasterController.java2
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java7
-rw-r--r--same/src/main/java/com/orbekk/same/State.java4
5 files changed, 15 insertions, 31 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 2479591..5f9cfd4 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -154,9 +154,7 @@ public class Client {
if (masterInfo != null &&
request.getMasterId() <= masterInfo.getMasterId()) {
logger.warn("{} tried to take over, but current master is " +
- "{}:{}. Ignoring", new Object[]{request,
- state.getDataOf(".masterUrl"),
- masterInfo.getMasterId()});
+ "{}. Ignoring", masterInfo);
return;
}
abortMasterElection();
@@ -223,7 +221,8 @@ public class Client {
}
if (!currentMasterProposal.isCancelled() && result != null &&
masterInfo.getMasterId() <= failedMaster.getMasterId()) {
- masterController.enableMaster(new State(state), result);
+ masterController.enableMaster(failedMaster.getNetworkName(),
+ new State(state), result);
} else {
logger.info("Master election aborted. Master already chosen.");
}
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java
index 4327a7a..473fd1e 100644
--- a/same/src/main/java/com/orbekk/same/Master.java
+++ b/same/src/main/java/com/orbekk/same/Master.java
@@ -17,7 +17,6 @@ package com.orbekk.same;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
@@ -28,15 +27,14 @@ import com.google.protobuf.RpcController;
import com.orbekk.protobuf.Rpc;
import com.orbekk.same.Services.ClientState;
import com.orbekk.same.Services.Empty;
-import com.orbekk.same.Services.UpdateComponentResponse;
import com.orbekk.same.State.Component;
import com.orbekk.util.WorkQueue;
public class Master {
private Logger logger = LoggerFactory.getLogger(getClass());
private final ConnectionManager connections;
- private String myUrl;
private String myLocation; // Protobuf server location, i.e., myIp:port
+ private String networkName;
private AtomicLong revision = new AtomicLong(1);
State state;
private volatile int masterId = 1;
@@ -65,36 +63,29 @@ public class Master {
public static Master create(ConnectionManager connections,
String myUrl, String networkName,
String myLocation, RpcFactory rpcf) {
- State state = new State(networkName);
- state.update(".masterUrl", myUrl, 1);
- state.update(".masterLocation", myLocation, 1);
- return new Master(state, connections, myUrl, myLocation, rpcf);
+ State state = new State();
+ return new Master(state, connections, networkName, myLocation, rpcf);
}
Master(State initialState, ConnectionManager connections,
- String myUrl, String myLocation, RpcFactory rpcf) {
+ String networkName, String myLocation, RpcFactory rpcf) {
this.state = initialState;
this.connections = connections;
- this.myUrl = myUrl;
this.myLocation = myLocation;
+ this.networkName = networkName;
this.rpcf = rpcf;
}
public String getNetworkName() {
- return state.getDataOf(".networkName");
+ return networkName;
}
public String getLocation() {
return myLocation;
}
- public String getUrl() {
- return myUrl;
- }
-
public Services.MasterState getMasterInfo() {
return Services.MasterState.newBuilder()
- .setMasterUrl(getUrl())
.setMasterLocation(getLocation())
.setNetworkName(getNetworkName())
.setMasterId(masterId)
@@ -247,9 +238,6 @@ public class Master {
/** This master should take over from an earlier master. */
public void resumeFrom(State lastKnownState, final int masterId) {
state = lastKnownState;
- state.update(".masterUrl", myUrl, state.getRevision(".masterUrl") + 100);
- state.update(".masterLocation", myLocation,
- state.getRevision(".masterLocation") + 100);
this.masterId = masterId;
for (final String location : state.getList(State.PARTICIPANTS)) {
@@ -268,7 +256,5 @@ public class Master {
}
client.masterTakeover(rpc, getMasterInfo(), done);
}
- updateStateRequestThread.add(".masterUrl");
- updateStateRequestThread.add(".masterLocation");
}
}
diff --git a/same/src/main/java/com/orbekk/same/MasterController.java b/same/src/main/java/com/orbekk/same/MasterController.java
index 712524d..59cbfcc 100644
--- a/same/src/main/java/com/orbekk/same/MasterController.java
+++ b/same/src/main/java/com/orbekk/same/MasterController.java
@@ -16,6 +16,6 @@
package com.orbekk.same;
public interface MasterController {
- void enableMaster(State lastKnownState, int masterId);
+ void enableMaster(String networkName, State lastKnownState, int masterId);
void disableMaster();
}
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 9f1f9d2..6a0456d 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -93,7 +93,8 @@ public class SameController {
private MasterController masterController = new MasterController() {
@Override
- public void enableMaster(State lastKnownState, int masterId) {
+ public void enableMaster(String networkName,
+ State lastKnownState, int masterId) {
String myLocation = configuration.get("localIp") + ":" +
configuration.get("pport");
String masterUrl = configuration.get("baseUrl") +
@@ -140,7 +141,7 @@ public class SameController {
timeout, timeout);
RpcFactory rpcf = new RpcFactory(timeout);
- State clientState = new State(".InvalidClientNetwork");
+ State clientState = new State();
String baseUrl = String.format("http://%s:%s/",
configuration.get("localIp"), configuration.getInt("port"));
String clientUrl = baseUrl + "ClientService.json";
@@ -204,7 +205,7 @@ public class SameController {
public void createNetwork(String networkName) {
masterController.disableMaster();
- masterController.enableMaster(new State(networkName), 1);
+ masterController.enableMaster(networkName, new State(), 1);
joinNetwork(master.getMasterInfo());
}
diff --git a/same/src/main/java/com/orbekk/same/State.java b/same/src/main/java/com/orbekk/same/State.java
index 262fef0..d9f3cc0 100644
--- a/same/src/main/java/com/orbekk/same/State.java
+++ b/same/src/main/java/com/orbekk/same/State.java
@@ -41,9 +41,7 @@ public class State {
public static final String PARTICIPANTS = ".participants0";
- public State(String networkName) {
- update(".networkName", networkName, 1);
- updateFromObject(".participants", new ArrayList<String>(), 1);
+ public State() {
updateFromObject(PARTICIPANTS, new ArrayList<String>(), 1);
}