本文整理汇总了Java中javax.cache.processor.EntryProcessor类的典型用法代码示例。如果您正苦于以下问题:Java EntryProcessor类的具体用法?Java EntryProcessor怎么用?Java EntryProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntryProcessor类属于javax.cache.processor包,在下文中一共展示了EntryProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
@Override
void execute(Cache<Object, Object> cache, Exchange exchange) {
Message message = exchange.getIn();
Set<Object> keys = message.getHeader(JCacheConstants.KEYS, Set.class);
EntryProcessor<Object, Object, Object> entryProcessor = message.getHeader(JCacheConstants.ENTRY_PROCESSOR, EntryProcessor.class);
Collection<Object> arguments = message.getHeader(JCacheConstants.ARGUMENTS, Collection.class);
if (arguments == null) {
arguments = Collections.emptyList();
}
message.setBody(
keys != null
? cache.invokeAll(
keys,
entryProcessor,
arguments)
: cache.invoke(
exchange.getIn().getHeader(JCacheConstants.KEY),
entryProcessor,
arguments)
);
}
示例2: updateKey
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/**
* Update random key in async mode.
*
* @param cache Cache to use.
* @return IgniteFuture.
*/
private IgniteFuture<?> updateKey(IgniteCache<Integer, Integer> cache) {
IgniteCache asyncCache = cache.withAsync();
// Using EntryProcessor.invokeAll to increment every value in place.
asyncCache.invoke(rnd.nextInt(100), new EntryProcessor<Integer, Integer, Object>() {
@Override public Object process(MutableEntry<Integer, Integer> entry, Object... arguments)
throws EntryProcessorException {
entry.setValue(entry.getValue() + 1);
return null;
}
});
return asyncCache.future();
}
示例3: transferEntry
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/**
* Transfer entry from one directory to another.
*
* @param entry Entry to be transferred.
* @param srcId Source ID.
* @param srcName Source name.
* @param destId Destination ID.
* @param destName Destination name.
* @throws IgniteCheckedException If failed.
*/
private void transferEntry(IgfsListingEntry entry, IgniteUuid srcId, String srcName,
IgniteUuid destId, String destName) throws IgniteCheckedException {
validTxState(true);
if (F.eq(srcId, destId))
id2InfoPrj.invoke(srcId, new IgfsMetaDirectoryListingRenameProcessor(srcName, destName));
else {
Map<IgniteUuid, EntryProcessor<IgniteUuid, IgfsEntryInfo, Void>> procMap = new HashMap<>();
procMap.put(srcId, new IgfsMetaDirectoryListingRemoveProcessor(srcName, entry.fileId()));
procMap.put(destId, new IgfsMetaDirectoryListingAddProcessor(destName, entry));
id2InfoPrj.invokeAll(procMap);
}
}
示例4: invokeAll
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
@Override
public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... arguments) {
checkClosed();
if (keys == null || entryProcessor == null) {
throw new NullPointerException();
}
HashMap<K, EntryProcessorResult<T>> map = new HashMap<>();
for (K key : keys) {
EntryProcessorResult<T> result;
try {
T t = invoke(key, entryProcessor, arguments);
result = t == null ? null : new EntryProcessorResultImpl<>(t, null);
} catch (Exception e) {
result = new EntryProcessorResultImpl<>(null, new EntryProcessorException(e));
}
if (result != null) {
map.put(key, result);
}
}
return map;
}
示例5: invokeAllAsync
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(
Map<? extends K, ? extends EntryProcessor<K, V, T>> map,
Object... args) {
A.notNull(map, "map");
if (keyCheck)
validateCacheKeys(map.keySet());
return updateAll0(null,
map,
args,
null,
null,
false,
false,
TRANSFORM,
true);
}
示例6: invokeAllAsync
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(
Map<? extends K, ? extends EntryProcessor<K, V, T>> map,
Object... args) {
A.notNull(map, "map");
if (keyCheck)
validateCacheKeys(map.keySet());
return updateAllAsync0(null,
map,
args,
true,
false,
null);
}
示例7: invokeAll
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(
final Map<? extends K, ? extends EntryProcessor<K, V, T>> map,
final Object... args) throws IgniteCheckedException {
A.notNull(map, "map");
if (keyCheck)
validateCacheKeys(map.keySet());
return syncOp(new SyncOp<Map<K, EntryProcessorResult<T>>>(map.size() == 1) {
@Nullable @Override public Map<K, EntryProcessorResult<T>> op(GridNearTxLocal tx)
throws IgniteCheckedException {
IgniteInternalFuture<GridCacheReturn> fut =
tx.invokeAsync(ctx, null, (Map<? extends K, ? extends EntryProcessor<K, V, Object>>)map, args);
return fut.get().value();
}
});
}
示例8: invoke
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... args)
throws EntryProcessorException {
try {
if (isAsync()) {
setFuture(invokeAsync0(key, entryProcessor, args));
return null;
}
else {
EntryProcessorResult<T> res = delegate.invoke(key, entryProcessor, args);
return res != null ? res.get() : null;
}
}
catch (IgniteCheckedException | IgniteException e) {
throw cacheException(e);
}
}
示例9: invokeAsync0
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/**
* Invoke async operation internal implementation.
*
* @param key Key.
* @param entryProcessor Processor.
* @param args Arguments.
* @return Internal future.
*/
private <T> IgniteInternalFuture<T> invokeAsync0(K key, EntryProcessor<K, V, T> entryProcessor, Object[] args) {
IgniteInternalFuture<EntryProcessorResult<T>> fut = delegate.invokeAsync(key, entryProcessor, args);
return fut.chain(new CX1<IgniteInternalFuture<EntryProcessorResult<T>>, T>() {
@Override public T applyx(IgniteInternalFuture<EntryProcessorResult<T>> fut1)
throws IgniteCheckedException {
try {
EntryProcessorResult<T> res = fut1.get();
return res != null ? res.get() : null;
}
catch (RuntimeException e) {
throw new GridClosureException(e);
}
}
});
}
示例10: invokeAll
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys,
EntryProcessor<K, V, T> entryProcessor,
Object... args) {
try {
if (isAsync()) {
setFuture(delegate.invokeAllAsync(keys, entryProcessor, args));
return null;
}
else
return delegate.invokeAll(keys, entryProcessor, args);
}
catch (IgniteCheckedException | IgniteException e) {
throw cacheException(e);
}
}
示例11: checkImplicitTxSuccess
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/**
* Success if implicit tx fails.
*
* @param cache Cache instance.
* @throws Exception If failed.
*/
protected void checkImplicitTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception {
cache.invoke("key", new EntryProcessor<Object, Object, Object>() {
@Override public Object process(final MutableEntry<Object, Object> entry, final Object... args)
throws EntryProcessorException {
try {
sleepForTxFailure();
} catch (InterruptedException e) {
throw new EntryProcessorException(e);
}
return null;
}
});
cache.clear();
}
示例12: invokeAsync
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/**
* @param cacheCtx Cache context.
* @param map Entry processors map.
* @param invokeArgs Optional arguments for entry processor.
* @return Operation future.
*/
@SuppressWarnings("unchecked")
public <K, V, T> IgniteInternalFuture<GridCacheReturn> invokeAsync(
GridCacheContext cacheCtx,
@Nullable AffinityTopologyVersion entryTopVer,
@Nullable Map<? extends K, ? extends EntryProcessor<K, V, Object>> map,
Object... invokeArgs
) {
return (IgniteInternalFuture<GridCacheReturn>)putAllAsync0(cacheCtx,
entryTopVer,
null,
map,
invokeArgs,
null,
true);
}
示例13: addNearWriteValue
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
/**
* @param key Key to add.
* @param val Value, {@code null} if should be removed.
* @param entryProcessor Entry processor.
* @param ttl TTL.
* @param expireTime Expire time.
*/
@Override public void addNearWriteValue(KeyCacheObject key,
@Nullable CacheObject val,
EntryProcessor<Object, Object, Object> entryProcessor,
long ttl,
long expireTime) {
assert entryProcessor == null;
assert ttl <= 0 : ttl;
assert key.partition() >= 0 : key;
if (this.key != null) {
setFlag(true, DHT_ATOMIC_OBSOLETE_NEAR_KEY_FLAG_MASK);
return;
}
near(true);
this.key = key;
this.val = val;
}
示例14: invokeAll
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
@Override
public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor,
Object... arguments) {
checkNotClosed();
if (entryProcessor == null) {
throw new NullPointerException();
}
Map<K, EntryProcessorResult<T>> results = new HashMap<K, EntryProcessorResult<T>>();
for (K key : keys) {
try {
final T result = invoke(key, entryProcessor, arguments);
if (result != null) {
results.put(key, new EntryProcessorResult<T>() {
@Override
public T get() throws EntryProcessorException {
return result;
}
});
}
} catch (final EntryProcessorException e) {
results.put(key, new EntryProcessorResult<T>() {
@Override
public T get() throws EntryProcessorException {
throw e;
}
});
}
}
return results;
}
示例15: invokeAll
import javax.cache.processor.EntryProcessor; //导入依赖的package包/类
@Override
public <T> Map<K, EntryProcessorResult<T>> invokeAll(final Set<? extends K> keys, final EntryProcessor<K, V, T> entryProcessor,
final Object... arguments) {
checkClosed();
final Map<K, EntryProcessorResult<T>> ret = new HashMap<>();
for(final K key : keys){
try{
final T entryProcessorProcessResult = invoke( key, entryProcessor, arguments );
if(entryProcessorProcessResult!=null){
ret.put( key, new EntryProcessorResult<T>() {
@Override
public T get() throws EntryProcessorException {
return entryProcessorProcessResult;
}
} );
}
}
catch(final EntryProcessorException e){
ret.put( key, new EntryProcessorResult<T>() {
@Override
public T get() throws EntryProcessorException {
throw e;
}
} );
}
}
return ret;
}