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