├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature-refactoring-request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── .gitignore ├── .idea └── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── AUTHORS ├── ChangeLog ├── LICENSE ├── LICENSE.txt-spymemcached ├── PATENTS ├── README.md ├── buildfile ├── checkstyle-suppressions.xml ├── checkstyle.xml ├── devtools └── maketags.sh ├── docs ├── arcus-java-client-getting-started.md └── user_guide │ ├── 01-arcus-cloud-basics.md │ ├── 02-arcus-java-client.md │ ├── 03-key-value-API.md │ ├── 04-list-API.md │ ├── 05-set-API.md │ ├── 06-map-API.md │ ├── 07-btree-API.md │ ├── 08-attribute-API.md │ ├── 09-other-API.md │ ├── 10-log-message.md │ ├── 11-client-notes.md │ ├── 12-arcus-future-get-API.md │ ├── 13-front-cache.md │ ├── README.md │ └── images │ └── java_client_ehcache.png ├── etc └── MemcachedOptimization.graffle ├── pom.xml ├── src ├── main │ └── java │ │ └── net │ │ └── spy │ │ └── memcached │ │ ├── AddrUtil.java │ │ ├── AdminConnectTimeoutException.java │ │ ├── ArcusClient.java │ │ ├── ArcusClientException.java │ │ ├── ArcusClientIF.java │ │ ├── ArcusClientPool.java │ │ ├── ArcusKetamaNodeLocator.java │ │ ├── ArcusMBeanServer.java │ │ ├── ArcusReplKetamaNodeLocator.java │ │ ├── ArcusReplNodeAddress.java │ │ ├── ArrayModNodeLocator.java │ │ ├── BaseCacheMap.java │ │ ├── BinaryConnectionFactory.java │ │ ├── CASMutation.java │ │ ├── CASMutator.java │ │ ├── CASResponse.java │ │ ├── CASValue.java │ │ ├── CacheManager.java │ │ ├── CacheMap.java │ │ ├── CacheMonitor.java │ │ ├── CachedData.java │ │ ├── CollectionOperationException.java │ │ ├── ConnectionFactory.java │ │ ├── ConnectionFactoryBuilder.java │ │ ├── ConnectionObserver.java │ │ ├── DefaultConnectionFactory.java │ │ ├── ExceptionMessageFactory.java │ │ ├── FailureMode.java │ │ ├── HashAlgorithm.java │ │ ├── KetamaConnectionFactory.java │ │ ├── KetamaNodeLocator.java │ │ ├── KeyUtil.java │ │ ├── MemcachedClient.java │ │ ├── MemcachedClientIF.java │ │ ├── MemcachedConnection.java │ │ ├── MemcachedNode.java │ │ ├── MemcachedNodeROImpl.java │ │ ├── MemcachedReplicaGroup.java │ │ ├── MemcachedReplicaGroupImpl.java │ │ ├── MemcachedReplicaGroupROImpl.java │ │ ├── MigrationMonitor.java │ │ ├── MigrationState.java │ │ ├── MigrationType.java │ │ ├── NodeLocator.java │ │ ├── NotExistsServiceCodeException.java │ │ ├── OperationFactory.java │ │ ├── OperationTimeoutException.java │ │ ├── PartitionedList.java │ │ ├── PartitionedMap.java │ │ ├── ReadPriority.java │ │ ├── RedirectHandler.java │ │ ├── ReplicaPick.java │ │ ├── StatisticsHandler.java │ │ ├── auth │ │ ├── AuthDescriptor.java │ │ ├── AuthThread.java │ │ ├── AuthThreadMonitor.java │ │ ├── PlainCallbackHandler.java │ │ └── package.html │ │ ├── collection │ │ ├── Attributes.java │ │ ├── BKeyObject.java │ │ ├── BTreeCount.java │ │ ├── BTreeCreate.java │ │ ├── BTreeDelete.java │ │ ├── BTreeElement.java │ │ ├── BTreeFindPosition.java │ │ ├── BTreeFindPositionWithGet.java │ │ ├── BTreeGet.java │ │ ├── BTreeGetBulk.java │ │ ├── BTreeGetBulkImpl.java │ │ ├── BTreeGetBulkWithByteTypeBkey.java │ │ ├── BTreeGetBulkWithLongTypeBkey.java │ │ ├── BTreeGetByPosition.java │ │ ├── BTreeGetResult.java │ │ ├── BTreeInsert.java │ │ ├── BTreeInsertAndGet.java │ │ ├── BTreeMutate.java │ │ ├── BTreeOrder.java │ │ ├── BTreeSMGet.java │ │ ├── BTreeSMGetImpl.java │ │ ├── BTreeSMGetWithByteTypeBkey.java │ │ ├── BTreeSMGetWithByteTypeBkeyOld.java │ │ ├── BTreeSMGetWithLongTypeBkey.java │ │ ├── BTreeSMGetWithLongTypeBkeyOld.java │ │ ├── BTreeUpdate.java │ │ ├── BTreeUpsert.java │ │ ├── ByteArrayBKey.java │ │ ├── ByteArrayTreeMap.java │ │ ├── CollectionAttributes.java │ │ ├── CollectionBulkInsert.java │ │ ├── CollectionCount.java │ │ ├── CollectionCreate.java │ │ ├── CollectionDelete.java │ │ ├── CollectionExist.java │ │ ├── CollectionGet.java │ │ ├── CollectionInsert.java │ │ ├── CollectionMutate.java │ │ ├── CollectionObject.java │ │ ├── CollectionOverflowAction.java │ │ ├── CollectionPipe.java │ │ ├── CollectionPipedInsert.java │ │ ├── CollectionPipedUpdate.java │ │ ├── CollectionResponse.java │ │ ├── CollectionType.java │ │ ├── CollectionUpdate.java │ │ ├── Element.java │ │ ├── ElementFlagFilter.java │ │ ├── ElementFlagUpdate.java │ │ ├── ElementMultiFlagsFilter.java │ │ ├── ElementValueType.java │ │ ├── ListCreate.java │ │ ├── ListDelete.java │ │ ├── ListGet.java │ │ ├── ListInsert.java │ │ ├── MapCreate.java │ │ ├── MapDelete.java │ │ ├── MapGet.java │ │ ├── MapInsert.java │ │ ├── MapUpdate.java │ │ ├── MapUpsert.java │ │ ├── RequestMode.java │ │ ├── SMGetElement.java │ │ ├── SMGetMode.java │ │ ├── SMGetTrimKey.java │ │ ├── SetCreate.java │ │ ├── SetDelete.java │ │ ├── SetExist.java │ │ ├── SetGet.java │ │ ├── SetInsert.java │ │ └── SetPipedExist.java │ │ ├── compat │ │ ├── CloseUtil.java │ │ ├── SpyObject.java │ │ ├── SpyThread.java │ │ ├── SyncThread.java │ │ ├── log │ │ │ ├── AbstractLogger.java │ │ │ ├── DefaultLogger.java │ │ │ ├── Level.java │ │ │ ├── Log4JLogger.java │ │ │ ├── Logger.java │ │ │ ├── LoggerFactory.java │ │ │ ├── SLF4JLogger.java │ │ │ ├── SunLogger.java │ │ │ └── package.html │ │ └── package.html │ │ ├── internal │ │ ├── BTreeStoreAndGetFuture.java │ │ ├── BasicThreadFactory.java │ │ ├── BroadcastFuture.java │ │ ├── BulkFuture.java │ │ ├── BulkGetFuture.java │ │ ├── BulkOperationFuture.java │ │ ├── CheckedOperationTimeoutException.java │ │ ├── CollectionFuture.java │ │ ├── CollectionGetBulkFuture.java │ │ ├── CollectionGetFuture.java │ │ ├── CompositeException.java │ │ ├── GetFuture.java │ │ ├── ImmediateFuture.java │ │ ├── OperationFuture.java │ │ ├── PipedCollectionFuture.java │ │ ├── ReconnDelay.java │ │ ├── ReconnectJob.java │ │ ├── SMGetFuture.java │ │ ├── SingleElementInfiniteIterator.java │ │ ├── package.html │ │ └── result │ │ │ ├── BopGetBulkResultImpl.java │ │ │ ├── BopGetByPositionResultImpl.java │ │ │ ├── BopGetResultImpl.java │ │ │ ├── BopStoreAndGetResultImpl.java │ │ │ ├── GetResult.java │ │ │ ├── GetResultImpl.java │ │ │ ├── GetsResultImpl.java │ │ │ ├── LopGetResultImpl.java │ │ │ ├── MopGetResultImpl.java │ │ │ ├── SMGetResult.java │ │ │ ├── SMGetResultImpl.java │ │ │ ├── SMGetResultOldImpl.java │ │ │ └── SopGetResultImpl.java │ │ ├── ops │ │ ├── APIType.java │ │ ├── ArrayOperationQueueFactory.java │ │ ├── BTreeFindPositionOperation.java │ │ ├── BTreeFindPositionWithGetOperation.java │ │ ├── BTreeGetBulkOperation.java │ │ ├── BTreeGetByPositionOperation.java │ │ ├── BTreeInsertAndGetOperation.java │ │ ├── BTreeSortMergeGetOperation.java │ │ ├── BTreeSortMergeGetOperationOld.java │ │ ├── BaseOperationFactory.java │ │ ├── CASOperation.java │ │ ├── CASOperationStatus.java │ │ ├── CancelledOperationStatus.java │ │ ├── CollectionBulkInsertOperation.java │ │ ├── CollectionCountOperation.java │ │ ├── CollectionCreateOperation.java │ │ ├── CollectionDeleteOperation.java │ │ ├── CollectionExistOperation.java │ │ ├── CollectionGetOperation.java │ │ ├── CollectionInsertOperation.java │ │ ├── CollectionMutateOperation.java │ │ ├── CollectionOperationStatus.java │ │ ├── CollectionPipedExistOperation.java │ │ ├── CollectionPipedInsertOperation.java │ │ ├── CollectionPipedUpdateOperation.java │ │ ├── CollectionUpdateOperation.java │ │ ├── ConcatenationOperation.java │ │ ├── ConcatenationType.java │ │ ├── DeleteOperation.java │ │ ├── FlushOperation.java │ │ ├── GetAttrOperation.java │ │ ├── GetOperation.java │ │ ├── GetsOperation.java │ │ ├── KeyedOperation.java │ │ ├── LinkedOperationQueueFactory.java │ │ ├── MultiBTreeGetBulkOperationCallback.java │ │ ├── MultiBTreeSortMergeGetOperationCallback.java │ │ ├── MultiCollectionBulkInsertOperationCallback.java │ │ ├── MultiGetOperationCallback.java │ │ ├── MultiGetsOperationCallback.java │ │ ├── MultiOperationCallback.java │ │ ├── Mutator.java │ │ ├── MutatorOperation.java │ │ ├── NoopOperation.java │ │ ├── Operation.java │ │ ├── OperationCallback.java │ │ ├── OperationErrorType.java │ │ ├── OperationException.java │ │ ├── OperationQueueFactory.java │ │ ├── OperationState.java │ │ ├── OperationStatus.java │ │ ├── OperationType.java │ │ ├── PipedOperationCallback.java │ │ ├── SASLAuthOperation.java │ │ ├── SASLMechsOperation.java │ │ ├── SASLStepOperation.java │ │ ├── SetAttrOperation.java │ │ ├── StatsOperation.java │ │ ├── StatusCode.java │ │ ├── StoreOperation.java │ │ ├── StoreType.java │ │ ├── VersionOperation.java │ │ └── package.html │ │ ├── overview.html │ │ ├── package.html │ │ ├── plugin │ │ ├── FrontCacheBulkGetFuture.java │ │ ├── FrontCacheGetFuture.java │ │ ├── FrontCacheMemcachedClient.java │ │ └── LocalCacheManager.java │ │ ├── protocol │ │ ├── BaseOperationImpl.java │ │ ├── GetCallbackWrapper.java │ │ ├── ProxyCallback.java │ │ ├── TCPMemcachedNodeImpl.java │ │ ├── ascii │ │ │ ├── AsciiMemcachedNodeImpl.java │ │ │ ├── AsciiOperationFactory.java │ │ │ ├── BTreeFindPositionOperationImpl.java │ │ │ ├── BTreeFindPositionWithGetOperationImpl.java │ │ │ ├── BTreeGetBulkOperationImpl.java │ │ │ ├── BTreeGetByPositionOperationImpl.java │ │ │ ├── BTreeInsertAndGetOperationImpl.java │ │ │ ├── BTreeSortMergeGetOperationImpl.java │ │ │ ├── BTreeSortMergeGetOperationOldImpl.java │ │ │ ├── BaseGetOpImpl.java │ │ │ ├── BaseStoreOperationImpl.java │ │ │ ├── CASOperationImpl.java │ │ │ ├── CollectionBulkInsertOperationImpl.java │ │ │ ├── CollectionCountOperationImpl.java │ │ │ ├── CollectionCreateOperationImpl.java │ │ │ ├── CollectionDeleteOperationImpl.java │ │ │ ├── CollectionExistOperationImpl.java │ │ │ ├── CollectionGetOperationImpl.java │ │ │ ├── CollectionInsertOperationImpl.java │ │ │ ├── CollectionMutateOperationImpl.java │ │ │ ├── CollectionPipedExistOperationImpl.java │ │ │ ├── CollectionPipedInsertOperationImpl.java │ │ │ ├── CollectionPipedUpdateOperationImpl.java │ │ │ ├── CollectionUpdateOperationImpl.java │ │ │ ├── ConcatenationOperationImpl.java │ │ │ ├── DeleteOperationImpl.java │ │ │ ├── FlushByPrefixOperationImpl.java │ │ │ ├── FlushOperationImpl.java │ │ │ ├── GetAttrOperationImpl.java │ │ │ ├── GetOperationImpl.java │ │ │ ├── GetsOperationImpl.java │ │ │ ├── MutatorOperationImpl.java │ │ │ ├── OperationImpl.java │ │ │ ├── OperationReadType.java │ │ │ ├── OptimizedGetImpl.java │ │ │ ├── PipeOperationImpl.java │ │ │ ├── SetAttrOperationImpl.java │ │ │ ├── StatsOperationImpl.java │ │ │ ├── StoreOperationImpl.java │ │ │ ├── VersionOperationImpl.java │ │ │ └── package.html │ │ ├── binary │ │ │ ├── BinaryMemcachedNodeImpl.java │ │ │ ├── BinaryOperationFactory.java │ │ │ ├── ConcatenationOperationImpl.java │ │ │ ├── DeleteOperationImpl.java │ │ │ ├── FlushOperationImpl.java │ │ │ ├── GetOperationImpl.java │ │ │ ├── MultiGetOperationImpl.java │ │ │ ├── MutatorOperationImpl.java │ │ │ ├── NoopOperationImpl.java │ │ │ ├── OperationImpl.java │ │ │ ├── OptimizedGetImpl.java │ │ │ ├── OptimizedSetImpl.java │ │ │ ├── SASLAuthOperationImpl.java │ │ │ ├── SASLBaseOperationImpl.java │ │ │ ├── SASLMechsOperationImpl.java │ │ │ ├── SASLStepOperationImpl.java │ │ │ ├── StatsOperationImpl.java │ │ │ ├── StoreOperationImpl.java │ │ │ ├── VersionOperationImpl.java │ │ │ └── package.html │ │ └── package.html │ │ ├── transcoders │ │ ├── BaseSerializingTranscoder.java │ │ ├── CollectionTranscoder.java │ │ ├── InspectObjectSizeTranscoder.java │ │ ├── IntegerTranscoder.java │ │ ├── LongTranscoder.java │ │ ├── SerializingTranscoder.java │ │ ├── Transcoder.java │ │ ├── TranscoderUtils.java │ │ ├── WhalinTranscoder.java │ │ ├── WhalinV1Transcoder.java │ │ └── package.html │ │ └── util │ │ ├── ArcusKetamaNodeLocatorConfiguration.java │ │ ├── ArcusReplKetamaNodeLocatorConfiguration.java │ │ ├── BTreeUtil.java │ │ ├── CacheLoader.java │ │ ├── DefaultKetamaNodeLocatorConfiguration.java │ │ ├── KetamaNodeLocatorConfiguration.java │ │ └── package.html └── test │ ├── java │ └── net │ │ └── spy │ │ └── memcached │ │ ├── AbstractNodeLocationCase.java │ │ ├── AddrUtilTest.java │ │ ├── ArcusKetamaHashingTest.java │ │ ├── ArcusKetamaNodeLocatorTest.java │ │ ├── ArcusTimeoutTest.java │ │ ├── ArrayModNodeLocatorTest.java │ │ ├── AsciiCancellationTest.java │ │ ├── AsciiClientTest.java │ │ ├── AsciiIPV6ClientTest.java │ │ ├── BinaryCancellationTest.java │ │ ├── BinaryClientTest.java │ │ ├── BinaryIPV6ClientTest.java │ │ ├── CASMutatorTest.java │ │ ├── CacheMapTest.java │ │ ├── CacheMonitorTest.java │ │ ├── CancelFailureModeTest.java │ │ ├── CancellationBaseCase.java │ │ ├── ClientBaseCase.java │ │ ├── ConnectionFactoryBuilderTest.java │ │ ├── ConnectionFactoryTest.java │ │ ├── ConsistentHashingTest.java │ │ ├── DoLotsOfSets.java │ │ ├── ExpectationsUtil.java │ │ ├── HashAlgorithmTest.java │ │ ├── KetamaConnectionFactoryTest.java │ │ ├── KetamaNodeLocatorTest.java │ │ ├── LongClientTest.java │ │ ├── MemcachedClientConstructorTest.java │ │ ├── MemcachedConnectionTest.java │ │ ├── MemcachedNodeROImplTest.java │ │ ├── MockMemcachedNode.java │ │ ├── ObserverTest.java │ │ ├── OperationFactoryTestBase.java │ │ ├── ProtocolBaseCase.java │ │ ├── QueueOverflowTest.java │ │ ├── RedistributeFailureModeTest.java │ │ ├── SocketTest.java │ │ ├── TimeoutTest.java │ │ ├── compat │ │ └── log │ │ │ └── LoggingTest.java │ │ ├── internal │ │ ├── CheckedOperationTimeoutExceptionTest.java │ │ ├── CompositeExceptionTest.java │ │ └── SingleElementInfiniteIteratorTest.java │ │ ├── protocol │ │ ├── TCPMemcachedNodeImplTest.java │ │ ├── ascii │ │ │ ├── BaseOpTest.java │ │ │ ├── ExtensibleOperationImpl.java │ │ │ ├── OperationExceptionTest.java │ │ │ ├── OperationFactoryTest.java │ │ │ └── OptimizeOperationTest.java │ │ └── binary │ │ │ ├── OperationFactoryTest.java │ │ │ └── OperationTest.java │ │ ├── transcoders │ │ ├── BaseSerializingTranscoderTest.java │ │ ├── BaseTranscoderCase.java │ │ ├── CachedDataTest.java │ │ ├── IntegerTranscoderTest.java │ │ ├── LongTranscoderTest.java │ │ ├── SerializingTranscoderTest.java │ │ ├── TranscoderUtilsTest.java │ │ ├── WhalinTranscoderTest.java │ │ └── WhalinV1TranscoderTest.java │ │ └── util │ │ ├── BTreeUtilTest.java │ │ └── CacheLoaderTest.java │ ├── manual │ └── net │ │ └── spy │ │ └── memcached │ │ ├── ArcusClientConnectTest.java │ │ ├── ArcusClientCreateTest.java │ │ ├── ArcusClientFrontCacheTest.java │ │ ├── ArcusClientNotExistsServiceCodeTest.java │ │ ├── ArcusClientPoolCreateTest.java │ │ ├── ArcusClientPoolReconnectTest.java │ │ ├── ArcusClientPoolShutdownTest.java │ │ ├── ArcusClientReconnectTest.java │ │ ├── ArcusClientShutdownTest.java │ │ ├── LoggerSetter.java │ │ ├── LongKeyTest │ │ └── BaseLongKeyTest.java │ │ ├── MemcachedConnectionReplTest.java │ │ ├── MultibyteKeyTest.java │ │ ├── btreesmget │ │ ├── ByteArrayBKeySMGetErrorTest.java │ │ ├── ByteArrayBKeySMGetIrregularEflagTest.java │ │ ├── ByteArrayBKeySMGetTest.java │ │ ├── SMGetErrorTest.java │ │ ├── SMGetTest.java │ │ ├── SMGetWithCombinationEflagTest.java │ │ └── SMGetWithEflagTest.java │ │ ├── bulkoperation │ │ ├── BopInsertBulkMultipleBoundaryTest.java │ │ ├── BopInsertBulkMultipleTest.java │ │ ├── BopInsertBulkTest.java │ │ ├── BopPipeUpdateTest.java │ │ ├── BulkDeleteTest.java │ │ ├── BulkSetVariousTypeTest.java │ │ ├── BulkStoreTest.java │ │ ├── LopInsertBulkMultipleValueTest.java │ │ ├── LopInsertBulkTest.java │ │ ├── MopInsertBulkMultipleTest.java │ │ ├── MopInsertBulkTest.java │ │ ├── PipeInsertTest.java │ │ ├── SopInsertBulkMultipleValueTest.java │ │ └── SopInsertBulkTest.java │ │ ├── collection │ │ ├── BaseIntegrationTest.java │ │ ├── CollectionFutureTest.java │ │ ├── CollectionMaxElementSize.java │ │ ├── ElementFlagFilterTest.java │ │ ├── attribute │ │ │ ├── BTreeGetAttrTest.java │ │ │ ├── GetAttrTest.java │ │ │ ├── MaxBkeyRangeTest.java │ │ │ ├── SetAttrTest.java │ │ │ ├── UnReadableBTreeTest.java │ │ │ ├── UnReadableExtendedBTreeTest.java │ │ │ ├── UnReadableListTest.java │ │ │ ├── UnReadableMapTest.java │ │ │ └── UnReadableSetTest.java │ │ ├── btree │ │ │ ├── BKeyObjectTest.java │ │ │ ├── BopDeleteTest.java │ │ │ ├── BopFindPositionTest.java │ │ │ ├── BopFindPositionWithGetTest.java │ │ │ ├── BopGetBulkTest.java │ │ │ ├── BopGetByPositionTest.java │ │ │ ├── BopGetExceptionTest.java │ │ │ ├── BopGetIrregularEflagTest.java │ │ │ ├── BopGetOffsetSupportTest.java │ │ │ ├── BopGetSortTest.java │ │ │ ├── BopInsertAndGetTest.java │ │ │ ├── BopInsertAndGetWithElementFlagTest.java │ │ │ ├── BopInsertWhenKeyExists.java │ │ │ ├── BopInsertWhenKeyNotExist.java │ │ │ ├── BopMutateTest.java │ │ │ ├── BopOverflowActionTest.java │ │ │ ├── BopServerMessageTest.java │ │ │ ├── BopSortMergeOldTest.java │ │ │ ├── BopSortMergeTest.java │ │ │ ├── BopUpdateTest.java │ │ │ ├── BopUpsertTest.java │ │ │ ├── ElementTest.java │ │ │ ├── SMGetElementTest.java │ │ │ ├── SMGetTrimKeyTest.java │ │ │ └── longbkey │ │ │ │ ├── BopCountWithElementFlagFilterTest.java │ │ │ │ ├── BopGetBulkTest.java │ │ │ │ ├── BopGetIrregularEflagTest.java │ │ │ │ ├── BopGetTest.java │ │ │ │ ├── BopInsertAndGetWithElementFlagTest.java │ │ │ │ ├── BopUpdateTest.java │ │ │ │ └── BopUpsertTest.java │ │ ├── internal │ │ │ └── CancelFutureTest.java │ │ ├── list │ │ │ ├── LopBulkAPITest.java │ │ │ ├── LopDeleteTest.java │ │ │ ├── LopGetTest.java │ │ │ ├── LopInsertBoundary.java │ │ │ ├── LopInsertDataType.java │ │ │ ├── LopInsertWhenKeyExists.java │ │ │ ├── LopInsertWhenKeyNotExist.java │ │ │ ├── LopOverflowActionTest.java │ │ │ └── LopServerMessageTest.java │ │ ├── map │ │ │ ├── MopBulkAPITest.java │ │ │ ├── MopDeleteTest.java │ │ │ ├── MopGetTest.java │ │ │ ├── MopInsertWhenKeyExists.java │ │ │ ├── MopInsertWhenKeyNotExist.java │ │ │ ├── MopOverflowActionTest.java │ │ │ ├── MopServerMessageTest.java │ │ │ ├── MopUpdateTest.java │ │ │ └── MopUpsertTest.java │ │ ├── set │ │ │ ├── SopBulkAPITest.java │ │ │ ├── SopDeleteTest.java │ │ │ ├── SopExistTest.java │ │ │ ├── SopInsertWhenKeyExists.java │ │ │ ├── SopInsertWhenKeyNotExist.java │ │ │ ├── SopOverflowActionTest.java │ │ │ ├── SopPipedExistTest.java │ │ │ └── SopServerMessageTest.java │ │ └── transcoder │ │ │ └── CollectionTranscoderTest.java │ │ ├── emptycollection │ │ ├── BTreeDeleteWithFilterTest.java │ │ ├── BTreeGetWithFilterTest.java │ │ ├── CreateEmptyBTreeTest.java │ │ ├── CreateEmptyListTest.java │ │ ├── CreateEmptyMapTest.java │ │ ├── CreateEmptySetTest.java │ │ ├── GetCountBTreeTest.java │ │ ├── GetCountBTreeTestWithElementFlagFilterTest.java │ │ ├── GetWithDropBTreeTest.java │ │ ├── GetWithDropListTest.java │ │ ├── GetWithDropMapTest.java │ │ ├── GetWithDropSetTest.java │ │ ├── InsertBTreeWithAttrAndEFlagTest.java │ │ ├── InsertListWithAttrTest.java │ │ ├── InsertMapWithAttrTest.java │ │ ├── InsertSetWithAttrTest.java │ │ ├── PipedBulkInsertBTreeWithAttrTest.java │ │ ├── PipedBulkInsertListWithAttrTest.java │ │ ├── PipedBulkInsertMapWithAttrTest.java │ │ ├── PipedBulkInsertSetWithAttrTest.java │ │ ├── ProtocolBTreeDeleteTest.java │ │ ├── ProtocolBTreeGetTest.java │ │ ├── ProtocolListDeleteTest.java │ │ ├── ProtocolListGetTest.java │ │ ├── ProtocolMapDeleteTest.java │ │ ├── ProtocolMapGetTest.java │ │ ├── ProtocolSetDeleteTest.java │ │ ├── ProtocolSetExistTest.java │ │ ├── ProtocolSetGetTest.java │ │ └── VariousTypeTest.java │ │ ├── flushbyprefix │ │ └── FlushByPrefixTest.java │ │ ├── frontcache │ │ └── LocalCacheManagerTest.java │ │ ├── ops │ │ └── OperationStatusTest.java │ │ └── test │ │ ├── AuthTest.java │ │ ├── ExcessivelyLargeGetTest.java │ │ ├── LoaderTest.java │ │ ├── MemcachedThreadBench.java │ │ ├── MemoryFullTest.java │ │ ├── MultiNodeFailureTest.java │ │ ├── MutateWithDefaultTest.java │ │ ├── ObserverToy.java │ │ └── SASLConnectReconnect.java │ └── resources │ └── log4j2.xml └── xdocs └── index.xml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### ⛔ What happened? 11 | 12 | - 13 | 14 | ### 🎯 Reproduction Steps 15 | 16 | 17 | - 18 | 19 | ### 💡 Expected Behavior / Solution 20 | 21 | 22 | - -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-refactoring-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature/Refactoring request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### 🔍 Description 11 | 12 | 13 | - 14 | 15 | ### ⏰ Implementation Idea 16 | 17 | 18 | - -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### 🔗 Related Issue 2 | 3 | 4 | - 5 | 6 | ### ⌨️ What I did 7 | 8 | 9 | - -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - develop 10 | types: 11 | - opened 12 | - synchronize 13 | - reopened 14 | - ready_for_review 15 | 16 | concurrency: 17 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: true 19 | 20 | jobs: 21 | test: 22 | name: JDK ${{ matrix.jdk }}, ${{ matrix.os }} 23 | runs-on: ${{ matrix.os }} 24 | strategy: 25 | matrix: 26 | jdk: [ 8, 21 ] 27 | os: [ ubuntu-latest ] 28 | fail-fast: true 29 | if: | 30 | (github.event_name == 'pull_request' && github.event.pull_request.draft == false) || 31 | (github.event_name == 'push' && github.ref == 'refs/heads/master') 32 | steps: 33 | - uses: actions/checkout@v4 34 | - name: Set up JDK ${{ matrix.jdk }} 35 | uses: actions/setup-java@v4 36 | with: 37 | java-version: ${{ matrix.jdk }} 38 | distribution: 'temurin' 39 | cache: 'maven' 40 | - name: Update apt-get 41 | run: sudo apt-get update 42 | - name: Install ARCUS 43 | run: | 44 | # clone 45 | git clone https://github.com/naver/arcus.git $HOME/arcus 46 | 47 | # build server 48 | cd ~/arcus && docker compose up -d 49 | 50 | - name: Test ARCUS Client Without ZK 51 | run: mvn clean verify -DUSE_ZK=false -Dtest=ObserverTest,ArcusClientCreateTest 52 | - name: Test ARCUS Client With ZK 53 | run: mvn clean verify -DUSE_ZK=true 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | cobertura.ser 3 | target/ 4 | reports/ 5 | devtools/ 6 | junit* 7 | *.iml 8 | *~ 9 | !.idea 10 | .idea/* 11 | !.idea/codeStyles 12 | !.idea/codeStyles/** 13 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Chisu Yu (netspider) ; 2 | Hoonmin Kim (harebox) ; 3 | YeaSol Kim (ngleader) ; 4 | SeongHwa Ahn ; 5 | Hyongyoub Kim 6 | -------------------------------------------------------------------------------- /LICENSE.txt-spymemcached: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2009 Dustin Sallings 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /PATENTS: -------------------------------------------------------------------------------- 1 | Arcus has patents on the implementation of b+tree smget operation like below. 2 | 3 | | Nation | Number | Title | Status | 4 | | ------------- | --------------- | ------------------- | ---------- | 5 | | United States | 13/474,382 | Multiple Range Scan | registered | 6 | | Korea | 10-2011-0054384 | Multiple Range Scan | applied | 7 | | Japan | 2012-092668 | Multiple Range Scan | applied | 8 | -------------------------------------------------------------------------------- /checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /devtools/maketags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | find ../src -name "*java" > ./cscope.files 3 | ctags --extra=+q -L ./cscope.files -f ./tags 4 | rm ./cscope.files 5 | -------------------------------------------------------------------------------- /docs/user_guide/09-other-API.md: -------------------------------------------------------------------------------- 1 | ## Other API 2 | 3 | 본 절에서는 아래의 나머지 API들을 설명한다. 4 | 5 | - [Flush](09-other-API.md#flush) 6 | 7 | ### Flush 8 | 9 | ARCUS는 prefix단위로 flush하는 기능을 제공한다. 10 | 캐시 서버에 저장된 모든 데이터들 중 특정 prefix를 사용하는 모든 key들을 한번의 요청으로 삭제할 수 있다. 단, Front Cache의 데이터는 flush 되지 않는다. 11 | 12 | ```java 13 | OperationFuture flush(String prefix) 14 | ``` 15 | 16 | 정상적으로 prefix가 제거되었을 경우 true를 반환하며 만약 해당 prefix가 존재하지 않아 제거에 실패하였을 경우 false를 반환한다. 17 | 18 | **특정 prefix의 모든 item들을 삭제하는 기능이기 때문에 그 사용에 주의하여야 한다.** 19 | **특히, prefix를 입력하지 않으면, cache node의 모든 item들이 삭제므로 공용으로 사용하는 cloud에선 각별히 주의해야 한다.** 20 | 21 | 22 | 아래는 특정 prefix를 flush하는 예제이다. 23 | 24 | ```java 25 | OperationFuture future = null; 26 | try { 27 | future = client.flush(“myprefix”); 28 | boolean result = future.get(1000L, TimeUnit.MILLISECONDS); 29 | System.out.println(result); 30 | } catch (InterruptedException e) { 31 | future.cancel(true); 32 | } catch (TimeoutException e) { 33 | future.cancel(true); 34 | } catch (ExecutionException e) { 35 | future.cancel(true); 36 | } 37 | ``` 38 | 39 | 예를 들어, ARCUS 서버에 다음 key 들이 저장되어 있다고 가정하자. 40 | 41 | - mydata:subkey1 42 | - mydata:subkey2 43 | - yourdata:subkey3 44 | - ourdata:subkey4 45 | - theirdata:subkey5 46 | 47 | 위 코드에서 client.flush(“myprefix”)를 호출하면 “myprefix”를 prefix로 사용하는 mydata:subkey1, mydata:subkey2 두 key가 ARCUS에서 제거된다. 물론 ARCUS cloud를 구성하는 모든 서버에 대해서 수행된 결과이며 성공했을 경우 future.get()은 true를 반환한다. 48 | 49 | -------------------------------------------------------------------------------- /docs/user_guide/images/java_client_ehcache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/arcus-java-client/beeb9bb4816c8ec62d41a130b56f9de730755e38/docs/user_guide/images/java_client_ehcache.png -------------------------------------------------------------------------------- /etc/MemcachedOptimization.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/arcus-java-client/beeb9bb4816c8ec62d41a130b56f9de730755e38/etc/MemcachedOptimization.graffle -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/AdminConnectTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2014 JaM2in Co., Ltd. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | public class AdminConnectTimeoutException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = -1461409015284668293L; 22 | 23 | public AdminConnectTimeoutException(String message) { 24 | super(message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ArcusClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | public abstract class ArcusClientException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = -4658082759499319120L; 22 | 23 | public ArcusClientException(String message) { 24 | super(message); 25 | } 26 | 27 | public ArcusClientException(String message, Throwable e) { 28 | super(message, e); 29 | } 30 | 31 | public static class InitializeClientException extends ArcusClientException { 32 | 33 | private static final long serialVersionUID = 2001051171343419920L; 34 | 35 | public InitializeClientException(String message) { 36 | super(message); 37 | } 38 | 39 | public InitializeClientException(String message, Throwable e) { 40 | super(message, e); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/CASMutation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * Defines a mutation mechanism for a high-level CAS client interface. 5 | */ 6 | public interface CASMutation { 7 | 8 | /** 9 | * Get the new value to replace the current value. 10 | * 11 | * @param current the current value in the cache 12 | * @return the replacement value 13 | */ 14 | T getNewValue(T current); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/CASResponse.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * Response codes for a CAS operation. 5 | */ 6 | public enum CASResponse { 7 | /** 8 | * Status indicating that the CAS was successful and the new value is 9 | * stored in the cache. 10 | */ 11 | OK, 12 | /** 13 | * Status indicating the value was not found in the cache (an add 14 | * operation may be issued to store the value). 15 | */ 16 | NOT_FOUND, 17 | /** 18 | * Status indicating the value was found in the cache, but exists with a 19 | * different CAS value than expected. In this case, the value must be 20 | * refetched and the CAS operation tried again. 21 | */ 22 | EXISTS, 23 | /** 24 | * Status indicating the CAS operation was cancelled 25 | * by java client internal. 26 | */ 27 | CANCELED, 28 | /** 29 | * Status indicating the undefined response was delivered from the cache. 30 | */ 31 | UNDEFINED 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/CASValue.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * A value with a CAS identifier. 5 | */ 6 | public class CASValue { 7 | private final long cas; 8 | private final T value; 9 | 10 | /** 11 | * Construct a new CASValue with the given identifier and value. 12 | * 13 | * @param c the CAS identifier 14 | * @param v the value 15 | */ 16 | public CASValue(long c, T v) { 17 | super(); 18 | cas = c; 19 | value = v; 20 | } 21 | 22 | /** 23 | * Get the CAS identifier. 24 | */ 25 | public long getCas() { 26 | return cas; 27 | } 28 | 29 | /** 30 | * Get the object value. 31 | */ 32 | public T getValue() { 33 | return value; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "{CasValue " + cas + "/" + value + "}"; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/CacheMap.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * A Map interface to memcached. 5 | * 6 | *

