Skip to content

Commit f8b2c5f

Browse files
committed
updated client to new protocol buffer interface
- removed integer and aw-map types - added dw flag and ew flag support - fixed resolving of localhost as default host name - version switch to 0.2.0
1 parent b425478 commit f8b2c5f

11 files changed

Lines changed: 163 additions & 183 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'eu.antidotedb'
2-
version '0.1.0'
2+
version '0.2.0'
33

44
apply plugin: 'java'
55
apply plugin: 'maven'

src/main/java/eu/antidotedb/client/AntidoteConfigManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public List<InetSocketAddress> getConfigHosts(String filepath) {
110110
String cfgPath = filepath;
111111
if (!this.configFileExist(cfgPath)) {
112112
// No File Found, returning default values
113-
list.add(InetSocketAddress.createUnresolved(DEFAULT_HOST, DEFAULT_PORT));
113+
list.add(new InetSocketAddress(DEFAULT_HOST, DEFAULT_PORT));
114114
return list;
115115
}
116116
File config = new File(cfgPath);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package eu.antidotedb.client;
2+
3+
import com.google.protobuf.ByteString;
4+
import eu.antidotedb.antidotepb.AntidotePB;
5+
6+
import javax.annotation.CheckReturnValue;
7+
8+
public class FlagKey extends Key<Boolean> {
9+
10+
FlagKey(AntidotePB.CRDT_type type, ByteString key) {
11+
super(type, key);
12+
}
13+
14+
@Override
15+
Boolean readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
16+
return ResponseDecoder.flag().readResponseToValue(resp);
17+
}
18+
19+
/**
20+
* Creates an update operation which assigns a new value to the flag.
21+
* <p>
22+
* Use the methods on {@link Bucket} to execute the update.
23+
*/
24+
@CheckReturnValue
25+
public UpdateOpDefaultImpl assign(boolean value) {
26+
AntidotePB.ApbFlagUpdate.Builder flagUpdateInstruction = AntidotePB.ApbFlagUpdate.newBuilder(); // The specific instruction in update instructions
27+
flagUpdateInstruction.setValue(value); // Set increment
28+
AntidotePB.ApbUpdateOperation.Builder updateOperation = AntidotePB.ApbUpdateOperation.newBuilder();
29+
updateOperation.setFlagop(flagUpdateInstruction);
30+
return new UpdateOpDefaultImpl(this, updateOperation);
31+
}
32+
}

src/main/java/eu/antidotedb/client/IntegerKey.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/main/java/eu/antidotedb/client/Key.java

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/**
1111
* An Antidote key consists of a CRDT type and a corresponding key.
12-
* It can be used as a top-level-key of an Antidote object in a bucket or as a key in a map.
12+
* It can be used as a top-level-key of an Antidote object in a bucket or as a key in a map_rr.
1313
* <p>
1414
* Use the static methods of this class to create keys for the respective CRDT types.
1515
*/
@@ -95,21 +95,6 @@ public static CounterKey fatCounter(String key) {
9595
return fatCounter(ByteString.copyFromUtf8(key));
9696
}
9797

