Java Code Examples for javax.cache.processor.EntryProcessorResult#get()

The following examples show how to use javax.cache.processor.EntryProcessorResult#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteCacheProxyImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... args)
    throws EntryProcessorException {
    IgniteInternalCache<K, V> delegate = getDelegateSafe();

    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);
    }
}
 
Example 2
Source File: IgniteCacheProxyImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param topVer Locked topology version.
 * @param key Key.
 * @param entryProcessor Entry processor.
 * @param args Arguments.
 * @return Invoke result.
 */
public <T> T invoke(@Nullable AffinityTopologyVersion topVer,
    K key,
    EntryProcessor<K, V, T> entryProcessor,
    Object... args
) {
    IgniteInternalCache<K, V> delegate = getDelegateSafe();

    try {
        if (isAsync())
            throw new UnsupportedOperationException();
        else {
            EntryProcessorResult<T> res = delegate.invoke(topVer, key, entryProcessor, args);

            return res != null ? res.get() : null;
        }
    }
    catch (IgniteCheckedException | IgniteException e) {
        throw cacheException(e);
    }
}
 
Example 3
Source File: PlatformDotNetEntityFrameworkCacheExtension.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Removes old cache entries locally.
 *
 * @param ignite Ignite.
 * @param dataCacheName Cache name.
 * @param currentVersions Current versions.
 */
private static void removeOldEntries(final Ignite ignite, final String dataCacheName,
    final Map<String, EntryProcessorResult<Long>> currentVersions) {

    IgniteCache<PlatformDotNetEntityFrameworkCacheKey, PlatformDotNetEntityFrameworkCacheEntry> cache =
        ignite.cache(dataCacheName);

    Set<PlatformDotNetEntityFrameworkCacheKey> keysToRemove = new TreeSet<>();

    ClusterNode localNode = ignite.cluster().localNode();

    for (Cache.Entry<PlatformDotNetEntityFrameworkCacheKey, PlatformDotNetEntityFrameworkCacheEntry> cacheEntry :
        cache.localEntries(CachePeekMode.ALL)) {
        // Check if we are on a primary node for the key, since we use CachePeekMode.ALL
        // and we don't want to process backup entries.
        if (!ignite.affinity(dataCacheName).isPrimary(localNode, cacheEntry.getKey()))
            continue;

        long[] versions = cacheEntry.getKey().versions();
        String[] entitySets = cacheEntry.getValue().entitySets();

        for (int i = 0; i < entitySets.length; i++) {
            EntryProcessorResult<Long> curVer = currentVersions.get(entitySets[i]);

            if (curVer != null && versions[i] < curVer.get())
                keysToRemove.add(cacheEntry.getKey());
        }
    }

    cache.removeAll(keysToRemove);
}
 
Example 4
Source File: PlatformCache.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the result of InvokeAll cache method.
 *
 * @param writer Writer.
 * @param results Results.
 */
private static void writeInvokeAllResult(BinaryRawWriterEx writer, Map<Object, EntryProcessorResult> results) {
    if (results == null) {
        writer.writeInt(-1);

        return;
    }

    writer.writeInt(results.size());

    for (Map.Entry<Object, EntryProcessorResult> entry : results.entrySet()) {
        writer.writeObjectDetached(entry.getKey());

        EntryProcessorResult procRes = entry.getValue();

        try {
            Object res = procRes.get();

            writer.writeBoolean(false);  // No exception

            writer.writeObjectDetached(res);
        }
        catch (Exception ex) {
            writer.writeBoolean(true);  // Exception

            PlatformUtils.writeError(ex, writer);
        }
    }
}