|
36 | 36 | import net.spy.memcached.collection.BKeyObject; |
37 | 37 | import net.spy.memcached.collection.BTreeCount; |
38 | 38 | import net.spy.memcached.collection.BTreeCreate; |
| 39 | +import net.spy.memcached.collection.BTreeFindPosition; |
| 40 | +import net.spy.memcached.collection.BTreeFindPositionWithGet; |
39 | 41 | import net.spy.memcached.collection.BTreeDelete; |
40 | 42 | import net.spy.memcached.collection.BTreeGet; |
41 | 43 | import net.spy.memcached.collection.BTreeGetBulk; |
42 | 44 | import net.spy.memcached.collection.BTreeGetBulkWithByteTypeBkey; |
43 | 45 | import net.spy.memcached.collection.BTreeGetBulkWithLongTypeBkey; |
| 46 | +import net.spy.memcached.collection.BTreeGetByPosition; |
44 | 47 | import net.spy.memcached.collection.BTreeInsert; |
45 | 48 | import net.spy.memcached.collection.BTreeInsertAndGet; |
46 | 49 | import net.spy.memcached.collection.BTreeMutate; |
| 50 | +import net.spy.memcached.collection.BTreeOrder; |
47 | 51 | import net.spy.memcached.collection.BTreeSMGet; |
48 | 52 | import net.spy.memcached.collection.BTreeSMGetWithByteTypeBkey; |
49 | 53 | import net.spy.memcached.collection.BTreeSMGetWithLongTypeBkey; |
|
60 | 64 | import net.spy.memcached.collection.ElementValueType; |
61 | 65 | import net.spy.memcached.internal.result.GetsResultImpl; |
62 | 66 | import net.spy.memcached.ops.APIType; |
| 67 | +import net.spy.memcached.ops.BTreeFindPositionOperation; |
| 68 | +import net.spy.memcached.ops.BTreeFindPositionWithGetOperation; |
63 | 69 | import net.spy.memcached.ops.BTreeGetBulkOperation; |
| 70 | +import net.spy.memcached.ops.BTreeGetByPositionOperation; |
64 | 71 | import net.spy.memcached.ops.BTreeInsertAndGetOperation; |
65 | 72 | import net.spy.memcached.ops.BTreeSortMergeGetOperation; |
66 | 73 | import net.spy.memcached.ops.CollectionCreateOperation; |
|
79 | 86 | import net.spy.memcached.transcoders.TranscoderUtils; |
80 | 87 | import net.spy.memcached.v2.vo.BKey; |
81 | 88 | import net.spy.memcached.v2.vo.BTreeElement; |
| 89 | +import net.spy.memcached.v2.vo.BTreePositionElement; |
82 | 90 | import net.spy.memcached.v2.vo.BTreeElements; |
83 | 91 | import net.spy.memcached.v2.vo.BTreeUpdateElement; |
84 | 92 | import net.spy.memcached.v2.vo.BopDeleteArgs; |
@@ -1252,6 +1260,198 @@ private BTreeGetBulk<T> createBTreeGetBulk(MemcachedNode node, List<String> keys |
1252 | 1260 | } |
1253 | 1261 | } |
1254 | 1262 |
|
| 1263 | + public ArcusFuture<Integer> bopGetPosition(String key, BKey bKey, BTreeOrder order) { |
| 1264 | + AbstractArcusResult<Integer> result = new AbstractArcusResult<>(new AtomicReference<>()); |
| 1265 | + ArcusFutureImpl<Integer> future = new ArcusFutureImpl<>(result); |
| 1266 | + BTreeFindPosition findPosition = new BTreeFindPosition(bKey.toString(), order); |
| 1267 | + ArcusClient client = arcusClientSupplier.get(); |
| 1268 | + |
| 1269 | + BTreeFindPositionOperation.Callback cb = new BTreeFindPositionOperation.Callback() { |
| 1270 | + @Override |
| 1271 | + public void gotData(int position) { |
| 1272 | + result.set(position); |
| 1273 | + } |
| 1274 | + |
| 1275 | + @Override |
| 1276 | + public void receivedStatus(OperationStatus status) { |
| 1277 | + switch (status.getStatusCode()) { |
| 1278 | + case SUCCESS: |
| 1279 | + break; |
| 1280 | + case ERR_NOT_FOUND: |
| 1281 | + case ERR_NOT_FOUND_ELEMENT: |
| 1282 | + result.set(null); |
| 1283 | + break; |
| 1284 | + case CANCELLED: |
| 1285 | + future.internalCancel(); |
| 1286 | + break; |
| 1287 | + default: |
| 1288 | + /* TYPE_MISMATCH / BKEY_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */ |
| 1289 | + result.addError(key, status); |
| 1290 | + } |
| 1291 | + } |
| 1292 | + |
| 1293 | + @Override |
| 1294 | + public void complete() { |
| 1295 | + future.complete(); |
| 1296 | + } |
| 1297 | + }; |
| 1298 | + Operation op = client.getOpFact().bopFindPosition(key, findPosition, cb); |
| 1299 | + future.setOp(op); |
| 1300 | + client.addOp(key, op); |
| 1301 | + |
| 1302 | + return future; |
| 1303 | + } |
| 1304 | + |
| 1305 | + public ArcusFuture<BTreeElement<T>> bopGetByPosition(String key, int pos, BTreeOrder order) { |
| 1306 | + AbstractArcusResult<BTreeElement<T>> result |
| 1307 | + = new AbstractArcusResult<>(new AtomicReference<>()); |
| 1308 | + ArcusFutureImpl<BTreeElement<T>> future = new ArcusFutureImpl<>(result); |
| 1309 | + BTreeGetByPosition getByPosition = new BTreeGetByPosition(order, pos); |
| 1310 | + ArcusClient client = arcusClientSupplier.get(); |
| 1311 | + |
| 1312 | + BTreeGetByPositionOperation.Callback cb = new BTreeGetByPositionOperation.Callback() { |
| 1313 | + @Override |
| 1314 | + public void gotData(int pos, int flags, BKeyObject bKey, byte[] eFlag, byte[] data) { |
| 1315 | + result.set(buildBTreeElement(flags, bKey, eFlag, data)); |
| 1316 | + } |
| 1317 | + |
| 1318 | + @Override |
| 1319 | + public void receivedStatus(OperationStatus status) { |
| 1320 | + switch (status.getStatusCode()) { |
| 1321 | + case SUCCESS: |
| 1322 | + break; |
| 1323 | + case ERR_NOT_FOUND: |
| 1324 | + case ERR_NOT_FOUND_ELEMENT: |
| 1325 | + result.set(null); |
| 1326 | + break; |
| 1327 | + case CANCELLED: |
| 1328 | + future.internalCancel(); |
| 1329 | + break; |
| 1330 | + default: |
| 1331 | + /* TYPE_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */ |
| 1332 | + result.addError(key, status); |
| 1333 | + } |
| 1334 | + } |
| 1335 | + |
| 1336 | + @Override |
| 1337 | + public void complete() { |
| 1338 | + future.complete(); |
| 1339 | + } |
| 1340 | + }; |
| 1341 | + Operation op = client.getOpFact().bopGetByPosition(key, getByPosition, cb); |
| 1342 | + future.setOp(op); |
| 1343 | + client.addOp(key, op); |
| 1344 | + |
| 1345 | + return future; |
| 1346 | + } |
| 1347 | + |
| 1348 | + public ArcusFuture<List<BTreeElement<T>>> bopGetByPosition(String key, |
| 1349 | + int from, int to, |
| 1350 | + BTreeOrder order) { |
| 1351 | + if (from > to) { |
| 1352 | + throw new IllegalArgumentException("from should be less than or equal to to."); |
| 1353 | + } |
| 1354 | + |
| 1355 | + AbstractArcusResult<List<BTreeElement<T>>> result |
| 1356 | + = new AbstractArcusResult<>(new AtomicReference<>(new ArrayList<>())); |
| 1357 | + ArcusFutureImpl<List<BTreeElement<T>>> future = new ArcusFutureImpl<>(result); |
| 1358 | + BTreeGetByPosition getByPosition = new BTreeGetByPosition(order, from, to); |
| 1359 | + ArcusClient client = arcusClientSupplier.get(); |
| 1360 | + |
| 1361 | + BTreeGetByPositionOperation.Callback cb = new BTreeGetByPositionOperation.Callback() { |
| 1362 | + @Override |
| 1363 | + public void gotData(int pos, int flags, BKeyObject bKey, byte[] eFlag, byte[] data) { |
| 1364 | + result.get().add(buildBTreeElement(flags, bKey, eFlag, data)); |
| 1365 | + } |
| 1366 | + |
| 1367 | + @Override |
| 1368 | + public void receivedStatus(OperationStatus status) { |
| 1369 | + switch (status.getStatusCode()) { |
| 1370 | + case SUCCESS: |
| 1371 | + case ERR_NOT_FOUND_ELEMENT: |
| 1372 | + break; |
| 1373 | + case ERR_NOT_FOUND: |
| 1374 | + result.set(null); |
| 1375 | + break; |
| 1376 | + case CANCELLED: |
| 1377 | + future.internalCancel(); |
| 1378 | + break; |
| 1379 | + default: |
| 1380 | + /* TYPE_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */ |
| 1381 | + result.addError(key, status); |
| 1382 | + } |
| 1383 | + } |
| 1384 | + |
| 1385 | + @Override |
| 1386 | + public void complete() { |
| 1387 | + future.complete(); |
| 1388 | + } |
| 1389 | + }; |
| 1390 | + Operation op = client.getOpFact().bopGetByPosition(key, getByPosition, cb); |
| 1391 | + future.setOp(op); |
| 1392 | + client.addOp(key, op); |
| 1393 | + |
| 1394 | + return future; |
| 1395 | + } |
| 1396 | + |
| 1397 | + public ArcusFuture<List<BTreePositionElement<T>>> bopPositionWithGet(String key, |
| 1398 | + BKey bKey, |
| 1399 | + int count, |
| 1400 | + BTreeOrder order) { |
| 1401 | + AbstractArcusResult<List<BTreePositionElement<T>>> result = |
| 1402 | + new AbstractArcusResult<>(new AtomicReference<>(new ArrayList<>())); |
| 1403 | + ArcusFutureImpl<List<BTreePositionElement<T>>> future = new ArcusFutureImpl<>(result); |
| 1404 | + BTreeFindPositionWithGet findPositionWithGet = |
| 1405 | + new BTreeFindPositionWithGet(bKey.toBKeyObject(), order, count); |
| 1406 | + ArcusClient client = arcusClientSupplier.get(); |
| 1407 | + |
| 1408 | + BTreeFindPositionWithGetOperation.Callback cb = new BTreeFindPositionWithGetOperation |
| 1409 | + .Callback() { |
| 1410 | + |
| 1411 | + @Override |
| 1412 | + public void gotData(int pos, int flags, BKeyObject bKey, byte[] eFlag, byte[] data) { |
| 1413 | + T decodedData = tcForCollection.decode( |
| 1414 | + new CachedData(flags, data, tcForCollection.getMaxSize())); |
| 1415 | + result.get().add(new BTreePositionElement<>(BKey.of(bKey), decodedData, eFlag, pos)); |
| 1416 | + } |
| 1417 | + |
| 1418 | + @Override |
| 1419 | + public void receivedStatus(OperationStatus status) { |
| 1420 | + switch (status.getStatusCode()) { |
| 1421 | + case SUCCESS: |
| 1422 | + case ERR_NOT_FOUND_ELEMENT: |
| 1423 | + break; |
| 1424 | + case ERR_NOT_FOUND: |
| 1425 | + result.set(null); |
| 1426 | + break; |
| 1427 | + case CANCELLED: |
| 1428 | + future.internalCancel(); |
| 1429 | + break; |
| 1430 | + default: |
| 1431 | + /* TYPE_MISMATCH / BKEY_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */ |
| 1432 | + result.addError(key, status); |
| 1433 | + } |
| 1434 | + } |
| 1435 | + |
| 1436 | + @Override |
| 1437 | + public void complete() { |
| 1438 | + future.complete(); |
| 1439 | + } |
| 1440 | + }; |
| 1441 | + Operation op = client.getOpFact().bopFindPositionWithGet(key, findPositionWithGet, cb); |
| 1442 | + future.setOp(op); |
| 1443 | + client.addOp(key, op); |
| 1444 | + |
| 1445 | + return future; |
| 1446 | + } |
| 1447 | + |
| 1448 | + private BTreeElement<T> buildBTreeElement(int flags, BKeyObject bKey, |
| 1449 | + byte[] eFlag, byte[] data) { |
| 1450 | + T decodedData = tcForCollection.decode( |
| 1451 | + new CachedData(flags, data, tcForCollection.getMaxSize())); |
| 1452 | + return new BTreeElement<>(BKey.of(bKey), decodedData, eFlag); |
| 1453 | + } |
| 1454 | + |
1255 | 1455 | public ArcusFuture<SMGetElements<T>> bopSortMergeGet(List<String> keys, BKey from, BKey to, |
1256 | 1456 | boolean unique, BopGetArgs args) { |
1257 | 1457 | verifyBKeyRange(from, to); |
|
0 commit comments