Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/net/spy/memcached/ArcusClientPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,26 @@ public GetFuture<CASValue<Object>> asyncGets(String key) {
return this.getClient().asyncGets(key);
}

@Override
public <T> GetFuture<T> asyncGetAndTouch(String key, int exp, Transcoder<T> tc) {
return this.getClient().asyncGetAndTouch(key, exp, tc);
}

@Override
public GetFuture<Object> asyncGetAndTouch(String key, int exp) {
return this.getClient().asyncGetAndTouch(key, exp);
}

@Override
public <T> GetFuture<CASValue<T>> asyncGetsAndTouch(String key, int exp, Transcoder<T> tc) {
return this.getClient().asyncGetsAndTouch(key, exp, tc);
}

@Override
public GetFuture<CASValue<Object>> asyncGetsAndTouch(String key, int exp) {
return this.getClient().asyncGetsAndTouch(key, exp);
}

@Override
public <T> CASValue<T> gets(String key, Transcoder<T> tc)
throws OperationTimeoutException {
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
import net.spy.memcached.ops.CancelledOperationStatus;
import net.spy.memcached.ops.ConcatenationType;
import net.spy.memcached.ops.DeleteOperation;
import net.spy.memcached.ops.GetAndTouchOperation;
import net.spy.memcached.ops.GetOperation;
import net.spy.memcached.ops.GetsAndTouchOperation;
import net.spy.memcached.ops.GetsOperation;
import net.spy.memcached.ops.Mutator;
import net.spy.memcached.ops.Operation;
Expand Down Expand Up @@ -986,6 +988,107 @@ public GetFuture<CASValue<Object>> asyncGets(final String key) {
return asyncGets(key, transcoder);
}

/**
* Get the given key to reset its expiration time asynchronously.
*
* @param key the key to fetch
* @param exp the new expiration to set for the given key
* @param tc the transcoder to serialize and unserialize value
* @return a future that will hold the return value of the fetch
* @throws IllegalStateException in the rare circumstance where queue is too
* full to accept any more requests
*/
public <T> GetFuture<T> asyncGetAndTouch(final String key, final int exp,
final Transcoder<T> tc) {
final CountDownLatch latch = new CountDownLatch(1);
final GetFuture<T> future = new GetFuture<>(latch, operationTimeout);

Operation op = opFact.getAndTouch(key, exp,
new GetAndTouchOperation.Callback() {
private GetResult<T> result = null;

public void receivedStatus(OperationStatus status) {
future.set(result, status);
}

public void gotData(String k, int flags, byte[] data) {
assert k.equals(key) : "Wrong key returned";
result = new GetResultImpl<>(new CachedData(flags, data, tc.getMaxSize()), tc);
}

public void complete() {
latch.countDown();
}
});
future.setOperation(op);
addOp(key, op);
return future;
}

/**
* Get the given key to reset its expiration time asynchronously.
*
* @param key the key to fetch
* @param exp the new expiration to set for the given key
* @return a future that will hold the return value of the fetch
* @throws IllegalStateException in the rare circumstance where queue is too
* full to accept any more requests
*/
public GetFuture<Object> asyncGetAndTouch(final String key, final int exp) {
return asyncGetAndTouch(key, exp, transcoder);
}

/**
* Gets (with CAS support) the given key to reset its expiration time asynchronously.
*
* @param key the key to fetch
* @param exp the new expiration to set for the given key
* @param tc the transcoder to serialize and unserialize value
* @return a future that will hold the return value of the fetch
* @throws IllegalStateException in the rare circumstance where queue is too
* full to accept any more requests
*/
public <T> GetFuture<CASValue<T>> asyncGetsAndTouch(final String key, final int exp,
final Transcoder<T> tc) {
final CountDownLatch latch = new CountDownLatch(1);
final GetFuture<CASValue<T>> rv = new GetFuture<>(latch, operationTimeout);

Operation op = opFact.getsAndTouch(key, exp,
new GetsAndTouchOperation.Callback() {
private GetResult<CASValue<T>> val = null;

public void receivedStatus(OperationStatus status) {
rv.set(val, status);
}

public void gotData(String k, int flags, long cas, byte[] data) {
assert key.equals(k) : "Wrong key returned";
assert cas > 0 : "CAS was less than zero: " + cas;
val = new GetsResultImpl<>(cas, new CachedData(flags, data, tc.getMaxSize()), tc);
}

public void complete() {
latch.countDown();
}
});
rv.setOperation(op);
addOp(key, op);
return rv;
}

/**
* Gets (with CAS support) the given key to reset its expiration time asynchronously.
*
* @param key the key to fetch
* @param exp the new expiration to set for the given key
* @return a future that will hold the return value of the fetch
* @throws IllegalStateException in the rare circumstance where queue is too
* full to accept any more requests
*/
public GetFuture<CASValue<Object>> asyncGetsAndTouch(final String key, final int exp) {
return asyncGetsAndTouch(key, exp, transcoder);
}

/**
* Gets (with CAS support) with a single key.
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/spy/memcached/MemcachedClientIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ <T> Future<CASValue<T>> asyncGets(String key,

Future<CASValue<Object>> asyncGets(String key);

<T> Future<T> asyncGetAndTouch(final String key, final int exp, final Transcoder<T> tc);

Future<Object> asyncGetAndTouch(final String key, final int exp);

<T> Future<CASValue<T>> asyncGetsAndTouch(final String key, final int exp,
final Transcoder<T> tc);

Future<CASValue<Object>> asyncGetsAndTouch(final String key, final int exp);

<T> CASValue<T> gets(String key, Transcoder<T> tc)
throws OperationTimeoutException;

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/net/spy/memcached/OperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@
import net.spy.memcached.ops.ConcatenationType;
import net.spy.memcached.ops.DeleteOperation;
import net.spy.memcached.ops.FlushOperation;
import net.spy.memcached.ops.GetAndTouchOperation;
import net.spy.memcached.ops.GetAttrOperation;
import net.spy.memcached.ops.GetOperation;
import net.spy.memcached.ops.GetsAndTouchOperation;
import net.spy.memcached.ops.GetsOperation;
import net.spy.memcached.ops.KeyedOperation;
import net.spy.memcached.ops.MultiOperationCallback;
Expand Down Expand Up @@ -152,6 +154,28 @@ public interface OperationFactory {
*/
GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMGet);

