本文整理汇总了Java中net.spy.memcached.transcoders.Transcoder类的典型用法代码示例。如果您正苦于以下问题:Java Transcoder类的具体用法?Java Transcoder怎么用?Java Transcoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transcoder类属于net.spy.memcached.transcoders包,在下文中一共展示了Transcoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cas
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
/**
* Method to allow CAS
* @param <T>
* @param key
* @param mutation
* @param value
* @return
*/
public <T> T cas(String key,CASMutation<T> mutation,T value,int expireSecs)
{
Transcoder transcoder = new SerializingTranscoder();
// The mutator who'll do all the low-level stuff.
// Set number of retries to limit time taken..its not essential this succeeds
CASMutator<T> mutator = new CASMutator<>(memcachedClient, transcoder,MAX_CAS_RETRIES);
// This returns whatever value was successfully stored within the
// cache -- either the initial list as above, or a mutated existing
// one
try
{
return mutator.cas(hashKey(key), value, expireSecs, mutation);
}
catch (Exception e)
{
logger.error("Failed up update hits in cache ",e);
return null;
}
}
示例2: asyncMopInsertBulk
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@Override
public <T> Future<Map<String, CollectionOperationStatus>> asyncMopInsertBulk(
List<String> keyList, String mkey, T value,
CollectionAttributes attributesForCreate, Transcoder<T> tc) {
validateMKey(mkey);
Map<String, List<String>> arrangedKey = groupingKeys(keyList, NON_PIPED_BULK_INSERT_CHUNK_SIZE);
List<CollectionBulkStore<T>> storeList = new ArrayList<CollectionBulkStore<T>>(
arrangedKey.size());
for (List<String> eachKeyList : arrangedKey.values()) {
storeList.add(new CollectionBulkStore.MapBulkStore<T>(
eachKeyList, mkey, value, attributesForCreate, tc));
}
return asyncCollectionInsertBulk2(storeList);
}
示例3: makeBTreeElement
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
/**
* Utility method to create a b+tree element from individual parameters.
*
* @param key b+tree item's key
* @param flags item flags, used when creating the item (see createKeyIfNotExists)
* @param bkey element key
* @param eflag element flags
* @param value element value
* @param tc transcoder to serialize and unserialize value
* @return element object containing all the parameters and transcoded value
*/
private <T> Element<T> makeBTreeElement(String key, int flags,
BKeyObject bkey, byte[] eflag, byte[] data, Transcoder<T> tc) {
Element<T> element = null;
T value = tc.decode(new CachedData(flags, data, tc.getMaxSize()));
switch (bkey.getType()) {
case LONG:
element = new Element<T>(bkey.getLongBKey(), value, eflag);
break;
case BYTEARRAY:
element = new Element<T>(bkey.getByteArrayBKeyRaw(), value, eflag);
break;
default:
getLogger().error(
"Unexpected bkey type : (key:" + key + ", bkey:"
+ bkey.toString() + ")");
}
return element;
}
示例4: asyncStore
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
private <T> Future<Boolean> asyncStore(StoreType storeType, String key,
int exp, T value, Transcoder<T> tc) {
CachedData co=tc.encode(value);
final CountDownLatch latch=new CountDownLatch(1);
final OperationFuture<Boolean> rv=new OperationFuture<Boolean>(latch,
operationTimeout);
Operation op=opFact.store(storeType, key, co.getFlags(),
exp, co.getData(), new OperationCallback() {
public void receivedStatus(OperationStatus val) {
rv.set(val.isSuccess());
}
public void complete() {
latch.countDown();
}});
rv.setOperation(op);
addOp(key, op);
return rv;
}
示例5: getBulkAsync
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@Override
public ComposableFuture<Map<K, V>> getBulkAsync(final Iterable<? extends K> keys) {
final List<String> stringKeys = new ArrayList<>();
final Map<String, K> keysMap = new HashMap<>();
try {
for (final K key : keys) {
final String stringKey = keyTranslator.translateKey(key);
stringKeys.add(stringKey);
keysMap.put(stringKey, key);
}
return SpyFutureHelper.fromBulkGet(() -> {
@SuppressWarnings("unchecked")
final Transcoder<V> transcoder = (Transcoder<V>) spyClient.getTranscoder();
return spyClient.asyncGetBulk(stringKeys, transcoder);
}, keysMap);
} catch (final Exception e) {
return fromError(e);
}
}
示例6: MapBulkStore
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
public MapBulkStore(List<String> keyList, String mkey, T value,
CollectionAttributes attr, Transcoder<T> tc) {
if (attr != null) {
CollectionOverflowAction overflowAction = attr.getOverflowAction();
if (overflowAction != null && !CollectionType.map.isAvailableOverflowAction(overflowAction))
throw new IllegalArgumentException(overflowAction + " is unavailable overflow action in " + CollectionType.map + ".");
}
this.keyList = keyList;
this.mkey = mkey;
this.value = value;
this.attribute = attr;
this.tc = tc;
this.itemCount = keyList.size();
this.createKeyIfNotExists = (attr != null);
this.cachedData = tc.encode(value);
}
示例7: asyncSopInsertBulk
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@Override
public <T> Future<Map<String, CollectionOperationStatus>> asyncSopInsertBulk(
List<String> keyList, T value,
CollectionAttributes attributesForCreate, Transcoder<T> tc) {
Map<String, List<String>> arrangedKey = groupingKeys(keyList, NON_PIPED_BULK_INSERT_CHUNK_SIZE);
List<CollectionBulkStore<T>> storeList = new ArrayList<CollectionBulkStore<T>>(
arrangedKey.size());
for (List<String> eachKeyList : arrangedKey.values()) {
storeList.add(new CollectionBulkStore.SetBulkStore<T>(
eachKeyList, value, attributesForCreate, tc));
}
return asyncCollectionInsertBulk2(storeList);
}
示例8: asyncBopInsertBulk
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@Override
public <T> Future<Map<String, CollectionOperationStatus>> asyncBopInsertBulk(
List<String> keyList, byte[] bkey, byte[] eFlag, T value,
CollectionAttributes attributesForCreate, Transcoder<T> tc) {
Map<String, List<String>> arrangedKey = groupingKeys(keyList, NON_PIPED_BULK_INSERT_CHUNK_SIZE);
List<CollectionBulkStore<T>> storeList = new ArrayList<CollectionBulkStore<T>>(
arrangedKey.size());
for (List<String> eachKeyList : arrangedKey.values()) {
storeList.add(new CollectionBulkStore.BTreeBulkStore<T>(
eachKeyList, bkey, eFlag, value, attributesForCreate, tc));
}
return asyncCollectionInsertBulk2(storeList);
}
示例9: asyncLopInsertBulk
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@Override
public <T> Future<Map<String, CollectionOperationStatus>> asyncLopInsertBulk(
List<String> keyList, int index, T value,
CollectionAttributes attributesForCreate, Transcoder<T> tc) {
Map<String, List<String>> arrangedKey = groupingKeys(keyList, NON_PIPED_BULK_INSERT_CHUNK_SIZE);
List<CollectionBulkStore<T>> storeList = new ArrayList<CollectionBulkStore<T>>(
arrangedKey.size());
for (List<String> eachKeyList : arrangedKey.values()) {
storeList.add(new CollectionBulkStore.ListBulkStore<T>(
eachKeyList, index, value, attributesForCreate, tc));
}
return asyncCollectionInsertBulk2(storeList);
}
示例10: BaseCacheMap
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
/**
* Build a BaseCacheMap.
*
* @param c the underlying client
* @param expiration the expiration for objects set through this Map
* @param prefix a prefix to ensure objects in this map are unique
* @param t the transcoder to serialize and deserialize objects
*/
public BaseCacheMap(MemcachedClientIF c, int expiration, String prefix,
Transcoder<V> t) {
super();
keyPrefix = prefix;
transcoder = t;
client = c;
exp = expiration;
}
示例11: cas
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
/**
* Method to allow CAS
* @param <T>
* @param key
* @param mutation
* @param value
* @return
*/
public static <T> T cas(String key,CASMutation<T> mutation,T value,int expireSecs)
{
MemcachedClient client = getClient();
if (client != null)
{
Transcoder transcoder = new SerializingTranscoder();
// The mutator who'll do all the low-level stuff.
// Set number of retries to limit time taken..its not essential this succeeds
CASMutator<T> mutator = new CASMutator<>(client, transcoder,MAX_CAS_RETRIES);
// This returns whatever value was successfully stored within the
// cache -- either the initial list as above, or a mutated existing
// one
try
{
return mutator.cas(hashKey(key), value, expireSecs, mutation);
}
catch (Exception e)
{
logger.error("Failed up update hits in cache ",e);
return null;
}
}
else
return null;
}
示例12: testGetBulkVarargWithTranscoder
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
public void testGetBulkVarargWithTranscoder() throws Exception {
Transcoder<String> t=new TestTranscoder();
assertEquals(0, client.getBulk(t, "test1", "test2", "test3").size());
client.set("test1", 5, "val1", t);
client.set("test2", 5, "val2", t);
Map<String, String> vals=client.getBulk(t, "test1", "test2", "test3");
assertEquals(2, vals.size());
assertEquals("val1", vals.get("test1"));
assertEquals("val2", vals.get("test2"));
}
示例13: asyncMopUpdate
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@Override
public <T> CollectionFuture<Boolean> asyncMopUpdate(String key, String mkey,
T value, Transcoder<T> tc) {
validateMKey(mkey);
MapUpdate<T> collectionUpdate = new MapUpdate<T>(value, false);
return asyncCollectionUpdate(key, String.valueOf(mkey),
collectionUpdate, tc);
}
示例14: getTranscoder
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Transcoder<T> getTranscoder(final CacheTranscoder transcoder) {
Transcoder<T> transcoderAdapter = (Transcoder<T>) adapters.get(transcoder);
if (transcoderAdapter == null) {
transcoderAdapter = (Transcoder<T>) new TranscoderAdapter(transcoder);
adapters.put(transcoder, transcoderAdapter);
}
return transcoderAdapter;
}
示例15: MapPipedUpdate
import net.spy.memcached.transcoders.Transcoder; //导入依赖的package包/类
public MapPipedUpdate(String key, Map<String, T> elements,
Transcoder<T> tc) {
this.key = key;
this.elements = elements;
this.tc = tc;
this.itemCount = elements.size();
}