summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-17 14:23:25 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-17 14:23:25 +0200
commita6a1c550731caaa2e46aab2112b81f318da229aa (patch)
tree5db60653f65c3b81899a89fd370c892b07bfab32 /same/src/main/java/com
parent3abdb97eafcf7825d8f2a0bf71b5966a6e3f7c1f (diff)
Client registers with protobuf service location.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java7
-rw-r--r--same/src/main/java/com/orbekk/same/Master.java8
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java5
3 files changed, 13 insertions, 7 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 7d1ce56..6386928 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -28,6 +28,7 @@ public class Client {
private final ConnectionManager connections;
volatile State state;
private volatile String myUrl;
+ private volatile String myLocation;
volatile String masterUrl;
volatile String masterLocation;
private volatile int masterId = 0;
@@ -206,10 +207,11 @@ public class Client {
};
public Client(State state, ConnectionManager connections,
- String myUrl, Broadcaster broadcaster) {
+ String myUrl, String myLocation, Broadcaster broadcaster) {
this.state = state;
this.connections = connections;
this.myUrl = myUrl;
+ this.myLocation = myLocation;
this.broadcaster = broadcaster;
}
@@ -229,7 +231,8 @@ public class Client {
public Services.ClientState getClientState() {
return Services.ClientState.newBuilder()
- .setUrl(getUrl())
+ .setUrl(myUrl)
+ .setLocation(myLocation)
.build();
}
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java
index b2adea1..511da08 100644
--- a/same/src/main/java/com/orbekk/same/Master.java
+++ b/same/src/main/java/com/orbekk/same/Master.java
@@ -83,7 +83,7 @@ public class Master {
}
/** New participant code. */
- addParticipant(request);
+ addParticipant(request.getLocation());
done.run(Empty.getDefaultInstance());
}
@@ -199,10 +199,10 @@ public class Master {
return serviceImpl;
}
- private synchronized void addParticipant(ClientState client) {
+ private synchronized void addParticipant(String location) {
List<String> participants = state.getList(State.PARTICIPANTS);
- if (!participants.contains(client.getUrl())) {
- participants.add(client.getUrl());
+ if (!participants.contains(location)) {
+ participants.add(location);
state.updateFromObject(State.PARTICIPANTS, participants,
state.getRevision(State.PARTICIPANTS) + 1);
updateStateRequestThread.add(State.PARTICIPANTS);
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 900dcbc..b87e6f5 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -57,6 +57,8 @@ public class SameController {
public static SameController create(Configuration configuration) {
int port = configuration.getInt("port");
int pport = configuration.getInt("pport");
+ String myLocation = configuration.get("localIp") + ":" + pport;
+
ConnectionManagerImpl connections = new ConnectionManagerImpl(
timeout, timeout);
State clientState = new State(".InvalidClientNetwork");
@@ -67,7 +69,8 @@ public class SameController {
MasterServiceProxy master = new MasterServiceProxy();
Client client = new Client(clientState, connections,
- clientUrl, BroadcasterImpl.getDefaultBroadcastRunner());
+ clientUrl, myLocation,
+ BroadcasterImpl.getDefaultBroadcastRunner());
PaxosServiceImpl paxos = new PaxosServiceImpl("");
StateServlet stateServlet = new StateServlet(client.getInterface(),
new VariableFactory(client.getInterface()));