/**
* Get the key and resets its timeout.
*
* @param key the key to get a value for and reset its timeout
* @param expiration the new expiration for the key
* @param cb the callback that will contain the result
* @return a new GetAndTouchOperation
*/
GetAndTouchOperation getAndTouch(String key, int expiration,
GetAndTouchOperation.Callback cb);

/**
* Gets (with CAS support) the key and resets its timeout.
*
* @param key the key to get a value for and reset its timeout
* @param expiration the new expiration for the key
* @param cb the callback that will contain the result
* @return a new GetsAndTouchOperation
*/
GetsAndTouchOperation getsAndTouch(String key, int expiration,
GetsAndTouchOperation.Callback cb);

/**
* Create a mutator operation.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/spy/memcached/ops/APIType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum APIType {
INCR(OperationType.WRITE), DECR(OperationType.WRITE),
DELETE(OperationType.WRITE),
GET(OperationType.READ), GETS(OperationType.READ),
GAT(OperationType.WRITE), GATS(OperationType.WRITE),

// List API Type
LOP_CREATE(OperationType.WRITE),
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/spy/memcached/ops/BaseOperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public Collection<Operation> clone(KeyedOperation op) {
for (String k : op.getKeys()) {
rv.add(gets(k, getsCb));
}
} else if (op instanceof GetAndTouchOperation) {
GetAndTouchOperation gt = (GetAndTouchOperation) op;
rv.add(getAndTouch(first(gt.getKeys()), gt.getExpiration(),
(GetAndTouchOperation.Callback) gt.getCallback()));
} else if (op instanceof GetsAndTouchOperation) {
GetsAndTouchOperation gt = (GetsAndTouchOperation) op;
rv.add(getsAndTouch(first(gt.getKeys()), gt.getExpiration(),
(GetsAndTouchOperation.Callback) gt.getCallback()));
} else if (op instanceof CASOperation) {
CASOperation cop = (CASOperation) op;
rv.add(cas(cop.getStoreType(), first(op.getKeys()),
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/net/spy/memcached/ops/GetAndTouchOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* arcus-java-client : Arcus Java client
* Copyright 2010-2014 NAVER Corp.
* Copyright 2014-present JaM2in Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.spy.memcached.ops;

/**
* Gat(GetAndTouch) operation.
*/
public interface GetAndTouchOperation extends KeyedOperation {

/**
* Operation callback for the gat request.
*/
interface Callback extends OperationCallback {
/**
* Callback for each result from a gat.
*
* @param key the key that was retrieved
* @param flags the flags for this value
* @param data the data stored under this key
*/
void gotData(String key, int flags, byte[] data);
}

/**
* Get the expiration to set in case of a new entry.
*/
int getExpiration();
}
44 changes: 44 additions & 0 deletions src/main/java/net/spy/memcached/ops/GetsAndTouchOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* arcus-java-client : Arcus Java client
* Copyright 2010-2014 NAVER Corp.
* Copyright 2014-present JaM2in Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.spy.memcached.ops;

