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