summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-05-07 14:00:14 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-05-07 14:00:14 +0200
commitacb7a2cd0794d8ed6f623ad6b279f193aa76188e (patch)
treedfc13baff049a4e399c84ec2da61c93bb64520da /same/src/main/java/com
parent9fc7d7a372301715745d4ef85cc2f7eba8a555a9 (diff)
Client keeps revision field.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java13
-rw-r--r--same/src/main/java/com/orbekk/same/Services.java114
-rw-r--r--same/src/main/java/com/orbekk/same/services.proto1
3 files changed, 100 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 0ee4c10..2479591 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -21,6 +21,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,6 +50,7 @@ public class Client {
private final RpcFactory rpcf;
private final ExecutorService executor;
private final ClientInterface clientInterface = new ClientInterfaceImpl();
+ private final AtomicLong revision = new AtomicLong(0);
private List<StateChangedListener> stateListeners =
new ArrayList<StateChangedListener>();
@@ -136,6 +138,7 @@ public class Client {
for (StateChangedListener listener : stateListeners) {
listener.stateChanged(state.getComponent(request.getId()));
}
+ updateRevision(request.getRevision());
} else {
logger.warn("Ignoring update: {) => {}",
state.getComponent(request.getId()),
@@ -257,6 +260,7 @@ public class Client {
return Services.ClientState.newBuilder()
.setUrl(myUrl)
.setLocation(myLocation)
+ .setRevision(revision.get())
.build();
}
@@ -337,4 +341,13 @@ public class Client {
}
}
}
+
+ public void updateRevision(long newRevision) {
+ boolean updated = false;
+ while (!updated) {
+ long expected = revision.get();
+ long update = Math.max(expected, newRevision);
+ updated = revision.compareAndSet(expected, update);
+ }
+ }
}
diff --git a/same/src/main/java/com/orbekk/same/Services.java b/same/src/main/java/com/orbekk/same/Services.java
index 8e08529..313a0b5 100644
--- a/same/src/main/java/com/orbekk/same/Services.java
+++ b/same/src/main/java/com/orbekk/same/Services.java
@@ -3480,6 +3480,10 @@ public final class Services {
// optional string location = 2;
boolean hasLocation();
String getLocation();
+
+ // optional int64 revision = 3;
+ boolean hasRevision();
+ long getRevision();
}
public static final class ClientState extends
com.google.protobuf.GeneratedMessage
@@ -3574,9 +3578,20 @@ public final class Services {
}
}
+ // optional int64 revision = 3;
+ public static final int REVISION_FIELD_NUMBER = 3;
+ private long revision_;
+ public boolean hasRevision() {
+ return ((bitField0_ & 0x00000004) == 0x00000004);
+ }
+ public long getRevision() {
+ return revision_;
+ }
+
private void initFields() {
url_ = "";
location_ = "";
+ revision_ = 0L;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -3596,6 +3611,9 @@ public final class Services {
if (((bitField0_ & 0x00000002) == 0x00000002)) {
output.writeBytes(2, getLocationBytes());
}
+ if (((bitField0_ & 0x00000004) == 0x00000004)) {
+ output.writeInt64(3, revision_);
+ }
getUnknownFields().writeTo(output);
}
@@ -3613,6 +3631,10 @@ public final class Services {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(2, getLocationBytes());
}
+ if (((bitField0_ & 0x00000004) == 0x00000004)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt64Size(3, revision_);
+ }
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -3741,6 +3763,8 @@ public final class Services {
bitField0_ = (bitField0_ & ~0x00000001);
location_ = "";
bitField0_ = (bitField0_ & ~0x00000002);
+ revision_ = 0L;
+ bitField0_ = (bitField0_ & ~0x00000004);
return this;
}
@@ -3787,6 +3811,10 @@ public final class Services {
to_bitField0_ |= 0x00000002;
}
result.location_ = location_;
+ if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
+ to_bitField0_ |= 0x00000004;
+ }
+ result.revision_ = revision_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -3809,6 +3837,9 @@ public final class Services {
if (other.hasLocation()) {
setLocation(other.getLocation());
}
+ if (other.hasRevision()) {
+ setRevision(other.getRevision());
+ }
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -3850,6 +3881,11 @@ public final class Services {
location_ = input.readBytes();
break;
}
+ case 24: {
+ bitField0_ |= 0x00000004;
+ revision_ = input.readInt64();
+ break;
+ }
}
}
}
@@ -3928,6 +3964,27 @@ public final class Services {
onChanged();
}
+ // optional int64 revision = 3;
+ private long revision_ ;
+ public boolean hasRevision() {
+ return ((bitField0_ & 0x00000004) == 0x00000004);
+ }
+ public long getRevision() {
+ return revision_;
+ }
+ public Builder setRevision(long value) {
+ bitField0_ |= 0x00000004;
+ revision_ = value;
+ onChanged();
+ return this;
+ }
+ public Builder clearRevision() {
+ bitField0_ = (bitField0_ & ~0x00000004);
+ revision_ = 0L;
+ onChanged();
+ return this;
+ }
+
// @@protoc_insertion_point(builder_scope:com.orbekk.same.ClientState)
}
@@ -6809,33 +6866,34 @@ public final class Services {
"\n\004data\030\002 \002(\t\022\020\n\010revision\030\003 \002(\003\"u\n\013Master" +
"State\022\022\n\nmaster_url\030\001 \001(\t\022\021\n\tmaster_id\030\002" +
" \001(\005\022\024\n\014network_name\030\003 \001(\t\022\027\n\017master_loc" +
- "ation\030\004 \001(\t\022\020\n\010revision\030\005 \001(\003\",\n\013ClientS" +
- "tate\022\013\n\003url\030\001 \001(\t\022\020\n\010location\030\002 \001(\t\"A\n\020N" +
- "etworkDirectory\022-\n\007network\030\001 \003(\0132\034.com.o" +
- "rbekk.same.MasterState\"T\n\014PaxosRequest\022,",
- "\n\006client\030\001 \001(\0132\034.com.orbekk.same.ClientS" +
- "tate\022\026\n\016proposalNumber\030\002 \001(\005\"\037\n\rPaxosRes" +
- "ponse\022\016\n\006result\030\001 \001(\0052\324\001\n\006Client\022>\n\010SetS" +
- "tate\022\032.com.orbekk.same.Component\032\026.com.o" +
- "rbekk.same.Empty\022F\n\016MasterTakeover\022\034.com" +
- ".orbekk.same.MasterState\032\026.com.orbekk.sa" +
- "me.Empty\022B\n\nMasterDown\022\034.com.orbekk.same" +
- ".MasterState\032\026.com.orbekk.same.Empty2\260\001\n" +
- "\006Master\022J\n\022JoinNetworkRequest\022\034.com.orbe" +
- "kk.same.ClientState\032\026.com.orbekk.same.Em",
- "pty\022Z\n\022UpdateStateRequest\022\032.com.orbekk.s" +
- "ame.Component\032(.com.orbekk.same.UpdateCo" +
- "mponentResponse2\236\001\n\tDirectory\022G\n\017Registe" +
- "rNetwork\022\034.com.orbekk.same.MasterState\032\026" +
- ".com.orbekk.same.Empty\022H\n\013GetNetworks\022\026." +
- "com.orbekk.same.Empty\032!.com.orbekk.same." +
- "NetworkDirectory2\241\001\n\005Paxos\022H\n\007Propose\022\035." +
- "com.orbekk.same.PaxosRequest\032\036.com.orbek" +
- "k.same.PaxosResponse\022N\n\rAcceptRequest\022\035." +
- "com.orbekk.same.PaxosRequest\032\036.com.orbek",
- "k.same.PaxosResponse2Y\n\rSystemService\022H\n" +
- "\017GetSystemStatus\022\026.com.orbekk.same.Empty" +
- "\032\035.com.orbekk.same.SystemStatusB\003\210\001\001"
+ "ation\030\004 \001(\t\022\020\n\010revision\030\005 \001(\003\">\n\013ClientS" +
+ "tate\022\013\n\003url\030\001 \001(\t\022\020\n\010location\030\002 \001(\t\022\020\n\010r" +
+ "evision\030\003 \001(\003\"A\n\020NetworkDirectory\022-\n\007net" +
+ "work\030\001 \003(\0132\034.com.orbekk.same.MasterState",
+ "\"T\n\014PaxosRequest\022,\n\006client\030\001 \001(\0132\034.com.o" +
+ "rbekk.same.ClientState\022\026\n\016proposalNumber" +
+ "\030\002 \001(\005\"\037\n\rPaxosResponse\022\016\n\006result\030\001 \001(\0052" +
+ "\324\001\n\006Client\022>\n\010SetState\022\032.com.orbekk.same" +
+ ".Component\032\026.com.orbekk.same.Empty\022F\n\016Ma" +
+ "sterTakeover\022\034.com.orbekk.same.MasterSta" +
+ "te\032\026.com.orbekk.same.Empty\022B\n\nMasterDown" +
+ "\022\034.com.orbekk.same.MasterState\032\026.com.orb" +
+ "ekk.same.Empty2\260\001\n\006Master\022J\n\022JoinNetwork" +
+ "Request\022\034.com.orbekk.same.ClientState\032\026.",
+ "com.orbekk.same.Empty\022Z\n\022UpdateStateRequ" +
+ "est\022\032.com.orbekk.same.Component\032(.com.or" +
+ "bekk.same.UpdateComponentResponse2\236\001\n\tDi" +
+ "rectory\022G\n\017RegisterNetwork\022\034.com.orbekk." +
+ "same.MasterState\032\026.com.orbekk.same.Empty" +
+ "\022H\n\013GetNetworks\022\026.com.orbekk.same.Empty\032" +
+ "!.com.orbekk.same.NetworkDirectory2\241\001\n\005P" +
+ "axos\022H\n\007Propose\022\035.com.orbekk.same.PaxosR" +
+ "equest\032\036.com.orbekk.same.PaxosResponse\022N" +
+ "\n\rAcceptRequest\022\035.com.orbekk.same.PaxosR",
+ "equest\032\036.com.orbekk.same.PaxosResponse2Y" +
+ "\n\rSystemService\022H\n\017GetSystemStatus\022\026.com" +
+ ".orbekk.same.Empty\032\035.com.orbekk.same.Sys" +
+ "temStatusB\003\210\001\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -6887,7 +6945,7 @@ public final class Services {
internal_static_com_orbekk_same_ClientState_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_com_orbekk_same_ClientState_descriptor,
- new java.lang.String[] { "Url", "Location", },
+ new java.lang.String[] { "Url", "Location", "Revision", },
com.orbekk.same.Services.ClientState.class,
com.orbekk.same.Services.ClientState.Builder.class);
internal_static_com_orbekk_same_NetworkDirectory_descriptor =
diff --git a/same/src/main/java/com/orbekk/same/services.proto b/same/src/main/java/com/orbekk/same/services.proto
index 99045ca..7149059 100644
--- a/same/src/main/java/com/orbekk/same/services.proto
+++ b/same/src/main/java/com/orbekk/same/services.proto
@@ -41,6 +41,7 @@ message MasterState {
message ClientState {
optional string url = 1;
optional string location = 2;
+ optional int64 revision = 3;
}
message NetworkDirectory {