98-
/**
99-
* An integer can be incremented and assigned to.
100-
*/
101-
public static IntegerKey integer(ByteString key) {
102-
return new IntegerKey(key);
103-
}
104-
105-
106-
/**
107-
* An integer can be incremented and assigned to.
108-
*/
109-
public static IntegerKey integer(String key) {
110-
return integer(ByteString.copyFromUtf8(key));
111-
}
112-
11398
/**
11499
* A last-writer-wins register.
115100
*
@@ -233,26 +218,10 @@ public static SetKey<String> set_removeWins(String key) {
233218
return set_removeWins(key, ValueCoder.utf8String);
234219
}
235220

236-
/**
237-
* An add-wins map.
238-
* Updates win over concurrent deletes.
239-
* Deleting an entry uses tombstones which are not garbage-collected.
240-
*/
241-
public static MapKey map_aw(ByteString key) {
242-
return new MapKey(AntidotePB.CRDT_type.AWMAP, key);
243-
}
244-
245-
/**
246-
* @see #map_aw(ByteString)
247-
*/
248-
public static MapKey map_aw(String key) {
249-
return map_aw(ByteString.copyFromUtf8(key));
250-
}
251-
252-
253221
/**
254222
* Remove-resets map.
255223
* Removing an entry resets the corresponding CRDT.
224+
* Entries using a CRDT that does not support resets cannot be removed form the map.
256225
* Therefore this map should mainly be used with embedded CRDTs that support a reset operation.
257226
* <p>
258227
* Reading the map only returns entries which have a value, where the internal state is not equal to the initial CRDT state.
@@ -285,6 +254,23 @@ public static MapKey map_g(String key) {
285254
}
286255

287256

257+
public static FlagKey flag_ew(ByteString key) {
258+
return new FlagKey(AntidotePB.CRDT_type.FLAG_EW, key);
259+
}
260+
261+
public static FlagKey flag_ew(String key) {
262+
return flag_ew(ByteString.copyFromUtf8(key));
263+
}
264+
265+
public static FlagKey flag_dw(ByteString key) {
266+
return new FlagKey(AntidotePB.CRDT_type.FLAG_DW, key);
267+
}
268+
269+
public static FlagKey flag_dw(String key) {
270+
return flag_ew(ByteString.copyFromUtf8(key));
271+
}
272+
273+
288274
AntidotePB.ApbMapKey.Builder toApbMapKey() {
289275
AntidotePB.ApbMapKey.Builder builder = AntidotePB.ApbMapKey.newBuilder();
290276
builder.setType(type);
@@ -311,20 +297,18 @@ public static Key<?> create(AntidotePB.CRDT_type type, ByteString k) {
311297
return register(k);
312298
case MVREG:
313299
return multiValueRegister(k);
314-
case INTEGER:
315-
return integer(k);
316300
case GMAP:
317301
return map_g(k);
318-
case AWMAP:
319-
return map_aw(k);
320302
case RWSET:
321303
return set_removeWins(k);
322304
case RRMAP:
323305
return map_rr(k);
324306
case FATCOUNTER:
325307
return fatCounter(k);
326-
case POLICY:
327-
throw new RuntimeException("policy CRDT not yet supported");
308+
case FLAG_EW:
309+
return flag_ew(k);
310+
case FLAG_DW:
311+
return flag_dw(k);
328312
default:
329313
throw new RuntimeException("CRDT not yet supported: " + type);
330314
}

src/main/java/eu/antidotedb/client/ResponseDecoder.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,13 @@ Integer readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
2626
};
2727
}
2828

29-
30-
public static ResponseDecoder<Long> integer() {
31-
return new ResponseDecoder<Long>() {
32-
@Override
33-
Long readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
34-
if (resp == null) {
35-
return 0L;
36-
} else if (resp.getInt() == null) {
37-
throw new AntidoteException("Invalid response " + resp);
38-
}
39-
return resp.getInt().getValue();
40-
}
41-
};
42-
}
43-
4429
public static <T> ResponseDecoder<T> register(ValueCoder<T> format) {
4530
return new ResponseDecoder<T>() {
4631
@Override
4732
T readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
4833
if (resp == null) {
4934
return null;
50-
} else if (resp.getReg() == null) {
35+
} else if (!resp.hasReg()) {
5136
throw new AntidoteException("Invalid response " + resp);
5237
}
5338
return format.decode(resp.getReg().getValue());
@@ -65,7 +50,7 @@ public static <T> ResponseDecoder<List<T>> multiValueRegister(ValueCoder<T> form
6550
List<T> readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
6651
if (resp == null) {
6752
return Collections.emptyList();
68-
} else if (resp.getMvreg() == null) {
53+
} else if (!resp.hasMvreg()) {
6954
throw new AntidoteException("Invalid response " + resp);
7055
}
7156
return format.decodeList(resp.getMvreg().getValuesList());
@@ -83,7 +68,7 @@ public static <T> ResponseDecoder<List<T>> set(ValueCoder<T> format) {
8368
List<T> readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
8469
if (resp == null) {
8570
return Collections.emptyList();
86-
} else if (resp.getSet() == null) {
71+
} else if (!resp.hasSet()) {
8772
throw new AntidoteException("Invalid response " + resp);
8873
}
8974
return format.decodeList(resp.getSet().getValueList());
@@ -102,13 +87,26 @@ public static <K> ResponseDecoder<MapKey.MapReadResult> map() {
10287
MapKey.MapReadResult readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
10388
if (resp == null) {
10489
return new MapKey.MapReadResult(Collections.emptyList());
105-
} else if (resp.getCounter() == null) {
90+
} else if (!resp.hasMap()) {
10691
throw new AntidoteException("Invalid response " + resp);
10792
}
10893
return new MapKey.MapReadResult(resp.getMap().getEntriesList());
10994
}
11095
};
11196
}
11297

98+
public static ResponseDecoder<Boolean> flag() {
99+
return new ResponseDecoder<Boolean>() {
100+
@Override
101+
Boolean readResponseToValue(AntidotePB.ApbReadObjectResp resp) {
102+
if (resp == null) {
103+
return false;
104+
} else if (!resp.hasFlag()) {
105+
throw new AntidoteException("Invalid response " + resp);
106+
}
107+
return resp.getFlag().getValue();
108+
}
109+
};
110+
}
113111

114112
}

src/main/java/eu/antidotedb/client/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
* <li>{@link eu.antidotedb.client.Key#register register}
2222
* <li>{@link eu.antidotedb.client.Key#multiValueRegister multiValueRegister}
2323
* <li>{@link eu.antidotedb.client.Key#counter counter}
24-
* <li>{@link eu.antidotedb.client.Key#integer integer}
2524
* <li>{@link eu.antidotedb.client.Key#fatCounter fatCounter}
2625
* <li>{@link eu.antidotedb.client.Key#map_g map_g}
27-
* <li>{@link eu.antidotedb.client.Key#map_aw map_aw}
2826
* <li>{@link eu.antidotedb.client.Key#map_rr map_rr}
2927
* <li>{@link eu.antidotedb.client.Key#set_removeWins set_removeWins}
3028
* <li>{@link eu.antidotedb.client.Key#set set}
29+
* <li>{@link eu.antidotedb.client.Key#flag_ew flag_ew}
30+
* <li>{@link eu.antidotedb.client.Key#flag_dw flag_dw}
3131
* <p>
3232
* </li>
3333
* </ul>

src/main/proto/eu/antidotedb/proto/antidote.proto

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ enum CRDT_type {
88
ORSET = 4;
99
LWWREG = 5;
1010
MVREG = 6;
11-
INTEGER = 7;
1211
GMAP = 8;
13-
AWMAP = 9;
1412
RWSET = 10;
1513
RRMAP = 11;
1614
FATCOUNTER = 12;
17-
POLICY = 13;
15+
FLAG_EW = 13;
16+
FLAG_DW = 14;
1817
}
1918

20-
21-
//------------------
22-
// Error messages
19+
// Riak Error response
2320
message ApbErrorResp {
2421
required bytes errmsg = 1;
2522
required uint32 errcode = 2;
@@ -83,33 +80,6 @@ message ApbGetMVRegResp {
8380
repeated bytes values = 1;
8481
}
8582

86-
87-
//------------------
88-
// Policy
89-
90-
message ApbPolicyUpdate {
91-
repeated bytes permissions = 1;
92-
}
93-
94-
message ApbGetPolicyResp {
95-
repeated bytes permissions = 1;
96-
}
97-
98-
//------------------
99-
// Integer
100-
101-
message ApbIntegerUpdate {
102-
// choose one of the following:
103-
// increment the integer
104-
optional sint64 inc = 1;
105-
// set the integer to a number
106-
optional sint64 set = 2;
107-
}
108-
109-
message ApbGetIntegerResp {
110-
required sint64 value = 1;
111-
}
112-
11383
//------------------
11484
// Map
11585

@@ -138,6 +108,18 @@ message ApbMapEntry {
138108
required ApbReadObjectResp value = 2;
139109
}
140110

111+
//-------------------
112+
// Flags
113+
114+
message ApbFlagUpdate {
115+
required bool value = 1;
116+
}
117+
118+
message ApbGetFlagResp {
119+
required bool value = 1;
120+
}
121+
122+
141123

142124
// General reset operation
143125
message ApbCrdtReset {
@@ -182,10 +164,9 @@ message ApbUpdateOperation { // TODO use this above
182164
optional ApbCounterUpdate counterop = 1;
183165
optional ApbSetUpdate setop = 2;
184166
optional ApbRegUpdate regop = 3;
185-
optional ApbIntegerUpdate integerop = 4;
186167
optional ApbMapUpdate mapop = 5;
187168
optional ApbCrdtReset resetop = 6;
188-
optional ApbPolicyUpdate policyop = 7;
169+
optional ApbFlagUpdate flagop = 7;
189170
}
190171

191172
// Objects to be updated
@@ -235,9 +216,8 @@ message ApbReadObjectResp {
235216
optional ApbGetSetResp set = 2;
236217
optional ApbGetRegResp reg = 3;
237218
optional ApbGetMVRegResp mvreg = 4;
238-
optional ApbGetIntegerResp int = 5;
239219
optional ApbGetMapResp map = 6;
240-
optional ApbGetPolicyResp policy = 7;
220+
optional ApbGetFlagResp flag = 7;
241221
}
242222
message ApbReadObjectsResp {
243223
required bool success = 1;

0 commit comments

Comments
 (0)