7 | * Do note that nothing that iterates over the map will work (such is 8 | * memcached). All iteration mechanisms will return empty iterators and 9 | * such. 10 | *

11 | */ 12 | public class CacheMap extends BaseCacheMap { 13 | 14 | /** 15 | * Construct a CacheMap over the given MemcachedClient. 16 | * 17 | * @param c the client 18 | * @param expiration the expiration to set for keys written to the cache 19 | * @param prefix a prefix used to make keys in this map unique 20 | */ 21 | public CacheMap(MemcachedClientIF c, int expiration, String prefix) { 22 | super(c, expiration, prefix, c.getTranscoder()); 23 | } 24 | 25 | /** 26 | * Construct a CacheMap over the given MemcachedClient with no expiration. 27 | * 28 | *

29 | * Keys written into this Map will only expire when the LRU pushes them 30 | * out. 31 | *

32 | * 33 | * @param c the client 34 | * @param prefix a prefix used to make keys in this map unique 35 | */ 36 | public CacheMap(MemcachedClientIF c, String prefix) { 37 | this(c, 0, prefix); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/CollectionOperationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | public class CollectionOperationException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = 8715298251738556350L; 22 | 23 | public CollectionOperationException(String message) { 24 | super(message); 25 | } 26 | 27 | public CollectionOperationException(String message, Throwable cause) { 28 | super(message, cause); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ConnectionObserver.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.net.SocketAddress; 4 | 5 | /** 6 | * Users of this interface will be notified when changes to the state of 7 | * connections take place. 8 | */ 9 | public interface ConnectionObserver { 10 | 11 | /** 12 | * A connection has just successfully been established on the given socket. 13 | * 14 | * @param sa the address of the node whose connection was established 15 | * @param reconnectCount the number of attempts before the connection was 16 | * established 17 | */ 18 | void connectionEstablished(SocketAddress sa, int reconnectCount); 19 | 20 | 21 | /** 22 | * A connection was just lost on the given socket. 23 | * 24 | * @param sa the address of the node whose connection was lost 25 | */ 26 | void connectionLost(SocketAddress sa); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/FailureMode.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * Failure modes for node failures. 5 | */ 6 | public enum FailureMode { 7 | 8 | /** 9 | * Move on to functional nodes when nodes fail. 10 | * 11 | *

12 | * In this failure mode, the failure of a node will cause its current 13 | * queue and future requests to move to the next logical node in the 14 | * cluster for a given key. 15 | *

16 | */ 17 | Redistribute, 18 | /** 19 | * Continue to retry a failing node until it comes back up. 20 | * 21 | *

22 | * This failure mode is appropriate when you have a rare short downtime 23 | * of a memcached node that will be back quickly, and your app is written 24 | * to not wait very long for async command completion. 25 | *

26 | */ 27 | Retry, 28 | 29 | /** 30 | * Automatically cancel all operations heading towards a downed node. 31 | */ 32 | Cancel 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/KetamaConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * ConnectionFactory instance that sets up a ketama compatible connection. 7 | * 8 | *

9 | * This implementation piggy-backs on the functionality of the 10 | * DefaultConnectionFactory in terms of connections and queue 11 | * handling. Where it differs is that it uses both the 12 | * KetamaNodeLocator and the HashAlgorithm.KETAMA_HASH 13 | * to provide consistent node hashing. 14 | *

15 | * 16 | * @see RJ's blog post 17 | */ 18 | public class KetamaConnectionFactory extends DefaultConnectionFactory { 19 | /** 20 | * Create a KetamaConnectionFactory with the given maximum operation 21 | * queue length, and the given read buffer size. 22 | * 23 | * @param opQueueMaxBlockTime the maximum time to block waiting for op 24 | * queue operations to complete, in milliseconds 25 | */ 26 | public KetamaConnectionFactory(int qLen, int bufSize, 27 | long opQueueMaxBlockTime) { 28 | super(qLen, bufSize, HashAlgorithm.KETAMA_HASH); 29 | } 30 | 31 | /** 32 | * Create a KetamaConnectionFactory with the default parameters. 33 | */ 34 | public KetamaConnectionFactory() { 35 | this(DEFAULT_OP_QUEUE_LEN, DEFAULT_READ_BUFFER_SIZE, 36 | DEFAULT_OP_QUEUE_MAX_BLOCK_TIME); 37 | } 38 | 39 | @Override 40 | public NodeLocator createLocator(List nodes) { 41 | return new KetamaNodeLocator(nodes, getHashAlg()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/KeyUtil.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.ArrayList; 5 | import java.util.Collection; 6 | 7 | /** 8 | * Utilities for processing key values. 9 | */ 10 | public final class KeyUtil { 11 | 12 | private KeyUtil() { 13 | } 14 | 15 | /** 16 | * Get the bytes for a key. 17 | * 18 | * @param k the key 19 | * @return the bytes 20 | */ 21 | public static byte[] getKeyBytes(String k) { 22 | try { 23 | return k.getBytes("UTF-8"); 24 | } catch (UnsupportedEncodingException e) { 25 | throw new RuntimeException(e); 26 | } 27 | } 28 | 29 | /** 30 | * Get the keys in byte form for all of the string keys. 31 | * 32 | * @param keys a collection of keys 33 | * @return return a collection of the byte representations of keys 34 | */ 35 | public static Collection getKeyBytes(Collection keys) { 36 | Collection rv = new ArrayList<>(keys.size()); 37 | for (String s : keys) { 38 | rv.add(getKeyBytes(s)); 39 | } 40 | return rv; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/MemcachedReplicaGroupROImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /* ENABLE_REPLICATION if */ 18 | package net.spy.memcached; 19 | 20 | public final class MemcachedReplicaGroupROImpl extends MemcachedReplicaGroup { 21 | public MemcachedReplicaGroupROImpl(final MemcachedReplicaGroup group) { 22 | super(group.getGroupName()); 23 | this.masterNode = new MemcachedNodeROImpl(group.getMasterNode()); 24 | for (MemcachedNode slaveNode : group.getSlaveNodes()) { 25 | slaveNodes.add(new MemcachedNodeROImpl(slaveNode)); 26 | } 27 | } 28 | 29 | @Override 30 | public boolean setMemcachedNode(MemcachedNode node) { 31 | throw new UnsupportedOperationException(); 32 | } 33 | 34 | @Override 35 | public boolean deleteMemcachedNode(MemcachedNode node) { 36 | throw new UnsupportedOperationException(); 37 | } 38 | 39 | @Override 40 | public boolean changeRole() { 41 | throw new UnsupportedOperationException(); 42 | } 43 | } 44 | /* ENABLE_REPLICATION end */ 45 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/MigrationState.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | public enum MigrationState { 4 | UNKNOWN, 5 | BEGIN, 6 | PREPARED, 7 | DONE; 8 | 9 | public static MigrationState fromString(String state) { 10 | if ("BEGIN".equals(state)) { 11 | return BEGIN; 12 | } else if ("PREPARED".equals(state)) { 13 | return PREPARED; 14 | } else if ("DONE".equals(state)) { 15 | return DONE; 16 | } 17 | 18 | return UNKNOWN; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/MigrationType.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | public enum MigrationType { 4 | UNKNOWN, 5 | JOIN, 6 | LEAVE; 7 | 8 | public static MigrationType fromString(String type) { 9 | if ("JOIN".equals(type)) { 10 | return JOIN; 11 | } else if ("LEAVE".equals(type)) { 12 | return LEAVE; 13 | } 14 | return UNKNOWN; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/NotExistsServiceCodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | public class NotExistsServiceCodeException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = -1461409015284668292L; 22 | 23 | public NotExistsServiceCodeException(String message) { 24 | super(message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/OperationTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | /** 20 | * Thrown by {@link MemcachedClient} when any internal operations timeout. 21 | * 22 | * @author Ray Krueger 23 | * @see net.spy.memcached.ConnectionFactory#getOperationTimeout() 24 | */ 25 | public class OperationTimeoutException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = 1479557202445843619L; 28 | 29 | public OperationTimeoutException(String message) { 30 | super(message); 31 | } 32 | 33 | public OperationTimeoutException(Throwable cause) { 34 | super(cause); 35 | } 36 | 37 | public OperationTimeoutException(String message, Throwable cause) { 38 | super(message, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ReadPriority.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /* ENABLE_REPLICATION if */ 18 | package net.spy.memcached; 19 | 20 | /** 21 | * Read priority for read operation 22 | */ 23 | public enum ReadPriority { 24 | 25 | /** 26 | * Read on Master 27 | */ 28 | MASTER, 29 | 30 | /** 31 | * Read on Slave 32 | */ 33 | SLAVE, 34 | 35 | /** 36 | * Read RR(Round-robin) pattern. 37 | */ 38 | RR, 39 | } 40 | /* ENABLE_REPLICATION end */ 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ReplicaPick.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2021 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | /* ENABLE_REPLICATION if */ 19 | package net.spy.memcached; 20 | 21 | /** 22 | * Which replica node should we pick ? 23 | */ 24 | enum ReplicaPick { 25 | 26 | /** 27 | * Pick Master node. 28 | */ 29 | MASTER, 30 | 31 | /** 32 | * Pick Slave node. 33 | */ 34 | SLAVE, 35 | 36 | /** 37 | * Pick any node RR(Round-robin) pattern. 38 | */ 39 | RR 40 | } 41 | /* ENABLE_REPLICATION end */ 42 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/auth/PlainCallbackHandler.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.auth; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.security.auth.callback.Callback; 6 | import javax.security.auth.callback.CallbackHandler; 7 | import javax.security.auth.callback.NameCallback; 8 | import javax.security.auth.callback.PasswordCallback; 9 | import javax.security.auth.callback.TextOutputCallback; 10 | import javax.security.auth.callback.UnsupportedCallbackException; 11 | 12 | /** 13 | * Callback handler for doing plain auth. 14 | */ 15 | public class PlainCallbackHandler implements CallbackHandler { 16 | 17 | private final String username; 18 | private final char[] password; 19 | 20 | /** 21 | * Construct a plain callback handler with the given username and password. 22 | * 23 | * @param u the username 24 | * @param p the password 25 | */ 26 | public PlainCallbackHandler(String u, String p) { 27 | username = u; 28 | password = p.toCharArray(); 29 | } 30 | 31 | public void handle(Callback[] callbacks) throws IOException, 32 | UnsupportedCallbackException { 33 | for (Callback cb : callbacks) { 34 | if (cb instanceof TextOutputCallback) { 35 | // Not implementing this one yet... 36 | } else if (cb instanceof NameCallback) { 37 | NameCallback nc = (NameCallback) cb; 38 | nc.setName(username); 39 | } else if (cb instanceof PasswordCallback) { 40 | PasswordCallback pc = (PasswordCallback) cb; 41 | pc.setPassword(password); 42 | } else { 43 | throw new UnsupportedCallbackException(cb); 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/auth/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Auth Utilities. 8 | 9 | 10 | 11 |

Auth Utilities.

12 |

13 | Extra utilities for authentication management. 14 |

15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class BTreeCreate extends CollectionCreate { 20 | 21 | private static final String COMMAND = "bop create"; 22 | 23 | public BTreeCreate(int flags, Integer expTime, Long maxCount, 24 | CollectionOverflowAction overflowAction, Boolean readable, boolean noreply) { 25 | super(CollectionType.btree, flags, expTime, maxCount, overflowAction, readable, noreply); 26 | } 27 | 28 | public String getCommand() { 29 | return COMMAND; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | import java.util.Arrays; 20 | import java.util.Objects; 21 | 22 | public class BTreeElement { 23 | private final K bkey; 24 | private final V value; 25 | private final byte[] eflag; 26 | 27 | public BTreeElement(K bkey, byte[] eflag, V value) { 28 | this.bkey = bkey; 29 | this.eflag = eflag; 30 | this.value = value; 31 | } 32 | 33 | public K getBkey() { 34 | return bkey; 35 | } 36 | 37 | public V getValue() { 38 | return value; 39 | } 40 | 41 | public byte[] getEflag() { 42 | return eflag; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object o) { 47 | if (this == o) { 48 | return true; 49 | } 50 | if (!(o instanceof BTreeElement)) { 51 | return false; 52 | } 53 | 54 | BTreeElement that = (BTreeElement) o; 55 | return Objects.equals(bkey, that.bkey) && 56 | Objects.equals(value, that.value) && 57 | Arrays.equals(eflag, that.eflag); 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return Objects.hash(bkey, value, Arrays.hashCode(eflag)); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeGetBulk.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | import java.util.List; 20 | 21 | import net.spy.memcached.MemcachedNode; 22 | 23 | public interface BTreeGetBulk { 24 | 25 | int HEADER_COUNT = 3; 26 | 27 | void setKeySeparator(String keySeparator); 28 | 29 | String getSpaceSeparatedKeys(); 30 | 31 | MemcachedNode getMemcachedNode(); 32 | 33 | List getKeyList(); 34 | 35 | String stringify(); 36 | 37 | String getCommand(); 38 | 39 | boolean headerReady(int spaceCount); 40 | 41 | Object getBkey(); 42 | 43 | int getDataLength(); 44 | 45 | byte[] getEFlag(); 46 | 47 | void decodeItemHeader(String[] splited); 48 | 49 | BTreeGetBulk clone(MemcachedNode node, List keyList); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeInsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class BTreeInsert extends CollectionInsert { 20 | 21 | private static final String command = "bop insert"; 22 | 23 | public BTreeInsert(T value, byte[] eFlag, RequestMode requestMode, CollectionAttributes attr) { 24 | super(CollectionType.btree, value, eFlag, requestMode, attr); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | /** 20 | * A type component for "bop position" and "bop gbp" 21 | */ 22 | public enum BTreeOrder { 23 | ASC("asc"), 24 | DESC("desc"); 25 | 26 | private String ascii; 27 | 28 | BTreeOrder(String ascii) { 29 | this.ascii = ascii; 30 | } 31 | 32 | public String getAscii() { 33 | return ascii; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeSMGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | import java.util.List; 20 | 21 | import net.spy.memcached.MemcachedNode; 22 | 23 | public interface BTreeSMGet { 24 | 25 | int headerCount = 4; 26 | 27 | void setKeySeparator(String keySeparator); 28 | 29 | String getSpaceSeparatedKeys(); 30 | 31 | MemcachedNode getMemcachedNode(); 32 | 33 | List getKeyList(); 34 | 35 | String stringify(); 36 | 37 | String getCommand(); 38 | 39 | boolean headerReady(int spaceCount); 40 | 41 | String getKey(); 42 | 43 | int getFlags(); 44 | 45 | Object getBkey(); 46 | 47 | int getDataLength(); 48 | 49 | byte[] getEflag(); 50 | 51 | void decodeItemHeader(String itemHeader); 52 | 53 | BTreeSMGet clone(MemcachedNode node, List keyList); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class BTreeUpdate extends CollectionUpdate { 20 | 21 | private static final String command = "bop update"; 22 | 23 | public BTreeUpdate(T newValue, ElementFlagUpdate elementFlagUpdate, boolean noreply) { 24 | super(newValue, elementFlagUpdate, noreply); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/BTreeUpsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class BTreeUpsert extends CollectionInsert { 20 | 21 | private static final String command = "bop upsert"; 22 | 23 | public BTreeUpsert(T value, byte[] eFlag, RequestMode requestMode, CollectionAttributes attr) { 24 | super(CollectionType.btree, value, eFlag, requestMode, attr); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/ByteArrayTreeMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | import java.util.Comparator; 20 | import java.util.TreeMap; 21 | 22 | public final class ByteArrayTreeMap extends TreeMap { 23 | 24 | private static final long serialVersionUID = -304580135331634224L; 25 | 26 | public ByteArrayTreeMap(Comparator comparator) { 27 | super(comparator); 28 | } 29 | 30 | @Override 31 | public V get(Object key) { 32 | if (key instanceof byte[]) { 33 | return super.get(new ByteArrayBKey((byte[]) key)); 34 | } else { 35 | return super.get(key); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/CollectionCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public abstract class CollectionCount { 20 | protected String str; 21 | 22 | public abstract String stringify(); 23 | 24 | public abstract String getCommand(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/CollectionDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public abstract class CollectionDelete { 20 | 21 | protected String range; 22 | protected boolean noreply; 23 | protected boolean dropIfEmpty = true; 24 | 25 | protected String str; 26 | 27 | public abstract byte[] getAdditionalArgs(); 28 | 29 | public abstract String stringify(); 30 | 31 | public abstract String getCommand(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/CollectionExist.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public abstract class CollectionExist { 20 | 21 | protected String str; 22 | 23 | public abstract byte[] getAdditionalArgs(); 24 | 25 | public abstract String stringify(); 26 | 27 | public abstract String getCommand(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/CollectionMutate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public abstract class CollectionMutate { 20 | protected String str; 21 | 22 | public abstract String stringify(); 23 | 24 | public abstract String getCommand(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/CollectionObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | import java.nio.ByteBuffer; 20 | 21 | import net.spy.memcached.KeyUtil; 22 | import net.spy.memcached.compat.SpyObject; 23 | 24 | public class CollectionObject extends SpyObject { 25 | 26 | protected static final byte[] CRLF = {'\r', '\n'}; 27 | 28 | /** 29 | * Set some arguments for an operation into the given byte buffer. 30 | */ 31 | protected final void setArguments(ByteBuffer bb, Object... args) { 32 | boolean wasFirst = true; 33 | for (Object o : args) { 34 | String s = String.valueOf(o); 35 | if (wasFirst) { 36 | wasFirst = false; 37 | } else if (!"".equals(s)) { 38 | bb.put((byte) ' '); 39 | } 40 | bb.put(KeyUtil.getKeyBytes(s)); 41 | } 42 | bb.put(CRLF); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/CollectionPipe.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.collection; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public abstract class CollectionPipe extends CollectionObject { 6 | 7 | public static final String PIPE = "pipe"; 8 | 9 | protected final int itemCount; 10 | protected int nextOpIndex = 0; 11 | 12 | protected CollectionPipe(int itemCount) { 13 | this.itemCount = itemCount; 14 | } 15 | 16 | public int getItemCount() { 17 | return this.itemCount; 18 | } 19 | 20 | /** 21 | * set next index of operation 22 | * that will be processed after when operation 23 | * moved by switchover or redirected by migration. 24 | */ 25 | public void setNextOpIndex(int i) { 26 | this.nextOpIndex = i; 27 | } 28 | 29 | public boolean isNotPiped() { 30 | /* 31 | * We can consider two cases in this method. 32 | * 33 | * First, itemCount == 1 && nextOpIndex == 0. 34 | * In this case, there is only one line of ascii command. 35 | * Of course, there is no "pipe" keyword. 36 | * 37 | * Second, itemCount > 1 && nextOpIndex == itemCount - 1. 38 | * In this case, there is only one last line of ascii command 39 | * that is moved by switchover or redirected by migration. 40 | * Of course, there is no "pipe" keyword either. 41 | */ 42 | return itemCount - nextOpIndex == 1; 43 | } 44 | 45 | public ByteBuffer getBinaryCommand() { 46 | throw new RuntimeException("not supported in binary protocol yet."); 47 | } 48 | 49 | public abstract ByteBuffer getAsciiCommand(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/ListCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class ListCreate extends CollectionCreate { 20 | 21 | private static final String command = "lop create"; 22 | 23 | public ListCreate(int flags, Integer expTime, Long maxCount, 24 | CollectionOverflowAction overflowAction, Boolean readable, boolean noreply) { 25 | super(CollectionType.list, flags, expTime, maxCount, overflowAction, readable, noreply); 26 | } 27 | 28 | public String getCommand() { 29 | return command; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/ListDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class ListDelete extends CollectionDelete { 20 | 21 | private static final String command = "lop delete"; 22 | 23 | public ListDelete(int index, boolean dropIfEmpty, boolean noreply) { 24 | this.range = String.valueOf(index); 25 | this.dropIfEmpty = dropIfEmpty; 26 | this.noreply = noreply; 27 | } 28 | 29 | public ListDelete(int from, int to, boolean dropIfEmpty, boolean noreply) { 30 | this.range = from + ".." + to; 31 | this.dropIfEmpty = dropIfEmpty; 32 | this.noreply = noreply; 33 | } 34 | 35 | @Override 36 | public byte[] getAdditionalArgs() { 37 | return null; 38 | } 39 | 40 | public String stringify() { 41 | if (str != null) { 42 | return str; 43 | } 44 | 45 | StringBuilder b = new StringBuilder(); 46 | b.append(range); 47 | 48 | if (dropIfEmpty) { 49 | b.append(" drop"); 50 | } 51 | 52 | if (noreply) { 53 | b.append(" noreply"); 54 | } 55 | 56 | str = b.toString(); 57 | return str; 58 | } 59 | 60 | public String getCommand() { 61 | return command; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/ListInsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class ListInsert extends CollectionInsert { 20 | 21 | private static final String command = "lop insert"; 22 | 23 | public ListInsert(T value, RequestMode requestMode, CollectionAttributes attr) { 24 | super(CollectionType.list, value, null, requestMode, attr); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/MapCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2016 JaM2in Co., Ltd. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class MapCreate extends CollectionCreate { 20 | 21 | private static final String command = "mop create"; 22 | 23 | public MapCreate(int flags, Integer expTime, Long maxCount, Boolean readable, boolean noreply) { 24 | super(CollectionType.map, flags, expTime, maxCount, null, readable, noreply); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/MapInsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2016 JaM2in Co., Ltd. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class MapInsert extends CollectionInsert { 20 | 21 | private static final String command = "mop insert"; 22 | 23 | public MapInsert(T value, RequestMode requestMode, CollectionAttributes attr) { 24 | super(CollectionType.map, value, null, requestMode, attr); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/MapUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2016 JaM2in Co., Ltd. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class MapUpdate extends CollectionUpdate { 20 | 21 | private static final String command = "mop update"; 22 | 23 | public MapUpdate(T newValue, boolean noreply) { 24 | super(newValue, null, noreply); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/MapUpsert.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.collection; 2 | 3 | public class MapUpsert extends CollectionInsert { 4 | 5 | private static final String command = "mop upsert"; 6 | 7 | public MapUpsert(T value, CollectionAttributes attr) { 8 | super(CollectionType.map, value, null, null, attr); 9 | } 10 | 11 | @Override 12 | public String getCommand() { 13 | return command; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/RequestMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | /** 20 | * Optional request modes. 21 | */ 22 | public enum RequestMode { 23 | 24 | NO_REPLY("noreply"), PIPE("pipe"), GET_TRIM("getrim"); 25 | 26 | private final String ascii; 27 | 28 | RequestMode(String ascii) { 29 | this.ascii = ascii; 30 | } 31 | 32 | public String getAscii() { 33 | return ascii; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/SMGetMode.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.collection; 2 | 3 | /** 4 | * A type component for "bop smgetmode" 5 | */ 6 | public enum SMGetMode { 7 | UNIQUE("unique"), 8 | DUPLICATE("duplicate"); 9 | 10 | private String mode; 11 | 12 | SMGetMode(String mode) { 13 | this.mode = mode; 14 | } 15 | 16 | public String getMode() { 17 | return mode; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/SetCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class SetCreate extends CollectionCreate { 20 | 21 | private static final String command = "sop create"; 22 | 23 | public SetCreate(int flags, Integer expTime, Long maxCount, Boolean readable, boolean noreply) { 24 | super(CollectionType.set, flags, expTime, maxCount, null, readable, noreply); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/SetExist.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | import net.spy.memcached.transcoders.Transcoder; 20 | 21 | public class SetExist extends CollectionExist { 22 | 23 | private static final String command = "sop exist"; 24 | 25 | protected T value; 26 | protected byte[] additionalArgs; 27 | protected Transcoder tc; 28 | 29 | public SetExist(T value, Transcoder tc) { 30 | this.value = value; 31 | this.tc = tc; 32 | this.additionalArgs = tc.encode(value).getData(); 33 | } 34 | 35 | @Override 36 | public byte[] getAdditionalArgs() { 37 | return additionalArgs; 38 | } 39 | 40 | public String stringify() { 41 | return String.valueOf(additionalArgs.length); 42 | } 43 | 44 | public String getCommand() { 45 | return command; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/collection/SetInsert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection; 18 | 19 | public class SetInsert extends CollectionInsert { 20 | 21 | private static final String command = "sop insert"; 22 | 23 | public SetInsert(T value, RequestMode requestMode, CollectionAttributes attr) { 24 | super(CollectionType.set, value, null, requestMode, attr); 25 | } 26 | 27 | public String getCommand() { 28 | return command; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/compat/CloseUtil.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006 Dustin Sallings 2 | 3 | package net.spy.memcached.compat; 4 | 5 | import net.spy.memcached.compat.log.Logger; 6 | import net.spy.memcached.compat.log.LoggerFactory; 7 | 8 | 9 | /** 10 | * Superclass for all Spy Objects. 11 | */ 12 | public class SpyObject extends Object { 13 | 14 | private transient Logger logger = null; 15 | 16 | /** 17 | * Get an instance of SpyObject. 18 | */ 19 | public SpyObject() { 20 | super(); 21 | } 22 | 23 | /** 24 | * Get a Logger instance for this class. 25 | * 26 | * @return an appropriate logger instance. 27 | */ 28 | protected Logger getLogger() { 29 | if (logger == null) { 30 | logger = LoggerFactory.getLogger(getClass()); 31 | } 32 | return (logger); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/compat/SpyThread.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2002 Dustin Sallings 2 | 3 | package net.spy.memcached.compat; 4 | 5 | import net.spy.memcached.compat.log.Logger; 6 | import net.spy.memcached.compat.log.LoggerFactory; 7 | 8 | /** 9 | * Superclass for all Spy Threads. 10 | */ 11 | public class SpyThread extends Thread { 12 | 13 | private transient Logger logger = null; 14 | 15 | // Thread has *eight* constructors. Damnit. 16 | 17 | /** 18 | * Get an instance of SpyThread. 19 | */ 20 | public SpyThread() { 21 | super(); 22 | } 23 | 24 | /** 25 | * Get an instance of SpyThread with a name. 26 | * 27 | * @param name thread name 28 | */ 29 | public SpyThread(String name) { 30 | super(name); 31 | } 32 | 33 | /** 34 | * Get a Logger instance for this class. 35 | * 36 | * @return an appropriate logger instance. 37 | */ 38 | protected Logger getLogger() { 39 | if (logger == null) { 40 | logger = LoggerFactory.getLogger(getClass()); 41 | } 42 | return (logger); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/compat/log/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Logging Abstractions 8 | 9 | 10 | 11 |

Logging Abstractions

12 | 13 |

14 | Logging is performed through these logging abstractions that 15 | were pulled from another project and duplicated here to avoid a 16 | dependency (hence compat). 17 |

18 | 19 |

20 | For more information on logging, see the 21 | logging 22 | page on the project wiki. 23 |

24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/compat/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | spy.jar compatibility classes 8 | 9 | 10 | 11 |

spy.jar compatibility classes

12 | 13 |

14 | This package exists to remove the spy.jar dependency by copying 15 | some of the critical pieces into the client base itself. 16 |

17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/BasicThreadFactory.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.util.concurrent.ThreadFactory; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | /** 7 | * Simple thread factory that can set daemon status on threads and give them names. 8 | */ 9 | public class BasicThreadFactory implements ThreadFactory { 10 | 11 | private static final AtomicInteger poolNumber = new AtomicInteger(1); 12 | private final AtomicInteger threadNumber = new AtomicInteger(1); 13 | private final String namePrefix; 14 | private final boolean daemon; 15 | 16 | public BasicThreadFactory(String name, boolean daemon) { 17 | this.namePrefix = name + "-" + poolNumber.getAndIncrement() + "-"; 18 | this.daemon = daemon; 19 | } 20 | 21 | public Thread newThread(Runnable r) { 22 | Thread t = new Thread(r, namePrefix + threadNumber.getAndIncrement()); 23 | t.setDaemon(daemon); 24 | return t; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/BulkFuture.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.util.concurrent.Future; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | /** 7 | * Additional flexibility for asyncGetBulk 8 | * 9 | *

10 | * This interface is now returned from all asyncGetBulk 11 | * methods. Unlike {@link #get(long, TimeUnit)}, 12 | * {@link #getSome(long, TimeUnit)} does not throw 13 | * CheckedOperationTimeoutException, thus allowing retrieval 14 | * of partial results after timeout occurs. This behavior is 15 | * especially useful in case of large multi gets. 16 | *

17 | * 18 | * @param 19 | * @author boris.partensky@gmail.com 20 | */ 21 | public interface BulkFuture extends Future { 22 | 23 | /** 24 | * @return true if timeout was reached, false otherwise 25 | */ 26 | boolean isTimeout(); 27 | 28 | /** 29 | * Wait for the operation to complete and return results. 30 | * 31 | * If operation could not complete within specified timeout, error, cancellation occurred, 32 | * partial result is returned. 33 | * Otherwise, the behavior is identical to {@link #get(long, TimeUnit)} 34 | * 35 | * @param timeout the maximum time to wait 36 | * @param unit the time unit of the timeout argument 37 | * @return the computed result 38 | * @throws InterruptedException if the current thread was interrupted while waiting 39 | */ 40 | V getSome(long timeout, TimeUnit unit) throws InterruptedException; 41 | 42 | 43 | int getOpCount(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/CollectionFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.internal; 18 | 19 | import java.util.concurrent.CountDownLatch; 20 | import java.util.concurrent.atomic.AtomicReference; 21 | 22 | import net.spy.memcached.ops.CollectionOperationStatus; 23 | 24 | /** 25 | * Managed future for collection operations. 26 | * 27 | * Not intended for general use. 28 | * 29 | * @param Type of object returned from this future. 30 | */ 31 | public class CollectionFuture extends OperationFuture { 32 | protected CollectionOperationStatus collectionOpStatus; 33 | 34 | public CollectionFuture(CountDownLatch l, long opTimeout) { 35 | this(l, new AtomicReference<>(null), opTimeout); 36 | } 37 | 38 | public CollectionFuture(CountDownLatch l, AtomicReference oref, 39 | long opTimeout) { 40 | super(l, oref, opTimeout); 41 | } 42 | 43 | public void set(T o, CollectionOperationStatus status) { 44 | super.set(o, status); 45 | collectionOpStatus = status; 46 | } 47 | 48 | public CollectionOperationStatus getOperationStatus() { 49 | return this.isDone() ? collectionOpStatus : null; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/CollectionGetFuture.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.ExecutionException; 5 | import java.util.concurrent.TimeUnit; 6 | import java.util.concurrent.TimeoutException; 7 | 8 | import net.spy.memcached.internal.result.GetResult; 9 | import net.spy.memcached.ops.CollectionOperationStatus; 10 | 11 | public class CollectionGetFuture extends CollectionFuture { 12 | private GetResult result; 13 | 14 | public CollectionGetFuture(CountDownLatch l, long opTimeout) { 15 | super(l, opTimeout); 16 | } 17 | 18 | @Override 19 | public T get(long duration, TimeUnit unit) 20 | throws InterruptedException, TimeoutException, ExecutionException { 21 | super.get(duration, unit); // for waiting latch. 22 | return result == null ? null : result.getDecodedValue(); 23 | } 24 | 25 | public void setResult(GetResult result, CollectionOperationStatus status) { 26 | super.set(null, status); 27 | this.result = result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/CompositeException.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.concurrent.ExecutionException; 8 | 9 | import net.spy.memcached.ExceptionMessageFactory; 10 | 11 | public class CompositeException extends ExecutionException { 12 | 13 | private static final long serialVersionUID = -599478797582490012L; 14 | private final ArrayList exceptions = new ArrayList<>(); 15 | private final Throwable cause; 16 | 17 | public CompositeException(List exceptions) { 18 | super(ExceptionMessageFactory.createCompositeMessage(exceptions)); 19 | 20 | if (exceptions.size() > 1) { 21 | StringWriter sw = new StringWriter(); 22 | sw.write(System.lineSeparator()); 23 | try (PrintWriter pw = new PrintWriter(sw)) { 24 | for (Exception e : exceptions) { 25 | e.printStackTrace(pw); 26 | } 27 | } 28 | 29 | this.cause = new ExceptionOverview(sw.toString()); 30 | } else { 31 | this.cause = exceptions.get(0); 32 | } 33 | this.exceptions.addAll(exceptions); 34 | } 35 | 36 | public List getExceptions() { 37 | return exceptions; 38 | } 39 | 40 | public int size() { 41 | return exceptions.size(); 42 | } 43 | 44 | @Override 45 | public synchronized Throwable getCause() { 46 | return cause; 47 | } 48 | 49 | static final class ExceptionOverview extends RuntimeException { 50 | 51 | private static final long serialVersionUID = -641960514509105302L; 52 | 53 | ExceptionOverview(String message) { 54 | super(message); 55 | } 56 | 57 | @Override 58 | public synchronized Throwable fillInStackTrace() { 59 | return this; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/GetFuture.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.ExecutionException; 5 | import java.util.concurrent.TimeUnit; 6 | import java.util.concurrent.TimeoutException; 7 | 8 | import net.spy.memcached.internal.result.GetResult; 9 | import net.spy.memcached.ops.OperationStatus; 10 | 11 | /** 12 | * Future returned for GET operations. 13 | * 14 | * Not intended for general use. 15 | * 16 | * @param Type of object returned from the get 17 | */ 18 | public class GetFuture extends OperationFuture { 19 | private GetResult result; 20 | 21 | public GetFuture(CountDownLatch l, long opTimeout) { 22 | super(l, opTimeout); 23 | } 24 | 25 | @Override 26 | public T get(long duration, TimeUnit unit) 27 | throws InterruptedException, TimeoutException, ExecutionException { 28 | super.get(duration, unit); // for waiting latch. 29 | return result == null ? null : result.getDecodedValue(); 30 | } 31 | 32 | public void set(GetResult result, OperationStatus status) { 33 | super.set(null, status); 34 | this.result = result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/ImmediateFuture.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package net.spy.memcached.internal; 5 | 6 | import java.util.concurrent.ExecutionException; 7 | import java.util.concurrent.Future; 8 | import java.util.concurrent.TimeUnit; 9 | import java.util.concurrent.TimeoutException; 10 | 11 | /** 12 | * A future that fires immediately. 13 | */ 14 | public class ImmediateFuture implements Future { 15 | private final Boolean value; 16 | private final ExecutionException exception; 17 | 18 | public ImmediateFuture(Boolean returnValue) { 19 | value = returnValue; 20 | exception = null; 21 | } 22 | 23 | public ImmediateFuture(Exception e) { 24 | value = null; 25 | exception = new ExecutionException(e); 26 | } 27 | 28 | public boolean cancel(boolean mayInterruptIfRunning) { 29 | return false; 30 | } 31 | 32 | public Boolean get() throws InterruptedException, ExecutionException { 33 | if (exception != null) { 34 | throw exception; 35 | } 36 | return value; 37 | } 38 | 39 | public Boolean get(long timeout, TimeUnit unit) 40 | throws InterruptedException, ExecutionException, 41 | TimeoutException { 42 | if (exception != null) { 43 | throw exception; 44 | } 45 | return value; 46 | } 47 | 48 | public boolean isCancelled() { 49 | return false; 50 | } 51 | 52 | public boolean isDone() { 53 | return true; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/ReconnDelay.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | public enum ReconnDelay { 4 | IMMEDIATE, 5 | DEFAULT, 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/ReconnectJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.internal; 18 | 19 | import net.spy.memcached.ArcusClient; 20 | import net.spy.memcached.ConnectionFactoryBuilder; 21 | 22 | public class ReconnectJob { 23 | 24 | private final String hostPort; 25 | private final String serviceCode; 26 | private final ConnectionFactoryBuilder cfb; 27 | private final ArcusClient[] client; 28 | 29 | public ReconnectJob(String hostPort, String serviceCode, 30 | ConnectionFactoryBuilder cfb, ArcusClient[] client) { 31 | super(); 32 | this.hostPort = hostPort; 33 | this.serviceCode = serviceCode; 34 | this.cfb = cfb; 35 | this.client = client; 36 | } 37 | 38 | public String getHostPort() { 39 | return hostPort; 40 | } 41 | 42 | public String getServiceCode() { 43 | return serviceCode; 44 | } 45 | 46 | public ConnectionFactoryBuilder getCfb() { 47 | return cfb; 48 | } 49 | 50 | public ArcusClient[] getClient() { 51 | return client; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/SingleElementInfiniteIterator.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.util.Iterator; 4 | 5 | /** 6 | * An iterator that returns a single element for as many elements as 7 | * are needed from the iterator; in other words, #hasNext() never 8 | * returns false. 9 | */ 10 | public class SingleElementInfiniteIterator 11 | implements Iterator { 12 | private final T element; 13 | 14 | /** 15 | * Construct a iterator tat returns the input element an 16 | * infinite number of times. 17 | * 18 | * @param element the element that #next() should return 19 | */ 20 | public SingleElementInfiniteIterator(T element) { 21 | this.element = element; 22 | } 23 | 24 | public boolean hasNext() { 25 | return true; 26 | } 27 | 28 | public T next() { 29 | return element; 30 | } 31 | 32 | public void remove() { 33 | throw new UnsupportedOperationException("Cannot remove from this iterator."); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Internal utilities. 8 | 9 | 10 | 11 |

Internal utilities.

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/BopGetBulkResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import net.spy.memcached.CachedData; 8 | import net.spy.memcached.collection.BTreeElement; 9 | import net.spy.memcached.collection.BTreeGetResult; 10 | import net.spy.memcached.ops.CollectionOperationStatus; 11 | import net.spy.memcached.transcoders.Transcoder; 12 | 13 | public class BopGetBulkResultImpl implements GetResult>> { 14 | private final Map>> cachedDataMap; 15 | private final Map opStatusMap; 16 | private final boolean reverse; 17 | private final Transcoder transcoder; 18 | private Map> result 19 | = new HashMap<>(); 20 | 21 | public BopGetBulkResultImpl(Map>> cachedDataMap, 22 | Map opStatusMap, 23 | boolean reverse, Transcoder transcoder) { 24 | this.cachedDataMap = cachedDataMap; 25 | this.opStatusMap = opStatusMap; 26 | this.reverse = reverse; 27 | this.transcoder = transcoder; 28 | } 29 | 30 | @Override 31 | public Map> getDecodedValue() { 32 | if (result.isEmpty() && !opStatusMap.isEmpty()) { 33 | Map> temp = new HashMap<>(result); 34 | for (Map.Entry entry : opStatusMap.entrySet()) { 35 | String key = entry.getKey(); 36 | temp.put(key, new BTreeGetResult<>(cachedDataMap.get(key), 37 | reverse, transcoder, entry.getValue())); 38 | } 39 | result = temp; 40 | } 41 | return result; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/BopGetByPositionResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | import java.util.SortedMap; 6 | import java.util.TreeMap; 7 | 8 | import net.spy.memcached.CachedData; 9 | import net.spy.memcached.collection.BKeyObject; 10 | import net.spy.memcached.collection.Element; 11 | import net.spy.memcached.transcoders.Transcoder; 12 | import net.spy.memcached.util.BTreeUtil; 13 | 14 | public class BopGetByPositionResultImpl implements GetResult>> { 15 | private final Map> cachedDataMap; 16 | private final Transcoder transcoder; 17 | private SortedMap> result; 18 | 19 | public BopGetByPositionResultImpl(Map> cachedDataMap, 20 | boolean reverse, 21 | Transcoder transcoder) { 22 | this.cachedDataMap = cachedDataMap; 23 | this.result = new TreeMap<>((reverse) ? Collections.reverseOrder() : null); 24 | this.transcoder = transcoder; 25 | } 26 | 27 | @Override 28 | public Map> getDecodedValue() { 29 | if (result.isEmpty() && !cachedDataMap.isEmpty()) { 30 | SortedMap> temp = new TreeMap<>(result); 31 | for (Map.Entry> entry : cachedDataMap.entrySet()) { 32 | Map.Entry cachedDataEntry = entry.getValue(); 33 | temp.put(entry.getKey(), BTreeUtil.makeBTreeElement( 34 | cachedDataEntry.getKey(), cachedDataEntry.getValue(), transcoder)); 35 | } 36 | result = temp; 37 | } 38 | return result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/BopStoreAndGetResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import net.spy.memcached.CachedData; 4 | import net.spy.memcached.collection.BKeyObject; 5 | import net.spy.memcached.collection.Element; 6 | import net.spy.memcached.transcoders.Transcoder; 7 | import net.spy.memcached.util.BTreeUtil; 8 | 9 | public class BopStoreAndGetResultImpl implements GetResult> { 10 | private final BKeyObject bKeyObject; 11 | private final CachedData cachedData; 12 | private final Transcoder transcoder; 13 | private Element result = null; 14 | 15 | public BopStoreAndGetResultImpl(BKeyObject bKeyObject, 16 | CachedData cachedData, 17 | Transcoder transcoder) { 18 | this.bKeyObject = bKeyObject; 19 | this.cachedData = cachedData; 20 | this.transcoder = transcoder; 21 | } 22 | 23 | @Override 24 | public Element getDecodedValue() { 25 | if (cachedData != null && result == null) { 26 | result = BTreeUtil.makeBTreeElement(bKeyObject, cachedData, transcoder); 27 | } 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/GetResult.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | public interface GetResult { 4 | T getDecodedValue(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/GetResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import net.spy.memcached.CachedData; 4 | import net.spy.memcached.transcoders.Transcoder; 5 | 6 | public final class GetResultImpl implements GetResult { 7 | private final CachedData cachedData; 8 | private final Transcoder transcoder; 9 | private volatile T decodedValue = null; 10 | 11 | public GetResultImpl(CachedData cachedData, Transcoder transcoder) { 12 | this.cachedData = cachedData; 13 | this.transcoder = transcoder; 14 | } 15 | 16 | @Override 17 | public T getDecodedValue() { 18 | if (decodedValue == null) { 19 | decodedValue = transcoder.decode(cachedData); 20 | } 21 | return decodedValue; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/GetsResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import net.spy.memcached.CASValue; 4 | import net.spy.memcached.CachedData; 5 | import net.spy.memcached.transcoders.Transcoder; 6 | 7 | public class GetsResultImpl implements GetResult> { 8 | private final long cas; 9 | private final CachedData cachedData; 10 | private final Transcoder transcoder; 11 | private volatile CASValue decodedValue = null; 12 | 13 | public GetsResultImpl(long cas, CachedData cachedData, Transcoder transcoder) { 14 | this.cas = cas; 15 | this.cachedData = cachedData; 16 | this.transcoder = transcoder; 17 | } 18 | 19 | @Override 20 | public CASValue getDecodedValue() { 21 | if (decodedValue == null) { 22 | decodedValue = new CASValue<>(cas, transcoder.decode(cachedData)); 23 | } 24 | return decodedValue; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/LopGetResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import net.spy.memcached.CachedData; 7 | import net.spy.memcached.transcoders.Transcoder; 8 | 9 | public class LopGetResultImpl implements GetResult> { 10 | private final List cachedDataList; 11 | private final Transcoder transcoder; 12 | private List result = new ArrayList<>(); 13 | 14 | public LopGetResultImpl(List cachedDataList, Transcoder transcoder) { 15 | this.cachedDataList = cachedDataList; 16 | this.transcoder = transcoder; 17 | } 18 | 19 | @Override 20 | public List getDecodedValue() { 21 | if (result.isEmpty() && !cachedDataList.isEmpty()) { 22 | List temp = new ArrayList<>(); 23 | for (CachedData cachedData : cachedDataList) { 24 | temp.add(transcoder.decode(cachedData)); 25 | } 26 | result = temp; 27 | } 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/MopGetResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import net.spy.memcached.CachedData; 7 | import net.spy.memcached.transcoders.Transcoder; 8 | 9 | public class MopGetResultImpl implements GetResult> { 10 | private final Map cachedDataMap; 11 | private final Transcoder transcoder; 12 | private Map result = new HashMap<>(); 13 | 14 | public MopGetResultImpl(Map cachedDataMap, Transcoder transcoder) { 15 | this.cachedDataMap = cachedDataMap; 16 | this.transcoder = transcoder; 17 | } 18 | 19 | @Override 20 | public Map getDecodedValue() { 21 | if (result.isEmpty() && !cachedDataMap.isEmpty()) { 22 | Map temp = new HashMap<>(); 23 | for (Map.Entry entry : cachedDataMap.entrySet()) { 24 | temp.put(entry.getKey(), transcoder.decode(entry.getValue())); 25 | } 26 | result = temp; 27 | } 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/internal/result/SopGetResultImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal.result; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import net.spy.memcached.CachedData; 7 | import net.spy.memcached.transcoders.Transcoder; 8 | 9 | public class SopGetResultImpl implements GetResult> { 10 | private final Set cachedDataSet; 11 | private final Transcoder transcoder; 12 | private Set result = new HashSet<>(); 13 | 14 | public SopGetResultImpl(Set cachedDataSet, Transcoder transcoder) { 15 | this.cachedDataSet = cachedDataSet; 16 | this.transcoder = transcoder; 17 | } 18 | 19 | @Override 20 | public Set getDecodedValue() { 21 | if (result.isEmpty() && !cachedDataSet.isEmpty()) { 22 | Set temp = new HashSet<>(); 23 | for (CachedData cachedData : cachedDataSet) { 24 | temp.add(transcoder.decode(cachedData)); 25 | } 26 | result = temp; 27 | } 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/ArrayOperationQueueFactory.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import java.util.concurrent.ArrayBlockingQueue; 4 | import java.util.concurrent.BlockingQueue; 5 | 6 | /** 7 | * OperationQueueFactory that uses an ArrayBlockingQueue. 8 | */ 9 | public class ArrayOperationQueueFactory implements OperationQueueFactory { 10 | 11 | private final int capacity; 12 | 13 | /** 14 | * Create an ArrayOperationQueueFactory that creates blocking queues with 15 | * the given capacity. 16 | * 17 | * @param cap maximum size of a queue produced by this factory 18 | */ 19 | public ArrayOperationQueueFactory(int cap) { 20 | super(); 21 | capacity = cap; 22 | } 23 | 24 | public BlockingQueue create() { 25 | return new ArrayBlockingQueue<>(capacity); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeFindPositionOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.BTreeFindPosition; 20 | 21 | public interface BTreeFindPositionOperation extends KeyedOperation { 22 | 23 | BTreeFindPosition getGet(); 24 | 25 | interface Callback extends OperationCallback { 26 | void gotData(int position); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeFindPositionWithGetOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.BKeyObject; 20 | import net.spy.memcached.collection.BTreeFindPositionWithGet; 21 | 22 | public interface BTreeFindPositionWithGetOperation extends KeyedOperation { 23 | 24 | BTreeFindPositionWithGet getGet(); 25 | 26 | interface Callback extends OperationCallback { 27 | void gotData(int pos, int flags, BKeyObject bkey, byte[] eflag, byte[] data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeGetBulkOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.BTreeGetBulk; 20 | 21 | public interface BTreeGetBulkOperation extends KeyedOperation { 22 | BTreeGetBulk getBulk(); 23 | 24 | interface Callback extends OperationCallback { 25 | void gotElement(String key, int flags, Object bkey, byte[] eflag, byte[] data); 26 | 27 | void gotKey(String key, int elementCount, OperationStatus status); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeGetByPositionOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.BKeyObject; 20 | import net.spy.memcached.collection.BTreeGetByPosition; 21 | 22 | public interface BTreeGetByPositionOperation extends KeyedOperation { 23 | BTreeGetByPosition getGet(); 24 | 25 | interface Callback extends OperationCallback { 26 | void gotData(int pos, int flags, BKeyObject bkey, byte[] eflag, byte[] data); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeInsertAndGetOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.BKeyObject; 20 | import net.spy.memcached.collection.BTreeInsertAndGet; 21 | 22 | public interface BTreeInsertAndGetOperation extends KeyedOperation { 23 | 24 | BTreeInsertAndGet getGet(); 25 | 26 | interface Callback extends OperationCallback { 27 | void gotData(int flags, BKeyObject bkeyObject, byte[] elementFlag, byte[] data); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeSortMergeGetOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.BTreeSMGet; 20 | 21 | public interface BTreeSortMergeGetOperation extends KeyedOperation { 22 | BTreeSMGet getSMGet(); 23 | 24 | interface Callback extends OperationCallback { 25 | void gotData(String key, int flags, Object bkey, byte[] eflag, byte[] data); 26 | 27 | void gotMissedKey(String key, OperationStatus cause); 28 | 29 | void gotTrimmedKey(String key, Object bkey); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/BTreeSortMergeGetOperationOld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | public interface BTreeSortMergeGetOperationOld extends KeyedOperation { 20 | interface Callback extends OperationCallback { 21 | void gotData(String key, int flags, Object bkey, byte[] eflag, byte[] data); 22 | 23 | void gotMissedKey(byte[] data); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CASOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Operation that represents compare-and-swap. 5 | */ 6 | public interface CASOperation extends KeyedOperation { 7 | 8 | /** 9 | * Get the type of storage used by this CASOperation. 10 | */ 11 | StoreType getStoreType(); 12 | 13 | /** 14 | * Get the CAS value advised for this operation. 15 | */ 16 | long getCasValue(); 17 | 18 | /** 19 | * Get the flags to be set for this operation. 20 | */ 21 | int getFlags(); 22 | 23 | /** 24 | * Get the expiration to be set for this operation. 25 | */ 26 | int getExpiration(); 27 | 28 | /** 29 | * Get the bytes to be set during this operation. 30 | * 31 | *

32 | * Note, this returns an exact reference to the bytes and the data 33 | * must not be modified. 34 | *

35 | */ 36 | byte[] getBytes(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CASOperationStatus.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import net.spy.memcached.CASResponse; 4 | 5 | /** 6 | * OperationStatus subclass for indicating CAS status. 7 | */ 8 | public class CASOperationStatus extends OperationStatus { 9 | 10 | private final CASResponse casResponse; 11 | 12 | public CASOperationStatus(boolean success, String msg, CASResponse cres, StatusCode code) { 13 | super(success, msg, code); 14 | casResponse = cres; 15 | } 16 | 17 | /** 18 | * Get the CAS response indicated here. 19 | */ 20 | public CASResponse getCASResponse() { 21 | return casResponse; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CancelledOperationStatus.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Operation status indicating an operation was cancelled. 5 | */ 6 | public class CancelledOperationStatus extends OperationStatus { 7 | 8 | public CancelledOperationStatus() { 9 | super(false, "cancelled", StatusCode.CANCELLED); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionBulkInsertOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionBulkInsert; 20 | 21 | /** 22 | * Operation that represents collection object storage. 23 | */ 24 | public interface CollectionBulkInsertOperation extends KeyedOperation { 25 | 26 | CollectionBulkInsert getInsert(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionCountOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | /** 20 | * Operation that represents empty collection object create. 21 | */ 22 | public interface CollectionCountOperation extends KeyedOperation { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionCreateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionCreate; 20 | 21 | /** 22 | * Operation that represents empty collection object create. 23 | */ 24 | public interface CollectionCreateOperation extends KeyedOperation { 25 | 26 | CollectionCreate getCreate(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionDeleteOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionDelete; 20 | 21 | /** 22 | * Operation that represents collection object deletion. 23 | */ 24 | public interface CollectionDeleteOperation extends KeyedOperation { 25 | 26 | CollectionDelete getDelete(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionExistOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionExist; 20 | 21 | /** 22 | * Operation that represents collection object membership check. 23 | */ 24 | public interface CollectionExistOperation extends KeyedOperation { 25 | 26 | String getSubKey(); 27 | 28 | CollectionExist getExist(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionGetOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionGet; 20 | 21 | /** 22 | * Operation that represents collection object retreival. 23 | */ 24 | public interface CollectionGetOperation extends KeyedOperation { 25 | 26 | CollectionGet getGet(); 27 | 28 | interface Callback extends OperationCallback { 29 | void gotData(String subkey, int flags, byte[] data, byte[] eflag); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionInsertOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionInsert; 20 | 21 | /** 22 | * Operation that represents collection object storage. 23 | */ 24 | public interface CollectionInsertOperation extends KeyedOperation { 25 | 26 | String getSubKey(); 27 | 28 | CollectionInsert getInsert(); 29 | 30 | byte[] getData(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionMutateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | /** 20 | * Operation that represents empty collection object create. 21 | */ 22 | public interface CollectionMutateOperation extends KeyedOperation { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionPipedExistOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.SetPipedExist; 20 | 21 | /** 22 | * Operation that represents collection object storage. 23 | */ 24 | public interface CollectionPipedExistOperation extends KeyedOperation { 25 | 26 | SetPipedExist getExist(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionPipedInsertOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionPipedInsert; 20 | 21 | /** 22 | * Operation that represents collection object storage. 23 | */ 24 | public interface CollectionPipedInsertOperation extends KeyedOperation { 25 | 26 | CollectionPipedInsert getInsert(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionPipedUpdateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionPipedUpdate; 20 | 21 | /** 22 | * Operation that represents collection object storage. 23 | */ 24 | public interface CollectionPipedUpdateOperation extends KeyedOperation { 25 | 26 | CollectionPipedUpdate getUpdate(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/CollectionUpdateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.CollectionUpdate; 20 | 21 | /** 22 | * Operation that represents collection object update. 23 | */ 24 | public interface CollectionUpdateOperation extends KeyedOperation { 25 | 26 | String getSubKey(); 27 | 28 | CollectionUpdate getUpdate(); 29 | 30 | byte[] getData(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/ConcatenationOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * ConcatenationOperation is used to append or prepend data to an existing 5 | * object in the cache. 6 | */ 7 | public interface ConcatenationOperation extends KeyedOperation { 8 | 9 | /** 10 | * Get the concatenation type for this operation. 11 | */ 12 | ConcatenationType getStoreType(); 13 | 14 | /** 15 | * Get the CAS value sent with this operation. 16 | */ 17 | long getCasValue(); 18 | 19 | /** 20 | * Get the bytes to be set during this operation. 21 | * 22 | *

23 | * Note, this returns an exact reference to the bytes and the data 24 | * must not be modified. 25 | *

26 | */ 27 | byte[] getData(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/ConcatenationType.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Types of concatenation operations. 5 | */ 6 | public enum ConcatenationType { 7 | /** 8 | * Concatenate supplied data to the end of the existing data. 9 | */ 10 | append, 11 | /** 12 | * Concatenate existing data onto the end of the supplied data. 13 | */ 14 | prepend 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/DeleteOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | 4 | /** 5 | * Deletion operation. 6 | */ 7 | public interface DeleteOperation extends KeyedOperation { 8 | // nothing in particular. 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/FlushOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | 4 | /** 5 | * Flush operation marker. 6 | */ 7 | public interface FlushOperation extends Operation { 8 | // nothing 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/GetAttrOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | /** 20 | * GetAttr operation. 21 | */ 22 | public interface GetAttrOperation extends KeyedOperation { 23 | 24 | /** 25 | * Operation callback for the get request. 26 | */ 27 | interface Callback extends OperationCallback { 28 | /** 29 | * Callback for each result from a get. 30 | * 31 | * @param key the key that was retrieved 32 | * @param attr an attribute(name=value) returned by the memcached server 33 | */ 34 | void gotAttribute(String key, String attr); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/GetOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | 4 | /** 5 | * Get operation. 6 | */ 7 | public interface GetOperation extends KeyedOperation { 8 | 9 | /** 10 | * Operation callback for the get request. 11 | */ 12 | interface Callback extends OperationCallback { 13 | /** 14 | * Callback for each result from a get. 15 | * 16 | * @param key the key that was retrieved 17 | * @param flags the flags for this value 18 | * @param data the data stored under this key 19 | */ 20 | void gotData(String key, int flags, byte[] data); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/GetsOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | 4 | /** 5 | * Gets operation (get with CAS identifier support). 6 | */ 7 | public interface GetsOperation extends KeyedOperation { 8 | 9 | /** 10 | * Operation callback for the Gets request. 11 | */ 12 | interface Callback extends OperationCallback { 13 | /** 14 | * Callback for each result from a gets. 15 | * 16 | * @param key the key that was retrieved 17 | * @param flags the flags for this value 18 | * @param cas the CAS value for this record 19 | * @param data the data stored under this key 20 | */ 21 | void gotData(String key, int flags, long cas, byte[] data); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/KeyedOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * Operations that contain keys. 7 | */ 8 | public interface KeyedOperation extends Operation { 9 | 10 | /** 11 | * Get the keys requested in this GetOperation. 12 | */ 13 | Collection getKeys(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/LinkedOperationQueueFactory.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import java.util.concurrent.BlockingQueue; 4 | import java.util.concurrent.LinkedBlockingQueue; 5 | 6 | /** 7 | * OperationQueueFactory that creates LinkedBlockingQueue (unbounded) operation 8 | * queues. 9 | */ 10 | public class LinkedOperationQueueFactory implements OperationQueueFactory { 11 | 12 | public BlockingQueue create() { 13 | return new LinkedBlockingQueue<>(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/MultiBTreeGetBulkOperationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.ops; 19 | 20 | public class MultiBTreeGetBulkOperationCallback extends MultiOperationCallback 21 | implements BTreeGetBulkOperation.Callback { 22 | 23 | public MultiBTreeGetBulkOperationCallback(OperationCallback original, int todo) { 24 | super(original, todo); 25 | } 26 | 27 | @Override 28 | public void gotElement(String key, int flags, Object bkey, byte[] eflag, byte[] data) { 29 | ((BTreeGetBulkOperation.Callback) originalCallback).gotElement(key, flags, bkey, eflag, data); 30 | } 31 | 32 | @Override 33 | public void gotKey(String key, int elementCount, OperationStatus status) { 34 | ((BTreeGetBulkOperation.Callback) originalCallback).gotKey(key, elementCount, status); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/MultiBTreeSortMergeGetOperationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.ops; 19 | 20 | public class MultiBTreeSortMergeGetOperationCallback extends MultiOperationCallback 21 | implements BTreeSortMergeGetOperation.Callback { 22 | 23 | public MultiBTreeSortMergeGetOperationCallback(OperationCallback original, int todo) { 24 | super(original, todo); 25 | } 26 | 27 | @Override 28 | public void gotData(String key, int flags, Object bkey, byte[] eflag, byte[] data) { 29 | ((BTreeSortMergeGetOperation.Callback) originalCallback).gotData(key, flags, 30 | bkey, eflag, data); 31 | } 32 | 33 | @Override 34 | public void gotMissedKey(String key, OperationStatus cause) { 35 | ((BTreeSortMergeGetOperation.Callback) originalCallback).gotMissedKey(key, cause); 36 | } 37 | 38 | @Override 39 | public void gotTrimmedKey(String key, Object bkey) { 40 | ((BTreeSortMergeGetOperation.Callback) originalCallback).gotTrimmedKey(key, bkey); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/MultiCollectionBulkInsertOperationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.ops; 19 | 20 | public class MultiCollectionBulkInsertOperationCallback extends MultiOperationCallback 21 | implements PipedOperationCallback { 22 | 23 | public MultiCollectionBulkInsertOperationCallback(OperationCallback original, int todo) { 24 | super(original, todo); 25 | } 26 | 27 | @Override 28 | public void gotStatus(Integer index, OperationStatus status) { 29 | ((PipedOperationCallback) originalCallback).gotStatus(index, status); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/MultiGetOperationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.ops; 19 | 20 | /** 21 | * MultiOperationCallback for get operations. 22 | */ 23 | public class MultiGetOperationCallback extends MultiOperationCallback 24 | implements GetOperation.Callback { 25 | 26 | public MultiGetOperationCallback(OperationCallback original, int todo) { 27 | super(original, todo); 28 | } 29 | 30 | @Override 31 | public void gotData(String key, int flags, byte[] data) { 32 | ((GetOperation.Callback) originalCallback).gotData(key, flags, data); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/MultiGetsOperationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.ops; 19 | 20 | /** 21 | * MultiOperationCallback for get operations. 22 | */ 23 | public class MultiGetsOperationCallback extends MultiOperationCallback 24 | implements GetsOperation.Callback { 25 | 26 | public MultiGetsOperationCallback(OperationCallback original, int todo) { 27 | super(original, todo); 28 | } 29 | 30 | @Override 31 | public void gotData(String key, int flags, long cas, byte[] data) { 32 | ((GetsOperation.Callback) originalCallback).gotData( 33 | key, flags, cas, data); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/Mutator.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Type of mutation to perform. 5 | */ 6 | public enum Mutator { 7 | /** 8 | * Increment a value on the memcached server. 9 | */ 10 | incr, 11 | /** 12 | * Decrement a value on the memcached server. 13 | */ 14 | decr 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/MutatorOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * incr and decr operations. 5 | */ 6 | public interface MutatorOperation extends KeyedOperation { 7 | 8 | /** 9 | * Get the mutator type used for this operation. 10 | */ 11 | Mutator getType(); 12 | 13 | /** 14 | * Get the amount we're mutating by. 15 | */ 16 | int getBy(); 17 | 18 | /** 19 | * Get the default value (for when there's no value to mutate). 20 | */ 21 | long getDefault(); 22 | 23 | /** 24 | * Get the expiration to set in case of a new entry. 25 | */ 26 | int getExpiration(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/NoopOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * The NOOP Operation. 5 | */ 6 | public interface NoopOperation extends Operation { 7 | // Nothing 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/OperationCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006 Dustin Sallings 2 | 3 | package net.spy.memcached.ops; 4 | 5 | /** 6 | * Callback that's invoked with the response of an operation. 7 | */ 8 | public interface OperationCallback { 9 | 10 | /** 11 | * Method invoked with the status when the operation is complete. 12 | * 13 | * @param status the result of the operation 14 | */ 15 | void receivedStatus(OperationStatus status); 16 | 17 | /** 18 | * Called whenever an operation completes. 19 | */ 20 | void complete(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/OperationErrorType.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Error classification. 5 | */ 6 | public enum OperationErrorType { 7 | /** 8 | * General error. 9 | */ 10 | GENERAL, 11 | /** 12 | * Error that occurred because the client did something stupid. 13 | */ 14 | CLIENT, 15 | /** 16 | * Error that occurred because the server did something stupid. 17 | */ 18 | SERVER; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/OperationException.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import java.io.IOException; 4 | 5 | 6 | /** 7 | * Exceptions thrown when protocol errors occur. 8 | */ 9 | public final class OperationException extends IOException { 10 | 11 | private static final long serialVersionUID = 2457625388445818437L; 12 | private final OperationErrorType type; 13 | 14 | /** 15 | * Exception with a message. 16 | * 17 | * @param eType the type of error that occurred 18 | * @param msg the error message 19 | */ 20 | public OperationException(OperationErrorType eType, String msg) { 21 | super(msg); 22 | type = eType; 23 | } 24 | 25 | /** 26 | * Get the type of error. 27 | */ 28 | public OperationErrorType getType() { 29 | return type; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "OperationException: " + type + ": " + getMessage(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/OperationQueueFactory.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import java.util.concurrent.BlockingQueue; 4 | 5 | 6 | /** 7 | * Factory used for creating operation queues. 8 | */ 9 | public interface OperationQueueFactory { 10 | 11 | /** 12 | * Create an instance of a queue. 13 | */ 14 | BlockingQueue create(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/OperationState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | /** 20 | * State of this operation. 21 | */ 22 | public enum OperationState { 23 | /** 24 | * State indicating this operation is waiting to be written to the server. 25 | */ 26 | WRITE_QUEUED, 27 | /** 28 | * State indicating this operation is writing data to the server. 29 | */ 30 | WRITING, 31 | /** 32 | * State indicating this operation is reading data from the server. 33 | */ 34 | READING, 35 | /** 36 | * State indicating this operation is complete. 37 | */ 38 | COMPLETE, 39 | /* ENABLE_REPLICATION if */ 40 | /** 41 | * State indicating this operation received SWITCHOVER | REPL_SLAVE 42 | * and the node handling this operation need to switchover in the locator. 43 | */ 44 | NEED_SWITCHOVER, 45 | /* ENABLE_REPLICATION end */ 46 | 47 | /* ENABLE_MIGRATION if */ 48 | /** 49 | * State indicating this operation will be redirected by migration 50 | */ 51 | REDIRECT 52 | /* ENABLE_MIGRATION end */ 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/OperationStatus.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * Status indicator. 7 | */ 8 | public class OperationStatus { 9 | 10 | private final boolean isSuccess; 11 | private final String message; 12 | private final StatusCode statusCode; 13 | 14 | public OperationStatus(boolean success, String msg) { 15 | this(success, msg, null); 16 | } 17 | 18 | public OperationStatus(boolean success, String msg, StatusCode code) { 19 | isSuccess = success; 20 | message = msg; 21 | statusCode = code; 22 | } 23 | 24 | /** 25 | * Does this status indicate success? 26 | */ 27 | public boolean isSuccess() { 28 | return isSuccess; 29 | } 30 | 31 | /** 32 | * Get the message included as part of this status. 33 | */ 34 | public String getMessage() { 35 | return message; 36 | } 37 | 38 | /** 39 | * Get the status code associated with the operation status. 40 | */ 41 | public StatusCode getStatusCode() { 42 | return statusCode; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "{OperationStatus success=" + isSuccess + ": " + message + "}"; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) { 53 | return true; 54 | } 55 | if (o == null || getClass() != o.getClass()) { 56 | return false; 57 | } 58 | 59 | OperationStatus that = (OperationStatus) o; 60 | return isSuccess == that.isSuccess && 61 | Objects.equals(message, that.message) && 62 | Objects.equals(statusCode, that.statusCode); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return Objects.hash(isSuccess, message, statusCode); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/PipedOperationCallback.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | public interface PipedOperationCallback extends OperationCallback { 4 | void gotStatus(Integer index, OperationStatus status); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/SASLAuthOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Operation for beginning a SASL auth cycle. 5 | */ 6 | public interface SASLAuthOperation extends Operation { 7 | // nothing 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/SASLMechsOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Operation for listing supported SASL mechanisms. 5 | */ 6 | public interface SASLMechsOperation extends Operation { 7 | // Nothing. 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/SASLStepOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Operation for proceeding in a SASL auth negotiation. 5 | */ 6 | public interface SASLStepOperation extends Operation { 7 | // nothing 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/SetAttrOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.ops; 18 | 19 | import net.spy.memcached.collection.Attributes; 20 | 21 | /** 22 | * SetAttr operation. 23 | */ 24 | public interface SetAttrOperation extends KeyedOperation { 25 | 26 | Attributes getAttributes(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/StatsOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | 4 | /** 5 | * Stats fetching operation. 6 | */ 7 | public interface StatsOperation extends Operation { 8 | 9 | /** 10 | * Callback for stats operation. 11 | */ 12 | interface Callback extends OperationCallback { 13 | /** 14 | * Invoked once for every stat returned from the server. 15 | * 16 | * @param name the name of the stat 17 | * @param val the stat value. 18 | */ 19 | void gotStat(String name, String val); 20 | } 21 | // nothing 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/StoreOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Operation that represents object storage. 5 | */ 6 | public interface StoreOperation extends KeyedOperation { 7 | 8 | /** 9 | * Get the store type used by this operation. 10 | */ 11 | StoreType getStoreType(); 12 | 13 | /** 14 | * Get the flags to be set. 15 | */ 16 | int getFlags(); 17 | 18 | /** 19 | * Get the expiration value to be set. 20 | */ 21 | int getExpiration(); 22 | 23 | /** 24 | * Get the bytes to be set during this operation. 25 | * 26 | *

27 | * Note, this returns an exact reference to the bytes and the data 28 | * must not be modified. 29 | *

30 | */ 31 | byte[] getData(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/StoreType.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * The type of storage operation to perform. 5 | */ 6 | public enum StoreType { 7 | /** 8 | * Unconditionally store a value in the cache. 9 | */ 10 | set, 11 | /** 12 | * Store a value in the cache iff there is not already something stored 13 | * for the given key. 14 | */ 15 | add, 16 | /** 17 | * Store a value in the cache iff there is already something stored for 18 | * the given key. 19 | */ 20 | replace 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/VersionOperation.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.ops; 2 | 3 | /** 4 | * Version operation. 5 | */ 6 | public interface VersionOperation extends Operation { 7 | // nothing 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/ops/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Fundamental protocol operation interfaces 8 | 9 | 10 | 11 |

Fundamental protocol operation interfaces

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/overview.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Welcome to spymemcached 8 | 9 | 10 | 11 | 12 |

Welcome to spymemcached.

13 | 14 |

15 | Get a {@link net.spy.memcached.MemcachedClient} object and start setting and 16 | getting stuff in memcached. 17 |

18 | 19 |

20 | You may also find the 21 | online examples 22 | helpful. 23 |

24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Memcached client and transformation utils 8 | 9 | 10 | 11 |

Memcached client and transformation utils

12 | 13 |

14 | Usage should be pretty straightforward. Get a {@link 15 | net.spy.memcached.MemcachedClient} object and start setting and 16 | getting stuff in memcached. 17 |

18 |

19 | All operations are asynchronous internally, but most at least provide 20 | synchronous convenience interfaces. Some only provide synchronous 21 | interfaces (getVersion, getStats) and some only provide asynchronous 22 | interfaces (delete, flush). That'll probably all get cleared up if it 23 | bothers anyone. 24 |

25 |

26 | You may also find the 27 | online examples 28 | helpful. 29 |

30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/GetCallbackWrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package net.spy.memcached.protocol; 5 | 6 | import net.spy.memcached.ops.GetOperation; 7 | import net.spy.memcached.ops.OperationStatus; 8 | import net.spy.memcached.ops.StatusCode; 9 | 10 | /** 11 | * Wrapper callback for use in optimized gets. 12 | */ 13 | public class GetCallbackWrapper implements GetOperation.Callback { 14 | 15 | private static final OperationStatus END = 16 | new OperationStatus(true, "END", StatusCode.SUCCESS); 17 | 18 | private boolean completed = false; 19 | private int remainingKeys = 0; 20 | private GetOperation.Callback cb = null; 21 | 22 | public GetCallbackWrapper(int k, GetOperation.Callback c) { 23 | super(); 24 | remainingKeys = k; 25 | cb = c; 26 | } 27 | 28 | public void gotData(String key, int flags, byte[] data) { 29 | assert !completed : "Got data for a completed wrapped op"; 30 | cb.gotData(key, flags, data); 31 | if (--remainingKeys == 0) { 32 | // Fake a status line 33 | receivedStatus(END); 34 | } 35 | } 36 | 37 | public void receivedStatus(OperationStatus status) { 38 | if (!completed) { 39 | cb.receivedStatus(status); 40 | } 41 | } 42 | 43 | public void complete() { 44 | assert !completed; 45 | cb.complete(); 46 | completed = true; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/ascii/GetOperationImpl.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006 Dustin Sallings 2 | 3 | package net.spy.memcached.protocol.ascii; 4 | 5 | import java.util.Collection; 6 | import java.util.Collections; 7 | import java.util.HashSet; 8 | 9 | import net.spy.memcached.ops.APIType; 10 | import net.spy.memcached.ops.GetOperation; 11 | 12 | /** 13 | * Operation for retrieving data. 14 | */ 15 | class GetOperationImpl extends BaseGetOpImpl implements GetOperation { 16 | 17 | private static final String CMD = "get"; 18 | private static final String CMD_MGET = "mget"; 19 | 20 | public GetOperationImpl(String key, GetOperation.Callback c) { 21 | super(CMD, c, Collections.singleton(key)); 22 | setAPIType(APIType.GET); 23 | } 24 | 25 | public GetOperationImpl(Collection keys, GetOperation.Callback cb, boolean isMGet) { 26 | super(isMGet ? CMD_MGET : CMD, cb, new HashSet<>(keys)); 27 | setAPIType(APIType.GET); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/ascii/GetsOperationImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.ascii; 2 | 3 | import java.util.Collection; 4 | import java.util.Collections; 5 | import java.util.HashSet; 6 | 7 | import net.spy.memcached.ops.APIType; 8 | import net.spy.memcached.ops.GetsOperation; 9 | 10 | /** 11 | * Implementation of the gets operation. 12 | */ 13 | class GetsOperationImpl extends BaseGetOpImpl implements GetsOperation { 14 | 15 | private static final String CMD = "gets"; 16 | private static final String CMD_MGETS = "mgets"; 17 | 18 | public GetsOperationImpl(String key, GetsOperation.Callback cb) { 19 | super(CMD, cb, Collections.singleton(key)); 20 | setAPIType(APIType.GETS); 21 | } 22 | 23 | public GetsOperationImpl(Collection keys, GetsOperation.Callback cb, boolean isMGet) { 24 | super(isMGet ? CMD_MGETS : CMD, cb, new HashSet<>(keys)); 25 | setAPIType(APIType.GETS); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/ascii/OperationReadType.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.ascii; 2 | 3 | /** 4 | * Data read types. 5 | */ 6 | enum OperationReadType { 7 | /** 8 | * Read type indicating an operation currently wants to read lines. 9 | */ 10 | LINE, 11 | /** 12 | * Read type indicating an operation currently wants to read raw data. 13 | */ 14 | DATA 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/ascii/OptimizedGetImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.ascii; 2 | 3 | import java.util.HashSet; 4 | 5 | import net.spy.memcached.ops.GetOperation; 6 | import net.spy.memcached.protocol.ProxyCallback; 7 | 8 | /** 9 | * Optimized Get operation for folding a bunch of gets together. 10 | */ 11 | final class OptimizedGetImpl extends GetOperationImpl { 12 | 13 | private final ProxyCallback pcb; 14 | 15 | /** 16 | * Construct an optimized get starting with the given get operation. 17 | */ 18 | public OptimizedGetImpl(GetOperation firstGet, boolean isMGet) { 19 | super(new HashSet<>(), new ProxyCallback(), isMGet); 20 | pcb = (ProxyCallback) getCallback(); 21 | addOperation(firstGet); 22 | } 23 | 24 | /** 25 | * Add a new GetOperation to get. 26 | */ 27 | public void addOperation(GetOperation o) { 28 | getKeys().addAll(o.getKeys()); 29 | pcb.addCallbacks(o); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/ascii/StoreOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | // Copyright (c) 2006 Dustin Sallings 19 | 20 | package net.spy.memcached.protocol.ascii; 21 | 22 | import net.spy.memcached.ops.APIType; 23 | import net.spy.memcached.ops.OperationCallback; 24 | import net.spy.memcached.ops.StoreOperation; 25 | import net.spy.memcached.ops.StoreType; 26 | 27 | /** 28 | * Operation to store data in a memcached server. 29 | */ 30 | final class StoreOperationImpl extends BaseStoreOperationImpl 31 | implements StoreOperation { 32 | 33 | private final StoreType storeType; 34 | 35 | public StoreOperationImpl(StoreType t, String k, int f, int e, 36 | byte[] d, OperationCallback cb) { 37 | super(t.name(), k, f, e, d, cb); 38 | storeType = t; 39 | if (t == StoreType.add) { 40 | setAPIType(APIType.ADD); 41 | } else if (t == StoreType.set) { 42 | setAPIType(APIType.SET); 43 | } else if (t == StoreType.replace) { 44 | setAPIType(APIType.REPLACE); 45 | } 46 | } 47 | 48 | public StoreType getStoreType() { 49 | return storeType; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/ascii/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Low-level operations for the memcached ascii protocol 8 | 9 | 10 | 11 |

Low-level operations for the memcached ascii protocol

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/FlushOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.protocol.binary; 19 | 20 | import net.spy.memcached.ops.FlushOperation; 21 | import net.spy.memcached.ops.OperationCallback; 22 | 23 | class FlushOperationImpl extends OperationImpl implements FlushOperation { 24 | 25 | private static final int CMD = 8; 26 | private final int delay; 27 | 28 | public FlushOperationImpl(OperationCallback cb) { 29 | this(0, cb); 30 | } 31 | 32 | public FlushOperationImpl(int d, OperationCallback cb) { 33 | super(CMD, generateOpaque(), cb); 34 | delay = d; 35 | } 36 | 37 | @Override 38 | public void initialize() { 39 | prepareBuffer("", 0, EMPTY_BYTES, delay); 40 | } 41 | 42 | @Override 43 | public boolean isIdempotentOperation() { 44 | return false; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/NoopOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.protocol.binary; 19 | 20 | import net.spy.memcached.ops.NoopOperation; 21 | import net.spy.memcached.ops.OperationCallback; 22 | 23 | /** 24 | * Implementation of a noop operation. 25 | */ 26 | class NoopOperationImpl extends OperationImpl implements NoopOperation { 27 | 28 | static final int CMD = 10; 29 | 30 | public NoopOperationImpl(OperationCallback cb) { 31 | super(CMD, generateOpaque(), cb); 32 | } 33 | 34 | @Override 35 | public void initialize() { 36 | prepareBuffer("", 0, EMPTY_BYTES); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/OptimizedGetImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.binary; 2 | 3 | import java.util.Collections; 4 | 5 | import net.spy.memcached.ops.GetOperation; 6 | import net.spy.memcached.protocol.ProxyCallback; 7 | 8 | /** 9 | * Optimized Get operation for folding a bunch of gets together. 10 | */ 11 | final class OptimizedGetImpl extends MultiGetOperationImpl { 12 | 13 | private final ProxyCallback pcb; 14 | 15 | /** 16 | * Construct an optimized get starting with the given get operation. 17 | */ 18 | public OptimizedGetImpl(GetOperation firstGet) { 19 | super(Collections.emptySet(), new ProxyCallback()); 20 | pcb = (ProxyCallback) getCallback(); 21 | addOperation(firstGet); 22 | } 23 | 24 | /** 25 | * Add a new GetOperation to get. 26 | */ 27 | public void addOperation(GetOperation o) { 28 | pcb.addCallbacks(o); 29 | for (String k : o.getKeys()) { 30 | addKey(k); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/SASLAuthOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.protocol.binary; 19 | 20 | import javax.security.sasl.SaslClient; 21 | import javax.security.sasl.SaslException; 22 | 23 | import net.spy.memcached.ops.OperationCallback; 24 | import net.spy.memcached.ops.SASLAuthOperation; 25 | 26 | public class SASLAuthOperationImpl extends SASLBaseOperationImpl 27 | implements SASLAuthOperation { 28 | 29 | private final static int CMD = 0x21; 30 | 31 | public SASLAuthOperationImpl(SaslClient sc, OperationCallback cb) { 32 | super(CMD, sc, EMPTY_BYTES, cb); 33 | } 34 | 35 | @Override 36 | protected byte[] buildResponse(SaslClient sc) throws SaslException { 37 | return sc.hasInitialResponse() ? 38 | sc.evaluateChallenge(challenge) 39 | : EMPTY_BYTES; 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/SASLMechsOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.protocol.binary; 19 | 20 | import net.spy.memcached.ops.OperationCallback; 21 | import net.spy.memcached.ops.OperationStatus; 22 | import net.spy.memcached.ops.SASLMechsOperation; 23 | import net.spy.memcached.ops.StatusCode; 24 | 25 | class SASLMechsOperationImpl extends OperationImpl implements 26 | SASLMechsOperation { 27 | 28 | private static final int CMD = 0x20; 29 | 30 | public SASLMechsOperationImpl(OperationCallback cb) { 31 | super(CMD, generateOpaque(), cb); 32 | } 33 | 34 | @Override 35 | public void initialize() { 36 | prepareBuffer("", 0, EMPTY_BYTES); 37 | } 38 | 39 | @Override 40 | protected void decodePayload(byte[] pl) { 41 | getCallback().receivedStatus( 42 | new OperationStatus(true, new String(pl), StatusCode.SUCCESS)); 43 | } 44 | 45 | 46 | @Override 47 | public boolean isIdempotentOperation() { 48 | return false; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/SASLStepOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.protocol.binary; 19 | 20 | import javax.security.sasl.SaslClient; 21 | import javax.security.sasl.SaslException; 22 | 23 | import net.spy.memcached.ops.OperationCallback; 24 | import net.spy.memcached.ops.SASLStepOperation; 25 | 26 | public class SASLStepOperationImpl extends SASLBaseOperationImpl 27 | implements SASLStepOperation { 28 | 29 | private final static int CMD = 0x22; 30 | 31 | public SASLStepOperationImpl(SaslClient sc, byte[] challenge, OperationCallback cb) { 32 | super(CMD, sc, challenge, cb); 33 | } 34 | 35 | @Override 36 | protected byte[] buildResponse(SaslClient sc) throws SaslException { 37 | return sc.evaluateChallenge(challenge); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/VersionOperationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * Copyright 2014-2022 JaM2in Co., Ltd. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.spy.memcached.protocol.binary; 19 | 20 | import net.spy.memcached.ops.OperationCallback; 21 | import net.spy.memcached.ops.OperationStatus; 22 | import net.spy.memcached.ops.StatusCode; 23 | import net.spy.memcached.ops.VersionOperation; 24 | 25 | class VersionOperationImpl extends OperationImpl implements VersionOperation { 26 | 27 | private static final int CMD = 11; 28 | 29 | public VersionOperationImpl(OperationCallback cb) { 30 | super(CMD, generateOpaque(), cb); 31 | } 32 | 33 | @Override 34 | public void initialize() { 35 | prepareBuffer("", 0, EMPTY_BYTES); 36 | } 37 | 38 | @Override 39 | protected void decodePayload(byte[] pl) { 40 | getCallback().receivedStatus( 41 | new OperationStatus(true, new String(pl), StatusCode.SUCCESS)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/binary/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Low-level operations for the memcached binary protocol 8 | 9 | 10 | 11 |

Low-level operations for the memcached binary protocol

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/protocol/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Base classes for protocol abstractions. 8 | 9 | 10 | 11 |

Base classes for protocol abstractions.

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/transcoders/InspectObjectSizeTranscoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.transcoders; 18 | 19 | import net.spy.memcached.CachedData; 20 | 21 | public class InspectObjectSizeTranscoder extends SerializingTranscoder { 22 | 23 | public interface LoggingObjectSize { 24 | void histogram(int size); 25 | } 26 | 27 | private final LoggingObjectSize objSizeLogger; 28 | 29 | public InspectObjectSizeTranscoder(LoggingObjectSize objSizeLogger) { 30 | this.objSizeLogger = objSizeLogger; 31 | } 32 | 33 | @Override 34 | public CachedData encode(Object o) { 35 | CachedData encoded = super.encode(o); 36 | 37 | objSizeLogger.histogram(encoded.getData().length); 38 | 39 | return encoded; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/transcoders/IntegerTranscoder.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006 Dustin Sallings 2 | 3 | package net.spy.memcached.transcoders; 4 | 5 | import net.spy.memcached.CachedData; 6 | import net.spy.memcached.compat.SpyObject; 7 | 8 | /** 9 | * Transcoder that serializes and unserializes longs. 10 | */ 11 | public final class IntegerTranscoder extends SpyObject 12 | implements Transcoder { 13 | 14 | private static final int flags = SerializingTranscoder.SPECIAL_INT; 15 | 16 | private final TranscoderUtils tu = new TranscoderUtils(true); 17 | 18 | public boolean asyncDecode(CachedData d) { 19 | return false; 20 | } 21 | 22 | public CachedData encode(java.lang.Integer l) { 23 | return new CachedData(flags, tu.encodeInt(l), getMaxSize()); 24 | } 25 | 26 | public Integer decode(CachedData d) { 27 | if (flags == d.getFlags()) { 28 | return tu.decodeInt(d.getData()); 29 | } else { 30 | return null; 31 | } 32 | } 33 | 34 | public int getMaxSize() { 35 | return CachedData.MAX_SIZE; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/transcoders/LongTranscoder.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006 Dustin Sallings 2 | 3 | package net.spy.memcached.transcoders; 4 | 5 | import net.spy.memcached.CachedData; 6 | import net.spy.memcached.compat.SpyObject; 7 | 8 | /** 9 | * Transcoder that serializes and unserializes longs. 10 | */ 11 | public final class LongTranscoder extends SpyObject 12 | implements Transcoder { 13 | 14 | private static final int flags = SerializingTranscoder.SPECIAL_LONG; 15 | 16 | private final TranscoderUtils tu = new TranscoderUtils(true); 17 | 18 | public boolean asyncDecode(CachedData d) { 19 | return false; 20 | } 21 | 22 | public CachedData encode(java.lang.Long l) { 23 | return new CachedData(flags, tu.encodeLong(l), getMaxSize()); 24 | } 25 | 26 | public Long decode(CachedData d) { 27 | if (flags == d.getFlags()) { 28 | return tu.decodeLong(d.getData()); 29 | } else { 30 | getLogger().error("Unexpected flags for long: " 31 | + d.getFlags() + " wanted " + flags); 32 | return null; 33 | } 34 | } 35 | 36 | public int getMaxSize() { 37 | return CachedData.MAX_SIZE; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/transcoders/Transcoder.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006 Dustin Sallings 2 | 3 | package net.spy.memcached.transcoders; 4 | 5 | import net.spy.memcached.CachedData; 6 | 7 | /** 8 | * Transcoder is an interface for classes that convert between byte arrays and 9 | * objects for storage in the cache. 10 | */ 11 | public interface Transcoder { 12 | 13 | /** 14 | * Should the transcoder be run asynchronously. 15 | * 16 | * @return True if the CachedData should be decoded Asynchronously 17 | */ 18 | boolean asyncDecode(CachedData d); 19 | 20 | /** 21 | * Encode the given object for storage. 22 | * 23 | * @param o the object 24 | * @return the CachedData representing what should be sent 25 | */ 26 | CachedData encode(T o); 27 | 28 | /** 29 | * Decode the cached object into the object it represents. 30 | * 31 | * @param d the data 32 | * @return the return value 33 | */ 34 | T decode(CachedData d); 35 | 36 | /** 37 | * Get the maximum size of objects handled by this transcoder. 38 | */ 39 | int getMaxSize(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/transcoders/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Transcoders convert data to and from data and flags 8 | 9 | 10 | 11 |

Classes that deal with data encoding

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/util/KetamaNodeLocatorConfiguration.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.util; 2 | 3 | import net.spy.memcached.MemcachedNode; 4 | 5 | /** 6 | * Defines the set of all configuration dependencies 7 | * required for the KetamaNodeLocator algorithm to run 8 | */ 9 | public interface KetamaNodeLocatorConfiguration { 10 | 11 | /** 12 | * Returns a uniquely identifying key, suitable for hashing by the 13 | * KetamaNodeLocator algorithm. 14 | * 15 | * @param node The MemcachedNode to use to form the unique identifier 16 | * @param repetition The repetition number for the particular node in 17 | * question (0 is the first repetition) 18 | * @return The key that represents the specific repetition of the node 19 | */ 20 | String getKeyForNode(MemcachedNode node, int repetition); 21 | 22 | /** 23 | * Returns the number of discrete hashes that should be defined for each 24 | * node in the continuum. 25 | * 26 | * @return a value greater than 0 27 | */ 28 | int getNodeRepetitions(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/spy/memcached/util/package.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Cache Utilities. 8 | 9 | 10 | 11 |

Cache Utilities.

12 |

13 | Herein you'll find various things that make your life with cache 14 | a little better. 15 |

16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/AsciiCancellationTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * Test cancellation in ascii protocol. 5 | */ 6 | class AsciiCancellationTest extends CancellationBaseCase { 7 | // uses defaults 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/AsciiIPV6ClientTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.Collections; 4 | 5 | /** 6 | * Test the test protocol over IPv6. 7 | */ 8 | class AsciiIPV6ClientTest extends AsciiClientTest { 9 | 10 | @Override 11 | protected void initClient(ConnectionFactory cf) throws Exception { 12 | client = new MemcachedClient(cf, AddrUtil.getAddresses( 13 | Collections.singletonList("::1:11211"))); 14 | } 15 | 16 | @Override 17 | protected String getExpectedVersionSource() { 18 | return "/0:0:0:0:0:0:0:1:11211"; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/BinaryCancellationTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | /** 4 | * Test cancellation in the binary protocol. 5 | */ 6 | class BinaryCancellationTest extends CancellationBaseCase { 7 | 8 | @Override 9 | protected void initClient() throws Exception { 10 | initClient(new BinaryConnectionFactory() { 11 | @Override 12 | public FailureMode getFailureMode() { 13 | return FailureMode.Retry; 14 | } 15 | }); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/BinaryIPV6ClientTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.Collections; 4 | 5 | /** 6 | * Binary IPv6 client test. 7 | */ 8 | class BinaryIPV6ClientTest extends BinaryClientTest { 9 | 10 | @Override 11 | protected void initClient(ConnectionFactory cf) throws Exception { 12 | client = new MemcachedClient(cf, AddrUtil.getAddresses( 13 | Collections.singletonList("::1:11211"))); 14 | } 15 | 16 | @Override 17 | protected String getExpectedVersionSource() { 18 | return "/0:0:0:0:0:0:0:1:11211"; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/CancelFailureModeTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.Collections; 4 | import java.util.concurrent.ExecutionException; 5 | import java.util.concurrent.Future; 6 | 7 | import org.junit.jupiter.api.AfterEach; 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertTrue; 12 | import static org.junit.jupiter.api.Assertions.fail; 13 | 14 | class CancelFailureModeTest { 15 | private String serverList = "127.0.0.1:11311"; 16 | private MemcachedClient client = null; 17 | 18 | @BeforeEach 19 | protected void setUp() throws Exception { 20 | client = new MemcachedClient(new DefaultConnectionFactory() { 21 | @Override 22 | public FailureMode getFailureMode() { 23 | return FailureMode.Cancel; 24 | } 25 | }, AddrUtil.getAddresses(Collections.singletonList(serverList))); 26 | } 27 | 28 | @AfterEach 29 | protected void tearDown() throws Exception { 30 | if (client != null) { 31 | client.shutdown(); 32 | } 33 | } 34 | 35 | @Test 36 | void testQueueingToDownServer() throws Exception { 37 | Future f = client.add("someKey", 0, "some object"); 38 | try { 39 | boolean b = f.get(); 40 | fail("Should've thrown an exception, returned " + b); 41 | } catch (ExecutionException e) { 42 | // probably OK 43 | } 44 | assertTrue(f.isCancelled()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/ConnectionFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | /** 8 | * Test connection factory variations. 9 | */ 10 | class ConnectionFactoryTest { 11 | 12 | // These tests are a little lame. They don't verify anything other than 13 | // that the code executes without failure. 14 | @Test 15 | void testBinaryEmptyCons() { 16 | new BinaryConnectionFactory(); 17 | } 18 | 19 | @Test 20 | void testBinaryTwoIntCons() { 21 | new BinaryConnectionFactory(5, 5); 22 | } 23 | 24 | @Test 25 | void testBinaryAnIntAnotherIntAndAHashAlgorithmCons() { 26 | new BinaryConnectionFactory(5, 5, 27 | HashAlgorithm.FNV1_64_HASH); 28 | } 29 | 30 | @Test 31 | void testQueueSizes() { 32 | ConnectionFactory cf = new DefaultConnectionFactory(100, 1024); 33 | assertEquals(100, cf.createOperationQueue().remainingCapacity()); 34 | assertEquals(Integer.MAX_VALUE, 35 | cf.createWriteOperationQueue().remainingCapacity()); 36 | assertEquals(Integer.MAX_VALUE, 37 | cf.createReadOperationQueue().remainingCapacity()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/ExpectationsUtil.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.function.Consumer; 4 | 5 | import org.jmock.Expectations; 6 | 7 | public final class ExpectationsUtil { 8 | 9 | private ExpectationsUtil() { 10 | } 11 | 12 | public static Expectations buildExpectations(Consumer checkList) { 13 | Expectations expectations = new Expectations(); 14 | checkList.accept(expectations); 15 | return expectations; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/KetamaConnectionFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | import static org.junit.jupiter.api.Assertions.assertTrue; 9 | 10 | /** 11 | * A very basic test that the KetamaConnectionFactory returns both the correct 12 | * hash algorithm and the correct node locator. 13 | */ 14 | class KetamaConnectionFactoryTest { 15 | 16 | /* 17 | * This *is* kinda lame, but it tests the specific differences from the 18 | * DefaultConnectionFactory. 19 | */ 20 | @Test 21 | void testCorrectTypes() { 22 | ConnectionFactory factory = new KetamaConnectionFactory(); 23 | 24 | NodeLocator locator = factory.createLocator(new ArrayList<>()); 25 | assertTrue(locator instanceof KetamaNodeLocator); 26 | 27 | assertEquals(HashAlgorithm.KETAMA_HASH, factory.getHashAlg()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/LongClientTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Random; 8 | 9 | import net.spy.memcached.compat.SyncThread; 10 | 11 | import org.junit.jupiter.api.Test; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | import static org.junit.jupiter.api.Assertions.assertTrue; 15 | 16 | /** 17 | * Longer running test case. 18 | */ 19 | class LongClientTest extends ClientBaseCase { 20 | 21 | @Test 22 | void testParallelGet() throws Throwable { 23 | // Get a connection with the get optimization disabled. 24 | client.shutdown(); 25 | initClient(new DefaultConnectionFactory() { 26 | @Override 27 | public long getOperationTimeout() { 28 | return 15000; 29 | } 30 | 31 | @Override 32 | public boolean shouldOptimize() { 33 | return false; 34 | } 35 | }); 36 | 37 | // Throw in some seed data. 38 | byte data[] = new byte[32768]; 39 | Random r = new Random(); 40 | r.nextBytes(data); 41 | final int hashcode = Arrays.hashCode(data); 42 | final List keys = new ArrayList<>(50); 43 | for (int i = 0; i < 50; i++) { 44 | keys.add("k" + i); 45 | assertTrue(client.set(keys.get(i), 3600, data).get()); 46 | } 47 | 48 | int cnt = SyncThread.getDistinctResultCount(25, () -> { 49 | for (int i = 0; i < 25; i++) { 50 | Map m = client.getBulk(keys); 51 | for (String s : keys) { 52 | byte b[] = (byte[]) m.get(s); 53 | assertEquals(hashcode, Arrays.hashCode(b)); 54 | } 55 | } 56 | return hashcode; 57 | }); 58 | assertEquals(cnt, 25); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/SocketTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import java.net.SocketException; 4 | import java.util.Collection; 5 | 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertTrue; 10 | 11 | class SocketTest { 12 | private ArcusClient client; 13 | private final String ZK_STRING = "127.0.0.1:2181"; 14 | private final String SERVICE_CODE = "test"; 15 | 16 | @BeforeEach 17 | protected void setUp() throws Exception { 18 | ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder(); 19 | connectionFactoryBuilder.setKeepAlive(true); 20 | client = ArcusClient.createArcusClient(ZK_STRING, SERVICE_CODE, connectionFactoryBuilder); 21 | } 22 | 23 | @Test 24 | void testSocketKeepAliveTest() throws SocketException { 25 | Collection allNodes = 26 | client.getAllNodes(); 27 | for (MemcachedNode node : allNodes) { 28 | assertTrue(node.getChannel().socket().getKeepAlive()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/internal/CompositeExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import net.spy.memcached.ops.OperationErrorType; 7 | import net.spy.memcached.ops.OperationException; 8 | 9 | import org.junit.jupiter.api.Test; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertTrue; 12 | 13 | class CompositeExceptionTest { 14 | 15 | @Test 16 | void printStackTraceOfAllExceptions() { 17 | List exceptions = new ArrayList<>(); 18 | exceptions.add(new OperationException(OperationErrorType.SERVER, "msg1")); 19 | exceptions.add(new OperationException(OperationErrorType.CLIENT, "msg2")); 20 | Exception e = throwError1(); 21 | exceptions.add(e); 22 | CompositeException compositeException = new CompositeException(exceptions); 23 | String message = compositeException.getCause().getMessage(); 24 | 25 | assertTrue(message 26 | .contains("OperationException: SERVER: msg1")); 27 | assertTrue(message 28 | .contains("OperationException: CLIENT: msg2")); 29 | assertTrue(message 30 | .contains("OperationException: SERVER: msg3")); 31 | assertTrue(message 32 | .contains("at net.spy.memcached.internal.CompositeExceptionTest.throwError2")); 33 | assertTrue(message 34 | .contains("at net.spy.memcached.internal.CompositeExceptionTest.throwError1")); 35 | } 36 | 37 | private Exception throwError1() { 38 | return throwError2(); 39 | } 40 | 41 | private Exception throwError2() { 42 | return new OperationException(OperationErrorType.SERVER, "msg3"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/internal/SingleElementInfiniteIteratorTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.internal; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertSame; 7 | import static org.junit.jupiter.api.Assertions.assertTrue; 8 | import static org.junit.jupiter.api.Assertions.fail; 9 | 10 | class SingleElementInfiniteIteratorTest { 11 | private static final String CONSTANT = "foo"; 12 | private SingleElementInfiniteIterator iterator; 13 | 14 | @BeforeEach 15 | protected void setUp() throws Exception { 16 | iterator = new SingleElementInfiniteIterator<>(CONSTANT); 17 | } 18 | 19 | @Test 20 | void testHasNextAndNext() { 21 | for (int i = 0; i < 100; ++i) { 22 | assertTrue(iterator.hasNext()); 23 | assertSame(CONSTANT, iterator.next()); 24 | } 25 | } 26 | 27 | @Test 28 | void testRemove() { 29 | try { 30 | iterator.remove(); 31 | fail("Expected UnsupportedOperationException on a remove."); 32 | } catch (UnsupportedOperationException e) { 33 | // test success. 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/protocol/ascii/ExtensibleOperationImpl.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.ascii; 2 | 3 | import net.spy.memcached.ops.OperationCallback; 4 | 5 | /** 6 | * For testing, allow subclassing of the operation impl. 7 | */ 8 | public abstract class ExtensibleOperationImpl extends OperationImpl { 9 | 10 | public ExtensibleOperationImpl() { 11 | super(); 12 | } 13 | 14 | public ExtensibleOperationImpl(OperationCallback cb) { 15 | super(cb); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/protocol/ascii/OperationFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.ascii; 2 | 3 | import net.spy.memcached.OperationFactory; 4 | import net.spy.memcached.OperationFactoryTestBase; 5 | import net.spy.memcached.ops.Mutator; 6 | import net.spy.memcached.ops.MutatorOperation; 7 | 8 | import org.junit.jupiter.api.Test; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertSame; 12 | 13 | class OperationFactoryTest extends OperationFactoryTestBase { 14 | 15 | @Override 16 | protected OperationFactory getOperationFactory() { 17 | return new AsciiOperationFactory(); 18 | } 19 | 20 | @Test 21 | @Override 22 | public void testMutatorOperationIncrCloning() { 23 | int exp = 823862; 24 | long def = 28775; 25 | int by = 7735; 26 | MutatorOperation op = ofact.mutate(Mutator.incr, TEST_KEY, by, def, 27 | exp, genericCallback); 28 | 29 | MutatorOperation op2 = cloneOne(MutatorOperation.class, op); 30 | assertKey(op2); 31 | assertEquals(-1, op2.getExpiration()); 32 | assertEquals(-1, op2.getDefault()); 33 | assertEquals(by, op2.getBy()); 34 | assertSame(Mutator.incr, op2.getType()); 35 | assertCallback(op2); 36 | } 37 | 38 | @Test 39 | @Override 40 | public void testMutatorOperationDecrCloning() { 41 | int exp = 823862; 42 | long def = 28775; 43 | int by = 7735; 44 | MutatorOperation op = ofact.mutate(Mutator.decr, TEST_KEY, by, def, 45 | exp, genericCallback); 46 | 47 | MutatorOperation op2 = cloneOne(MutatorOperation.class, op); 48 | assertKey(op2); 49 | assertEquals(-1, op2.getExpiration()); 50 | assertEquals(-1, op2.getDefault()); 51 | assertEquals(by, op2.getBy()); 52 | assertSame(Mutator.decr, op2.getType()); 53 | assertCallback(op2); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/protocol/binary/OperationFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.binary; 2 | 3 | import net.spy.memcached.OperationFactory; 4 | import net.spy.memcached.OperationFactoryTestBase; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertTrue; 9 | 10 | class OperationFactoryTest extends OperationFactoryTestBase { 11 | 12 | @Override 13 | protected OperationFactory getOperationFactory() { 14 | return new BinaryOperationFactory(); 15 | } 16 | 17 | @Test 18 | @Override 19 | public void testMultipleGetsOperationCloning() { 20 | assertTrue(true); 21 | } 22 | 23 | @Test 24 | @Override 25 | public void testMultipleGetsOperationFanout() { 26 | assertTrue(true); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/protocol/binary/OperationTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.protocol.binary; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static net.spy.memcached.protocol.binary.OperationImpl.decodeInt; 6 | import static net.spy.memcached.protocol.binary.OperationImpl.decodeUnsignedInt; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | /** 11 | * Test operation stuff. 12 | */ 13 | class OperationTest { 14 | 15 | @Test 16 | void testIntegerDecode() { 17 | assertEquals(129, 18 | decodeInt(new byte[]{0, 0, 0, (byte) 0x81}, 0)); 19 | assertEquals(129 * 256, 20 | decodeInt(new byte[]{0, 0, (byte) 0x81, 0}, 0)); 21 | assertEquals(129 * 256 * 256, 22 | decodeInt(new byte[]{0, (byte) 0x81, 0, 0}, 0)); 23 | assertEquals(129 * 256 * 256 * 256, 24 | decodeInt(new byte[]{(byte) 0x81, 0, 0, 0}, 0)); 25 | } 26 | 27 | @Test 28 | void testUnsignedIntegerDecode() { 29 | assertEquals(129, 30 | decodeUnsignedInt(new byte[]{0, 0, 0, (byte) 0x81}, 0)); 31 | assertEquals(129 * 256, 32 | decodeUnsignedInt(new byte[]{0, 0, (byte) 0x81, 0}, 0)); 33 | assertEquals(129 * 256 * 256, 34 | decodeUnsignedInt(new byte[]{0, (byte) 0x81, 0, 0}, 0)); 35 | assertEquals(129L * 256L * 256L * 256L, 36 | decodeUnsignedInt(new byte[]{(byte) 0x81, 0, 0, 0}, 0)); 37 | } 38 | 39 | @Test 40 | void testOperationStatusString() { 41 | String s = String.valueOf(OperationImpl.STATUS_OK); 42 | assertEquals("{OperationStatus success=true: OK}", s); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/transcoders/CachedDataTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.transcoders; 2 | 3 | import net.spy.memcached.CachedData; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | /** 10 | * Test a couple aspects of CachedData. 11 | */ 12 | class CachedDataTest { 13 | 14 | @Test 15 | void testToString() throws Exception { 16 | String exp = "{CachedData flags=13 data=[84, 104, 105, 115, 32, 105, " 17 | + "115, 32, 97, 32, 115, 105, 109, 112, 108, 101, 32, 116, 101, " 18 | + "115, 116, 32, 115, 116, 114, 105, 110, 103, 46] eFlag=null }"; 19 | CachedData cd = new CachedData(13, 20 | "This is a simple test string.".getBytes("UTF-8"), 21 | CachedData.MAX_SIZE); 22 | assertEquals(exp, String.valueOf(cd)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/transcoders/IntegerTranscoderTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.transcoders; 2 | 3 | import net.spy.memcached.CachedData; 4 | 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertNull; 10 | 11 | /** 12 | * Test the integer transcoder. 13 | */ 14 | class IntegerTranscoderTest { 15 | 16 | private IntegerTranscoder tc = null; 17 | 18 | @BeforeEach 19 | protected void setUp() throws Exception { 20 | tc = new IntegerTranscoder(); 21 | } 22 | 23 | @Test 24 | void testInt() throws Exception { 25 | assertEquals(923, tc.decode(tc.encode(923)).intValue()); 26 | } 27 | 28 | @Test 29 | void testBadFlags() throws Exception { 30 | CachedData cd = tc.encode(9284); 31 | assertNull(tc.decode(new CachedData(cd.getFlags() + 1, cd.getData(), 32 | CachedData.MAX_SIZE))); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/transcoders/LongTranscoderTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.transcoders; 2 | 3 | import net.spy.memcached.CachedData; 4 | 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertNull; 10 | 11 | /** 12 | * Test the long transcoder. 13 | */ 14 | class LongTranscoderTest { 15 | 16 | private LongTranscoder tc = null; 17 | 18 | @BeforeEach 19 | protected void setUp() throws Exception { 20 | tc = new LongTranscoder(); 21 | } 22 | 23 | @Test 24 | void testLong() throws Exception { 25 | assertEquals(923, tc.decode(tc.encode(923L)).longValue()); 26 | } 27 | 28 | @Test 29 | void testBadFlags() throws Exception { 30 | CachedData cd = tc.encode(9284L); 31 | assertNull(tc.decode(new CachedData(cd.getFlags() + 1, cd.getData(), 32 | CachedData.MAX_SIZE))); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/spy/memcached/transcoders/WhalinV1TranscoderTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.transcoders; 2 | 3 | import java.util.Arrays; 4 | 5 | import net.spy.memcached.CachedData; 6 | 7 | import org.junit.jupiter.api.BeforeEach; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertNotNull; 10 | import static org.junit.jupiter.api.Assertions.assertTrue; 11 | 12 | class WhalinV1TranscoderTest extends BaseTranscoderCase { 13 | 14 | @BeforeEach 15 | protected void setUp() throws Exception { 16 | setTranscoder(new WhalinV1Transcoder()); 17 | } 18 | 19 | @Override 20 | void testByteArray() throws Exception { 21 | byte[] a = {'a', 'b', 'c'}; 22 | 23 | CachedData cd = getTranscoder().encode(a); 24 | byte[] decoded = (byte[]) getTranscoder().decode(cd); 25 | assertNotNull(decoded); 26 | assertTrue(Arrays.equals(a, decoded)); 27 | } 28 | 29 | @Override 30 | protected int getStringFlags() { 31 | // Flags are not used by this transcoder. 32 | return 0; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/ArcusClientConnectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | import net.spy.memcached.collection.BaseIntegrationTest; 20 | 21 | import org.junit.jupiter.api.Assumptions; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.BeforeEach; 24 | 25 | class ArcusClientConnectTest { 26 | 27 | @BeforeEach 28 | protected void setUp() throws Exception { 29 | // This test assumes we use ZK 30 | Assumptions.assumeTrue(BaseIntegrationTest.USE_ZK); 31 | } 32 | 33 | @Test 34 | void testOpenAndWait() { 35 | ArcusClient client = ArcusClient.createArcusClient(BaseIntegrationTest.ZK_ADDRESS, 36 | BaseIntegrationTest.SERVICE_CODE); 37 | client.shutdown(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/ArcusClientNotExistsServiceCodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | import net.spy.memcached.collection.BaseIntegrationTest; 20 | 21 | import org.junit.jupiter.api.Disabled; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.fail; 25 | 26 | @Disabled 27 | class ArcusClientNotExistsServiceCodeTest { 28 | 29 | @Test 30 | void testNotExistsServiceCode() { 31 | if (!BaseIntegrationTest.USE_ZK) { 32 | return; 33 | } 34 | 35 | try { 36 | ArcusClient.createArcusClient(BaseIntegrationTest.ZK_ADDRESS, "NOT_EXISTS_SVC_CODE"); 37 | } catch (NotExistsServiceCodeException e) { 38 | return; 39 | } 40 | fail("not exists service code test failed."); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/ArcusClientPoolReconnectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | import net.spy.memcached.collection.BaseIntegrationTest; 20 | 21 | import org.junit.jupiter.api.Disabled; 22 | import org.junit.jupiter.api.Test; 23 | 24 | @Disabled 25 | class ArcusClientPoolReconnectTest { 26 | 27 | @Test 28 | void testOpenAndWait() { 29 | ArcusClientPool client = ArcusClient.createArcusClientPool(BaseIntegrationTest.ZK_ADDRESS, 30 | BaseIntegrationTest.SERVICE_CODE, 2); 31 | 32 | try { 33 | Thread.sleep(120000L); 34 | } catch (InterruptedException e) { 35 | e.printStackTrace(); 36 | } 37 | 38 | client.shutdown(); 39 | 40 | try { 41 | Thread.sleep(Long.MAX_VALUE); 42 | } catch (InterruptedException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/ArcusClientReconnectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached; 18 | 19 | import net.spy.memcached.collection.BaseIntegrationTest; 20 | 21 | import org.junit.jupiter.api.Disabled; 22 | import org.junit.jupiter.api.Test; 23 | 24 | @Disabled 25 | class ArcusClientReconnectTest { 26 | 27 | @Test 28 | void testOpenAndWait() { 29 | if (!BaseIntegrationTest.USE_ZK) { 30 | return; 31 | } 32 | 33 | ArcusClient client = ArcusClient.createArcusClient(BaseIntegrationTest.ZK_ADDRESS, 34 | BaseIntegrationTest.SERVICE_CODE); 35 | 36 | try { 37 | Thread.sleep(120000L); 38 | } catch (InterruptedException e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | client.shutdown(); 43 | 44 | try { 45 | Thread.sleep(Long.MAX_VALUE); 46 | } catch (InterruptedException e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/LoggerSetter.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached; 2 | 3 | import net.spy.memcached.compat.log.DefaultLogger; 4 | import net.spy.memcached.compat.log.Log4JLogger; 5 | import net.spy.memcached.compat.log.Logger; 6 | import net.spy.memcached.compat.log.SLF4JLogger; 7 | import net.spy.memcached.compat.log.SunLogger; 8 | 9 | public final class LoggerSetter { 10 | private LoggerSetter() {} 11 | 12 | public static void setLogger(Class logger) { 13 | System.setProperty("net.spy.log.LoggerImpl", logger.getName()); 14 | } 15 | 16 | public static void setDefaultLogger() { 17 | setLogger(DefaultLogger.class); 18 | } 19 | 20 | public static void setLog4JLogger() { 21 | setLogger(Log4JLogger.class); 22 | } 23 | 24 | public static void setSLF4JLogger() { 25 | setLogger(SLF4JLogger.class); 26 | } 27 | 28 | public static void setSunLogger() { 29 | setLogger(SunLogger.class); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/collection/attribute/SetAttrTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.collection.attribute; 18 | 19 | import net.spy.memcached.collection.BaseIntegrationTest; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | class SetAttrTest extends BaseIntegrationTest { 24 | 25 | @Test 26 | void testSetAttr() throws Exception { 27 | // TODO: implement 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/emptycollection/ProtocolListGetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.emptycollection; 18 | 19 | import net.spy.memcached.collection.ListGet; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | 25 | class ProtocolListGetTest { 26 | 27 | private static final int index = 10; 28 | 29 | @Test 30 | void testStringify() { 31 | assertEquals("10 drop", 32 | (new ListGet(index, true, true)).stringify()); 33 | assertEquals("10 delete", (new ListGet(index, true, 34 | false)).stringify()); 35 | assertEquals("10", 36 | (new ListGet(index, false, true)).stringify()); 37 | assertEquals("10", 38 | (new ListGet(index, false, false)).stringify()); 39 | 40 | assertEquals("10..20 delete", (new ListGet(10, 20, true, 41 | false)).stringify()); 42 | assertEquals("10..20 drop", (new ListGet(10, 20, true, 43 | true)).stringify()); 44 | assertEquals("10..20", 45 | (new ListGet(10, 20, false, true)).stringify()); 46 | assertEquals("10..20", 47 | (new ListGet(10, 20, false, false)).stringify()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/emptycollection/ProtocolMapGetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2016 JaM2in Co., Ltd. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.emptycollection; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import net.spy.memcached.collection.MapGet; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class ProtocolMapGetTest { 29 | 30 | private final String MKEY = "mkey"; 31 | 32 | @Test 33 | void testStringify() { 34 | // default setting : dropIfEmpty = true 35 | 36 | List mkeyList = new ArrayList<>(); 37 | mkeyList.add(MKEY); 38 | assertEquals("4 1 drop", 39 | (new MapGet(mkeyList, true, true)).stringify()); 40 | assertEquals("4 1 delete", 41 | (new MapGet(mkeyList, true, false)).stringify()); 42 | assertEquals("4 1", 43 | (new MapGet(mkeyList, false, true)).stringify()); 44 | assertEquals("4 1", 45 | (new MapGet(mkeyList, false, false)).stringify()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/emptycollection/ProtocolSetExistTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.emptycollection; 18 | 19 | import net.spy.memcached.collection.SetExist; 20 | import net.spy.memcached.transcoders.CollectionTranscoder; 21 | import net.spy.memcached.transcoders.Transcoder; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class ProtocolSetExistTest { 29 | private final Object value = "value"; 30 | private final Transcoder testTranscoder = new CollectionTranscoder(); 31 | 32 | @Test 33 | void testStringify() { 34 | SetExist exist = new SetExist<>(value, testTranscoder); 35 | assertEquals("5", exist.stringify()); 36 | } 37 | 38 | @Test 39 | void testGetAdditionalArgs() { 40 | SetExist exist = new SetExist<>(value, testTranscoder); 41 | assertArrayEquals(new byte[]{'v', 'a', 'l', 'u', 'e'}, exist.getAdditionalArgs()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/emptycollection/ProtocolSetGetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * arcus-java-client : Arcus Java client 3 | * Copyright 2010-2014 NAVER Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package net.spy.memcached.emptycollection; 18 | 19 | import net.spy.memcached.collection.SetGet; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | 25 | class ProtocolSetGetTest { 26 | 27 | private static final int count = 10; 28 | 29 | @Test 30 | void testStringify() { 31 | assertEquals("10 drop", 32 | (new SetGet(count, true, true)).stringify()); 33 | assertEquals("10 delete", 34 | (new SetGet(count, true, false)).stringify()); 35 | assertEquals("10", 36 | (new SetGet(count, false, true)).stringify()); 37 | assertEquals("10", 38 | (new SetGet(count, false, false)).stringify()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/test/AuthTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.test; 2 | 3 | import java.util.Collections; 4 | 5 | import net.spy.memcached.AddrUtil; 6 | import net.spy.memcached.ConnectionFactoryBuilder; 7 | import net.spy.memcached.ConnectionFactoryBuilder.Protocol; 8 | import net.spy.memcached.MemcachedClient; 9 | import net.spy.memcached.auth.AuthDescriptor; 10 | import net.spy.memcached.compat.SpyObject; 11 | 12 | /** 13 | * Authentication functional test. 14 | */ 15 | class AuthTest extends SpyObject implements Runnable { 16 | 17 | private final String username; 18 | private final String password; 19 | private MemcachedClient client; 20 | 21 | public AuthTest(String u, String p) { 22 | username = u; 23 | password = p; 24 | } 25 | 26 | public void init() throws Exception { 27 | client = new MemcachedClient(new ConnectionFactoryBuilder() 28 | .setProtocol(Protocol.BINARY) 29 | .setAuthDescriptor(AuthDescriptor.typical(username, password)) 30 | .build(), AddrUtil.getAddresses(Collections.singletonList("localhost:11212"))); 31 | } 32 | 33 | public void shutdown() throws Exception { 34 | client.shutdown(); 35 | } 36 | 37 | public void run() { 38 | System.out.println("Available mechs: " + client.listSaslMechanisms()); 39 | try { 40 | Thread.sleep(1000); 41 | } catch (InterruptedException e) { 42 | e.printStackTrace(); 43 | } 44 | client.getVersions(); 45 | } 46 | 47 | public static void main(String[] a) throws Exception { 48 | AuthTest lt = new AuthTest("testuser", "testpass"); 49 | lt.init(); 50 | long start = System.currentTimeMillis(); 51 | try { 52 | lt.run(); 53 | } finally { 54 | lt.shutdown(); 55 | } 56 | long end = System.currentTimeMillis(); 57 | System.out.println("Runtime: " + (end - start) + "ms"); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/test/MultiNodeFailureTest.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.test; 2 | 3 | import java.util.Arrays; 4 | 5 | import net.spy.memcached.AddrUtil; 6 | import net.spy.memcached.MemcachedClient; 7 | 8 | /** 9 | * This is an attempt to reproduce a problem where a server fails during a 10 | * series of gets. 11 | */ 12 | final class MultiNodeFailureTest { 13 | 14 | private MultiNodeFailureTest() { 15 | } 16 | 17 | public static void main(String args[]) throws Exception { 18 | MemcachedClient c = new MemcachedClient(AddrUtil.getAddresses( 19 | Arrays.asList("localhost:11200", " localhost:11201"))); 20 | while (true) { 21 | for (int i = 0; i < 1000; i++) { 22 | try { 23 | c.getBulk(Arrays.asList("blah1", "blah2", "blah3", "blah4", "blah5")); 24 | } catch (Exception e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | System.out.println("Did a thousand."); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/manual/net/spy/memcached/test/ObserverToy.java: -------------------------------------------------------------------------------- 1 | package net.spy.memcached.test; 2 | 3 | import java.net.SocketAddress; 4 | import java.util.Collection; 5 | import java.util.Collections; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import net.spy.memcached.AddrUtil; 9 | import net.spy.memcached.ConnectionObserver; 10 | import net.spy.memcached.DefaultConnectionFactory; 11 | import net.spy.memcached.MemcachedClient; 12 | 13 | /** 14 | * This expects a server on port 11212 that's somewhat unstable so it can report 15 | * and what-not. 16 | */ 17 | final class ObserverToy { 18 | 19 | private ObserverToy() { 20 | } 21 | 22 | public static void main(String[] args) throws Exception { 23 | final ConnectionObserver obs = new ConnectionObserver() { 24 | public void connectionEstablished(SocketAddress sa, 25 | int reconnectCount) { 26 | System.out.println("*** Established: " + sa + " count=" 27 | + reconnectCount); 28 | } 29 | 30 | public void connectionLost(SocketAddress sa) { 31 | System.out.println("*** Lost connection: " + sa); 32 | } 33 | 34 | }; 35 | 36 | MemcachedClient client = new MemcachedClient(new DefaultConnectionFactory() { 37 | 38 | @Override 39 | public Collection getInitialObservers() { 40 | return Collections.singleton(obs); 41 | } 42 | 43 | @Override 44 | public boolean isDaemon() { 45 | return false; 46 | } 47 | 48 | }, AddrUtil.getAddresses(Collections.singletonList("localhost:11212"))); 49 | 50 | while (true) { 51 | try { 52 | client.asyncGet("ObserverToy").get(1, TimeUnit.SECONDS); 53 | Thread.sleep(1000); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /xdocs/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Dustin Sallings 8 | java memcached client 9 | 10 | 11 | 12 |
13 |

14 | This project is now primarily hosted at 15 | google code 16 | hosting with the source at github. 18 |

19 |

20 | Changelog 21 |

22 |
23 | 24 |
25 | --------------------------------------------------------------------------------