summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java2
-rw-r--r--same/src/main/java/com/orbekk/same/Master.java19
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java15
-rw-r--r--same/src/main/java/com/orbekk/same/Services.java133
-rw-r--r--same/src/main/java/com/orbekk/same/services.proto2
5 files changed, 143 insertions, 28 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index bd13576..257735c 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -155,6 +155,8 @@ public class Client {
@Override
public void setState(String component, String data, long revision) throws Exception {
+ logger.info("SetState: {}, {}, {}",
+ new Object[]{component, data, revision});
Services.Component request = Services.Component.newBuilder()
.setId(component)
.setData(data)
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java
index 4610540..1b2fbee 100644
--- a/same/src/main/java/com/orbekk/same/Master.java
+++ b/same/src/main/java/com/orbekk/same/Master.java
@@ -19,23 +19,34 @@ 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
State state;
private Broadcaster broadcaster;
private volatile int masterId = 1;
public static Master create(ConnectionManager connections,
- Broadcaster broadcaster, String myUrl, String networkName) {
+ Broadcaster broadcaster, String myUrl, String networkName,
+ String myLocation) {
State state = new State(networkName);
state.update(".masterUrl", myUrl, 1);
- return new Master(state, connections, broadcaster, myUrl);
+ return new Master(state, connections, broadcaster, myUrl, myLocation);
}
Master(State initialState, ConnectionManager connections,
- Broadcaster broadcaster, String myUrl) {
+ Broadcaster broadcaster, String myUrl, String myLocation) {
this.state = initialState;
this.connections = connections;
this.broadcaster = broadcaster;
this.myUrl = myUrl;
+ this.myLocation = myLocation;
+ }
+
+ public String getNetworkName() {
+ return state.getDataOf(".networkName");
+ }
+
+ public String getLocation() {
+ return myLocation;
}
public String getUrl() {
@@ -202,6 +213,8 @@ public class 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;
broadcaster.broadcast(state.getList(".participants"),
new ServiceOperation() {
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 78eed7a..a68290d 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -33,10 +33,12 @@ public class SameController {
private MasterController masterController = new MasterController() {
@Override
public void enableMaster(State lastKnownState, int masterId) {
+ String myLocation = configuration.get("localIp") + ":" +
+ configuration.get("pport");
String masterUrl = configuration.get("baseUrl") +
"MasterService.json";
master = Master.create(connections, serviceBroadcaster,
- masterUrl, configuration.get("networkName"));
+ masterUrl, configuration.get("networkName"), myLocation);
master.resumeFrom(lastKnownState, masterId);
pServer.registerService(master.getNewService());
master.start();
@@ -54,6 +56,7 @@ public class SameController {
public static SameController create(Configuration configuration) {
int port = configuration.getInt("port");
+ int pport = configuration.getInt("pport");
ConnectionManagerImpl connections = new ConnectionManagerImpl(
timeout, timeout);
State clientState = new State(".InvalidClientNetwork");
@@ -75,7 +78,7 @@ public class SameController {
.withService(paxos, PaxosService.class)
.build();
- SimpleProtobufServer pServer = SimpleProtobufServer.create(port + 1337);
+ SimpleProtobufServer pServer = SimpleProtobufServer.create(pport);
SameController controller = new SameController(
configuration, connections, server, master, client,
@@ -136,7 +139,6 @@ public class SameController {
String masterUrl = configuration.get("baseUrl") +
"MasterService.json";
joinNetwork(masterUrl);
- registerNetwork(networkName, masterUrl);
}
public void joinNetwork(String url) {
@@ -151,14 +153,15 @@ public class SameController {
return master;
}
- public void registerNetwork(String networkName, String masterUrl) {
+ public void registerNetwork(Master master) {
Services.Directory directory = getDirectory();
if (directory == null) {
return;
}
Services.MasterState request = Services.MasterState.newBuilder()
- .setNetworkName(networkName)
- .setMasterUrl(masterUrl)
+ .setNetworkName(master.getNetworkName())
+ .setMasterUrl(master.getUrl())
+ .setMasterLocation(master.getLocation())
.build();
final Rpc rpc = new Rpc();
RpcCallback<Services.Empty> done = new RpcCallback<Services.Empty>() {
diff --git a/same/src/main/java/com/orbekk/same/Services.java b/same/src/main/java/com/orbekk/same/Services.java
index 5418558..864da1b 100644
--- a/same/src/main/java/com/orbekk/same/Services.java
+++ b/same/src/main/java/com/orbekk/same/Services.java
@@ -1194,6 +1194,10 @@ public final class Services {
// optional string network_name = 3;
boolean hasNetworkName();
String getNetworkName();
+
+ // optional string master_location = 4;
+ boolean hasMasterLocation();
+ String getMasterLocation();
}
public static final class MasterState extends
com.google.protobuf.GeneratedMessage
@@ -1298,10 +1302,43 @@ public final class Services {
}
}
+ // optional string master_location = 4;
+ public static final int MASTER_LOCATION_FIELD_NUMBER = 4;
+ private java.lang.Object masterLocation_;
+ public boolean hasMasterLocation() {
+ return ((bitField0_ & 0x00000008) == 0x00000008);
+ }
+ public String getMasterLocation() {
+ java.lang.Object ref = masterLocation_;
+ if (ref instanceof String) {
+ return (String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ String s = bs.toStringUtf8();
+ if (com.google.protobuf.Internal.isValidUtf8(bs)) {
+ masterLocation_ = s;
+ }
+ return s;
+ }
+ }
+ private com.google.protobuf.ByteString getMasterLocationBytes() {
+ java.lang.Object ref = masterLocation_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8((String) ref);
+ masterLocation_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
private void initFields() {
masterUrl_ = "";
masterId_ = 0;
networkName_ = "";
+ masterLocation_ = "";
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -1324,6 +1361,9 @@ public final class Services {
if (((bitField0_ & 0x00000004) == 0x00000004)) {
output.writeBytes(3, getNetworkNameBytes());
}
+ if (((bitField0_ & 0x00000008) == 0x00000008)) {
+ output.writeBytes(4, getMasterLocationBytes());
+ }
getUnknownFields().writeTo(output);
}
@@ -1345,6 +1385,10 @@ public final class Services {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(3, getNetworkNameBytes());
}
+ if (((bitField0_ & 0x00000008) == 0x00000008)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(4, getMasterLocationBytes());
+ }
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -1475,6 +1519,8 @@ public final class Services {
bitField0_ = (bitField0_ & ~0x00000002);
networkName_ = "";
bitField0_ = (bitField0_ & ~0x00000004);
+ masterLocation_ = "";
+ bitField0_ = (bitField0_ & ~0x00000008);
return this;
}
@@ -1525,6 +1571,10 @@ public final class Services {
to_bitField0_ |= 0x00000004;
}
result.networkName_ = networkName_;
+ if (((from_bitField0_ & 0x00000008) == 0x00000008)) {
+ to_bitField0_ |= 0x00000008;
+ }
+ result.masterLocation_ = masterLocation_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -1550,6 +1600,9 @@ public final class Services {
if (other.hasNetworkName()) {
setNetworkName(other.getNetworkName());
}
+ if (other.hasMasterLocation()) {
+ setMasterLocation(other.getMasterLocation());
+ }
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -1596,6 +1649,11 @@ public final class Services {
networkName_ = input.readBytes();
break;
}
+ case 34: {
+ bitField0_ |= 0x00000008;
+ masterLocation_ = input.readBytes();
+ break;
+ }
}
}
}
@@ -1695,6 +1753,42 @@ public final class Services {
onChanged();
}
+ // optional string master_location = 4;
+ private java.lang.Object masterLocation_ = "";
+ public boolean hasMasterLocation() {
+ return ((bitField0_ & 0x00000008) == 0x00000008);
+ }
+ public String getMasterLocation() {
+ java.lang.Object ref = masterLocation_;
+ if (!(ref instanceof String)) {
+ String s = ((com.google.protobuf.ByteString) ref).toStringUtf8();
+ masterLocation_ = s;
+ return s;
+ } else {
+ return (String) ref;
+ }
+ }
+ public Builder setMasterLocation(String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000008;
+ masterLocation_ = value;
+ onChanged();
+ return this;
+ }
+ public Builder clearMasterLocation() {
+ bitField0_ = (bitField0_ & ~0x00000008);
+ masterLocation_ = getDefaultInstance().getMasterLocation();
+ onChanged();
+ return this;
+ }
+ void setMasterLocation(com.google.protobuf.ByteString value) {
+ bitField0_ |= 0x00000008;
+ masterLocation_ = value;
+ onChanged();
+ }
+
// @@protoc_insertion_point(builder_scope:com.orbekk.same.MasterState)
}
@@ -3598,25 +3692,26 @@ public final class Services {
".proto\022\017com.orbekk.same\"\007\n\005Empty\"*\n\027Upda" +
"teComponentResponse\022\017\n\007success\030\001 \002(\010\"7\n\t" +
"Component\022\n\n\002id\030\001 \002(\t\022\014\n\004data\030\002 \002(\t\022\020\n\010r" +
- "evision\030\003 \002(\003\"J\n\013MasterState\022\022\n\nmaster_u" +
+ "evision\030\003 \002(\003\"c\n\013MasterState\022\022\n\nmaster_u" +
"rl\030\001 \001(\t\022\021\n\tmaster_id\030\002 \001(\005\022\024\n\014network_n" +
- "ame\030\003 \001(\t\"\032\n\013ClientState\022\013\n\003url\030\001 \001(\t\"A\n" +
- "\020NetworkDirectory\022-\n\007network\030\001 \003(\0132\034.com" +
- ".orbekk.same.MasterState2\324\001\n\006Client\022>\n\010S" +
- "etState\022\032.com.orbekk.same.Component\032\026.co",
- "m.orbekk.same.Empty\022F\n\016MasterTakeover\022\034." +
- "com.orbekk.same.MasterState\032\026.com.orbekk" +
- ".same.Empty\022B\n\nMasterDown\022\034.com.orbekk.s" +
- "ame.MasterState\032\026.com.orbekk.same.Empty2" +
- "\260\001\n\006Master\022J\n\022JoinNetworkRequest\022\034.com.o" +
- "rbekk.same.ClientState\032\026.com.orbekk.same" +
- ".Empty\022Z\n\022UpdateStateRequest\022\032.com.orbek" +
- "k.same.Component\032(.com.orbekk.same.Updat" +
- "eComponentResponse2\236\001\n\tDirectory\022G\n\017Regi" +
- "sterNetwork\022\034.com.orbekk.same.MasterStat",
- "e\032\026.com.orbekk.same.Empty\022H\n\013GetNetworks" +
- "\022\026.com.orbekk.same.Empty\032!.com.orbekk.sa" +
- "me.NetworkDirectoryB\003\210\001\001"
+ "ame\030\003 \001(\t\022\027\n\017master_location\030\004 \001(\t\"\032\n\013Cl" +
+ "ientState\022\013\n\003url\030\001 \001(\t\"A\n\020NetworkDirecto" +
+ "ry\022-\n\007network\030\001 \003(\0132\034.com.orbekk.same.Ma" +
+ "sterState2\324\001\n\006Client\022>\n\010SetState\022\032.com.o",
+ "rbekk.same.Component\032\026.com.orbekk.same.E" +
+ "mpty\022F\n\016MasterTakeover\022\034.com.orbekk.same" +
+ ".MasterState\032\026.com.orbekk.same.Empty\022B\n\n" +
+ "MasterDown\022\034.com.orbekk.same.MasterState" +
+ "\032\026.com.orbekk.same.Empty2\260\001\n\006Master\022J\n\022J" +
+ "oinNetworkRequest\022\034.com.orbekk.same.Clie" +
+ "ntState\032\026.com.orbekk.same.Empty\022Z\n\022Updat" +
+ "eStateRequest\022\032.com.orbekk.same.Componen" +
+ "t\032(.com.orbekk.same.UpdateComponentRespo" +
+ "nse2\236\001\n\tDirectory\022G\n\017RegisterNetwork\022\034.c",
+ "om.orbekk.same.MasterState\032\026.com.orbekk." +
+ "same.Empty\022H\n\013GetNetworks\022\026.com.orbekk.s" +
+ "ame.Empty\032!.com.orbekk.same.NetworkDirec" +
+ "toryB\003\210\001\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -3652,7 +3747,7 @@ public final class Services {
internal_static_com_orbekk_same_MasterState_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_com_orbekk_same_MasterState_descriptor,
- new java.lang.String[] { "MasterUrl", "MasterId", "NetworkName", },
+ new java.lang.String[] { "MasterUrl", "MasterId", "NetworkName", "MasterLocation", },
com.orbekk.same.Services.MasterState.class,
com.orbekk.same.Services.MasterState.Builder.class);
internal_static_com_orbekk_same_ClientState_descriptor =
diff --git a/same/src/main/java/com/orbekk/same/services.proto b/same/src/main/java/com/orbekk/same/services.proto
index 4358098..f5cad7d 100644
--- a/same/src/main/java/com/orbekk/same/services.proto
+++ b/same/src/main/java/com/orbekk/same/services.proto
@@ -15,10 +15,12 @@ message Component {
required int64 revision = 3;
}
+// Next tag: 5
message MasterState {
optional string master_url = 1;
optional int32 master_id = 2;
optional string network_name = 3;
+ optional string master_location = 4;
}
message ClientState {