/**
* Gats(GetsAndTouch) operation.
*/
public interface GetsAndTouchOperation extends KeyedOperation {
/**
* Operation callback for the gats request.
*/
interface Callback extends OperationCallback {
/**
* Callback for each result from a gats.
*
* @param key the key that was retrieved
* @param flags the flags for this value
* @param cas the CAS value for this record
* @param data the data stored under this key
*/
void gotData(String key, int flags, long cas, byte[] data);
}

/**
* Get the expiration to set in case of a new entry.
*/
int getExpiration();
}
1 change: 1 addition & 0 deletions src/main/java/net/spy/memcached/ops/OperationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum OperationType {
* BTreeInsertAndGetOperationImpl (asyncBopInsertAndGetTrimmed)
* FlushOperationImpl / FlushByPrefixOperationImpl (flush)
* SetAttrOperationImpl (asyncSetAttr)
* GetAndTouchOperationImpl / GetsAndTouchOperationImpl (asyncGetAndTouch / asyncGetsAndTouch)
*/
WRITE,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@
import net.spy.memcached.ops.ConcatenationType;
import net.spy.memcached.ops.DeleteOperation;
import net.spy.memcached.ops.FlushOperation;
import net.spy.memcached.ops.GetAndTouchOperation;
import net.spy.memcached.ops.GetAttrOperation;
import net.spy.memcached.ops.GetOperation;
import net.spy.memcached.ops.GetsAndTouchOperation;
import net.spy.memcached.ops.GetsOperation;
import net.spy.memcached.ops.Mutator;
import net.spy.memcached.ops.MutatorOperation;
Expand Down Expand Up @@ -109,6 +111,16 @@ public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, bo
return new GetsOperationImpl(keys, cb, isMGet);
}

public GetAndTouchOperation getAndTouch(String key, int expiration,
GetAndTouchOperation.Callback cb) {
return new GetAndTouchOperationImpl(key, expiration, cb);
}

public GetsAndTouchOperation getsAndTouch(String key, int expiration,
GetsAndTouchOperation.Callback cb) {
return new GetsAndTouchOperationImpl(key, expiration, cb);
}

public MutatorOperation mutate(Mutator m, String key, int by,
long def, int exp, OperationCallback cb) {
return new MutatorOperationImpl(m, key, by, def, exp, cb);
Expand Down
Loading
Loading