|
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.Collection; |
23 | 23 | import java.util.HashMap; |
| 24 | +import java.util.HashSet; |
24 | 25 | import java.util.List; |
25 | 26 | import java.util.Map; |
| 27 | +import java.util.Set; |
26 | 28 | import java.util.concurrent.CompletableFuture; |
27 | 29 | import java.util.concurrent.atomic.AtomicReference; |
28 | 30 | import java.util.function.Supplier; |
|
53 | 55 | import net.spy.memcached.collection.CollectionCount; |
54 | 56 | import net.spy.memcached.collection.CollectionCreate; |
55 | 57 | import net.spy.memcached.collection.CollectionDelete; |
| 58 | +import net.spy.memcached.collection.CollectionExist; |
| 59 | +import net.spy.memcached.collection.CollectionGet; |
56 | 60 | import net.spy.memcached.collection.CollectionInsert; |
57 | 61 | import net.spy.memcached.collection.CollectionMutate; |
58 | 62 | import net.spy.memcached.collection.CollectionUpdate; |
|
62 | 66 | import net.spy.memcached.collection.ListDelete; |
63 | 67 | import net.spy.memcached.collection.ListGet; |
64 | 68 | import net.spy.memcached.collection.ListInsert; |
| 69 | +import net.spy.memcached.collection.SetCreate; |
| 70 | +import net.spy.memcached.collection.SetDelete; |
| 71 | +import net.spy.memcached.collection.SetExist; |
| 72 | +import net.spy.memcached.collection.SetGet; |
| 73 | +import net.spy.memcached.collection.SetInsert; |
65 | 74 | import net.spy.memcached.internal.result.GetsResultImpl; |
66 | 75 | import net.spy.memcached.ops.APIType; |
67 | 76 | import net.spy.memcached.ops.BTreeGetBulkOperation; |
@@ -1660,4 +1669,117 @@ public ArcusFuture<Boolean> lopDelete(String key, int from, int to, boolean drop |
1660 | 1669 | ListDelete delete = new ListDelete(from, to, dropIfEmpty, false); |
1661 | 1670 | return collectionDelete(key, delete); |
1662 | 1671 | } |
| 1672 | + |
| 1673 | + public ArcusFuture<Boolean> sopCreate(String key, ElementValueType type, |
| 1674 | + CollectionAttributes attributes) { |
| 1675 | + if (attributes == null) { |
| 1676 | + throw new IllegalArgumentException("CollectionAttributes cannot be null"); |
| 1677 | + } |
| 1678 | + |
| 1679 | + SetCreate create = new SetCreate( |
| 1680 | + TranscoderUtils.examineFlags(type), attributes.getExpireTime(), |
| 1681 | + attributes.getMaxCount(), attributes.getReadable(), false); |
| 1682 | + return collectionCreate(key, create); |
| 1683 | + } |
| 1684 | + |
| 1685 | + public ArcusFuture<Boolean> sopInsert(String key, T value) { |
| 1686 | + return sopInsert(key, value, null); |
| 1687 | + } |
| 1688 | + |
| 1689 | + public ArcusFuture<Boolean> sopInsert(String key, T value, CollectionAttributes attributes) { |
| 1690 | + CollectionInsert<T> collectionInsert = new SetInsert<>(value, null, attributes); |
| 1691 | + return collectionInsert(key, "", collectionInsert); |
| 1692 | + } |
| 1693 | + |
| 1694 | + public ArcusFuture<Boolean> sopExist(String key, T value) { |
| 1695 | + AbstractArcusResult<Boolean> result = new AbstractArcusResult<>(new AtomicReference<>()); |
| 1696 | + ArcusFutureImpl<Boolean> future = new ArcusFutureImpl<>(result); |
| 1697 | + ArcusClient client = arcusClientSupplier.get(); |
| 1698 | + CollectionExist collectionExist = new SetExist<>(value, tcForCollection); |
| 1699 | + |
| 1700 | + OperationCallback cb = new OperationCallback() { |
| 1701 | + @Override |
| 1702 | + public void receivedStatus(OperationStatus status) { |
| 1703 | + switch (status.getStatusCode()) { |
| 1704 | + case EXIST: |
| 1705 | + result.set(true); |
| 1706 | + break; |
| 1707 | + case NOT_EXIST: |
| 1708 | + result.set(false); |
| 1709 | + break; |
| 1710 | + case ERR_NOT_FOUND: |
| 1711 | + result.set(null); |
| 1712 | + break; |
| 1713 | + case CANCELLED: |
| 1714 | + future.internalCancel(); |
| 1715 | + break; |
| 1716 | + default: |
| 1717 | + /* |
| 1718 | + * TYPE_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement |
| 1719 | + */ |
| 1720 | + result.addError(key, status); |
| 1721 | + break; |
| 1722 | + } |
| 1723 | + } |
| 1724 | + |
| 1725 | + @Override |
| 1726 | + public void complete() { |
| 1727 | + future.complete(); |
| 1728 | + } |
| 1729 | + }; |
| 1730 | + Operation op = client.getOpFact().collectionExist(key, "", collectionExist, cb); |
| 1731 | + future.setOp(op); |
| 1732 | + client.addOp(key, op); |
| 1733 | + |
| 1734 | + return future; |
| 1735 | + } |
| 1736 | + |
| 1737 | + public ArcusFuture<Set<T>> sopGet(String key, int count, GetArgs args) { |
| 1738 | + AbstractArcusResult<Set<T>> result |
| 1739 | + = new AbstractArcusResult<>(new AtomicReference<>(new HashSet<>())); |
| 1740 | + ArcusFutureImpl<Set<T>> future = new ArcusFutureImpl<>(result); |
| 1741 | + ArcusClient client = arcusClientSupplier.get(); |
| 1742 | + CollectionGet collectionGet = new SetGet(count, args.isWithDelete(), args.isDropIfEmpty()); |
| 1743 | + |
| 1744 | + CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() { |
| 1745 | + @Override |
| 1746 | + public void gotData(String subkey, int flags, byte[] data, byte[] eflag) { |
| 1747 | + CachedData cachedData = new CachedData(flags, data, tcForCollection.getMaxSize()); |
| 1748 | + result.get().add(tcForCollection.decode(cachedData)); |
| 1749 | + } |
| 1750 | + |
| 1751 | + @Override |
| 1752 | + public void receivedStatus(OperationStatus status) { |
| 1753 | + switch (status.getStatusCode()) { |
| 1754 | + case SUCCESS: |
| 1755 | + case ERR_NOT_FOUND_ELEMENT: |
| 1756 | + break; |
| 1757 | + case ERR_NOT_FOUND: |
| 1758 | + result.set(null); |
| 1759 | + break; |
| 1760 | + case CANCELLED: |
| 1761 | + future.internalCancel(); |
| 1762 | + break; |
| 1763 | + default: |
| 1764 | + /* TYPE_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */ |
| 1765 | + result.addError(key, status); |
| 1766 | + } |
| 1767 | + } |
| 1768 | + |
| 1769 | + @Override |
| 1770 | + public void complete() { |
| 1771 | + future.complete(); |
| 1772 | + } |
| 1773 | + }; |
| 1774 | + Operation op = client.getOpFact().collectionGet(key, collectionGet, cb); |
| 1775 | + future.setOp(op); |
| 1776 | + client.addOp(key, op); |
| 1777 | + |
| 1778 | + return future; |
| 1779 | + } |
| 1780 | + |
| 1781 | + public ArcusFuture<Boolean> sopDelete(String key, T value, boolean dropIfEmpty) { |
| 1782 | + CollectionDelete collectionDelete = new SetDelete<>(value, dropIfEmpty, false, tcForCollection); |
| 1783 | + return collectionDelete(key, collectionDelete); |
| 1784 | + } |
1663 | 1785 | } |
0 commit comments