summaryrefslogtreecommitdiff
path: root/same/src
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-11 14:44:37 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-11 14:44:37 +0200
commit172beb67bf3f27fe1861a94cbcaad1e4d7a2390d (patch)
tree109417f52235ce07e27f0fe92f4c8c3965f1b89a /same/src
parentd5848fd3ba97f09f7522e7efd11e97bc44fd2360 (diff)
Register network when it is created.
Diffstat (limited to 'same/src')
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java31
1 files changed, 25 insertions, 6 deletions
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 855daa7..522a0a1 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -3,13 +3,14 @@ package com.orbekk.same;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.protobuf.RpcCallback;
import com.orbekk.paxos.PaxosService;
import com.orbekk.paxos.PaxosServiceImpl;
+import com.orbekk.protobuf.Rpc;
import com.orbekk.same.config.Configuration;
+import com.orbekk.same.http.JettyServerBuilder;
import com.orbekk.same.http.ServerContainer;
import com.orbekk.same.http.StateServlet;
-import com.orbekk.same.http.JettyServerBuilder;
-import com.orbekk.same.http.TjwsServerBuilder;
public class SameController {
private Logger logger = LoggerFactory.getLogger(getClass());
@@ -34,9 +35,6 @@ public class SameController {
"MasterService.json";
master = Master.create(connections, serviceBroadcaster,
masterUrl, configuration.get("networkName"));
- if (lastKnownState == null) {
- lastKnownState = master.state;
- }
master.resumeFrom(lastKnownState, masterId);
master.start();
masterService.setService(master.getService());
@@ -124,10 +122,11 @@ public class SameController {
public void createNetwork(String networkName) {
masterController.disableMaster();
- masterController.enableMaster(null, 1);
+ masterController.enableMaster(new State(networkName), 1);
String masterUrl = configuration.get("baseUrl") +
"MasterService.json";
joinNetwork(masterUrl);
+ registerNetwork(networkName, masterUrl);
}
public void joinNetwork(String url) {
@@ -142,6 +141,26 @@ public class SameController {
return master;
}
+ public void registerNetwork(String networkName, String masterUrl) {
+ Services.Directory directory = getDirectory();
+ if (directory == null) {
+ return;
+ }
+ Services.MasterState request = Services.MasterState.newBuilder()
+ .setNetworkName(networkName)
+ .setMasterUrl(masterUrl)
+ .build();
+ final Rpc rpc = new Rpc();
+ RpcCallback<Services.Empty> done = new RpcCallback<Services.Empty>() {
+ @Override public void run(Services.Empty unused) {
+ if (!rpc.isOk()) {
+ logger.warn("Failed to register network: {}", rpc);
+ }
+ }
+ };
+ directory.registerNetwork(rpc, request, done);
+ }
+
public Services.Directory getDirectory() {
String directoryLocation = configuration.get("directoryLocation");
if (directoryLocation != null) {