javax.cache.processor.EntryProcessorException Java Examples

The following examples show how to use javax.cache.processor.EntryProcessorException. 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: JCacheCache.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public T process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
	Callable<T> valueLoader = (Callable<T>) arguments[0];
	if (entry.exists()) {
		return (T) fromStoreValue(entry.getValue());
	}
	else {
		T value;
		try {
			value = valueLoader.call();
		}
		catch (Exception ex) {
			throw new EntryProcessorException("Value loader '" + valueLoader + "' failed " +
					"to compute value for key '" + entry.getKey() + "'", ex);
		}
		entry.setValue(toStoreValue(value));
		return value;
	}
}
 
Example #2
Source File: GridCacheAtomicStampedImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Boolean process(MutableEntry<GridCacheInternalKey, GridCacheAtomicStampedValue<T, S>> e,
    Object... args) {
    GridCacheAtomicStampedValue val = e.getValue();

    if (val == null)
        throw new EntryProcessorException("Failed to find atomic stamped with given name: " + e.getKey().name());

    if (F.eq(expVal, val.value()) && F.eq(expStamp, val.stamp())) {
        e.setValue(new GridCacheAtomicStampedValue<>(newVal, newStamp));

        return true;
    }

    return false;
}
 
Example #3
Source File: IgniteAtomicInvokeRetryBenchmark.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Object process(MutableEntry<String, Set> entry,
    Object... arguments) throws EntryProcessorException {
    assert !F.isEmpty(arguments);

    Object val = arguments[0];

    Set set;

    if (!entry.exists())
        set = new HashSet<>();
    else
        set = entry.getValue();

    set.add(val);

    entry.setValue(set);

    return null;
}
 
Example #4
Source File: PlatformCache.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Exception convertException(Exception e) {
    if (e instanceof CachePartialUpdateException)
        return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException)e.getCause(),
            platformCtx, keepBinary);

    if (e instanceof CachePartialUpdateCheckedException)
        return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException)e, platformCtx, keepBinary);

    if (e.getCause() instanceof EntryProcessorException)
        return (Exception)e.getCause();

    TransactionDeadlockException deadlockException = X.cause(e, TransactionDeadlockException.class);

    if (deadlockException != null)
        return deadlockException;

    TransactionTimeoutException timeoutException = X.cause(e, TransactionTimeoutException.class);

    if (timeoutException != null)
        return timeoutException;

    return super.convertException(e);
}
 
Example #5
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testTransformException() throws Exception {
    final IgniteCache<String, Integer> cache = jcache();

    assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            IgniteFuture fut = cache.invokeAsync("key2", ERR_PROCESSOR).chain(new IgniteClosure<IgniteFuture, Object>() {
                @Override public Object apply(IgniteFuture o) {
                    return o.get();
                }
            });

            fut.get();

            return null;
        }
    }, EntryProcessorException.class, null);
}
 
Example #6
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 */
private void cacheInvokeAsync(IgniteCache cache) {
    Random rnd = ThreadLocalRandom.current();

    Integer key = rnd.nextInt();
    Integer val = rnd.nextInt();

    cache.put(key, val);

    int one = rnd.nextInt();
    int two = rnd.nextInt();

    Object res = cache.invokeAsync(key, new CacheEntryProcessor<Integer, Integer, Integer>() {
        @Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException {
            assertEquals(arguments[0], entry.getValue());

            // Some calculation.
            return (Integer)arguments[1] + (Integer)arguments[2];
        }
    }, val, one, two).get(ASYNC_TIMEOUT);

    assertEquals(one + two, res);

    tearDown(cache);
}
 
Example #7
Source File: EntryProcessorResourceInjectorProxy.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public T process(MutableEntry<K, V> entry, Object... arguments) throws EntryProcessorException {
    if (!injected) {
        GridCacheContext cctx = entry.unwrap(GridCacheContext.class);

        GridResourceProcessor rsrc = cctx.kernalContext().resource();

        try {
            rsrc.inject(delegate, GridResourceIoc.AnnotationSet.ENTRY_PROCESSOR, cctx.name());
        }
        catch (IgniteCheckedException e) {
            throw new IgniteException(e);
        }

        injected = true;
    }

    return delegate.process(entry, arguments);
}
 
Example #8
Source File: PlatformDotNetSessionSetAndUnlockProcessor.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Void process(MutableEntry<String, PlatformDotNetSessionData> entry, Object... args)
    throws EntryProcessorException {
    assert entry.exists();

    PlatformDotNetSessionData data = entry.getValue();

    assert data != null;

    // Unlock and update.
    data = update
        ? data.updateAndUnlock(lockNodeId, lockId, items, isDiff, staticData, timeout)
        : data.unlock(lockNodeId, lockId);

    // Apply.
    entry.setValue(data);

    return null;
}
 
Example #9
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 #10
Source File: IgniteSqlNotNullConstraintTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void testTxInvokeAll() throws Exception {
    executeWithAllTxCaches(new TestClosure() {
        @Override public void run() throws Exception {

            try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                final Map<Integer, EntryProcessorResult<Object>> r = cache.invokeAll(F.asMap(
                    key1, new TestEntryProcessor(okValue),
                    key2, new TestEntryProcessor(badValue)));

                assertNotNull(r);

                GridTestUtils.assertThrows(log, new Callable<Object>() {
                    @Override public Object call() throws Exception {
                        return r.get(key2).get();
                    }
                }, EntryProcessorException.class, ERR_MSG);

                tx.rollback();
            }

            assertEquals(0, cache.size());
        }
    });
}
 
Example #11
Source File: IgniteCacheInvokeAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer process(MutableEntry<Integer, Integer> e, Object... args)
    throws EntryProcessorException {
    assertEquals(3, args.length);
    assertEquals(10, args[0]);
    assertEquals(20, args[1]);
    assertEquals(30, args[2]);

    assertTrue(e.exists());

    Integer res = e.getValue();

    for (Object arg : args)
        res += (Integer)arg;

    e.setValue(res);

    return args.length;
}
 
Example #12
Source File: DmlStatementsProcessor.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Boolean process(MutableEntry<Object, Object> entry, Object... arguments)
    throws EntryProcessorException {
    if (!entry.exists())
        return null; // Someone got ahead of us and removed this entry, let's skip it.

    Object entryVal = entry.getValue();

    if (entryVal == null)
        return null;

    // Something happened to the cache while we were performing map-reduce.
    if (!F.eq(entryVal, val))
        return false;

    entryModifier.apply(entry);

    return null; // To leave out only erroneous keys - nulls are skipped on results' processing.
}
 
Example #13
Source File: PlatformDotNetSessionLockProcessor.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Object process(MutableEntry<String, PlatformDotNetSessionData> entry, Object... args)
    throws EntryProcessorException {
    if (!entry.exists())
        return null;

    PlatformDotNetSessionData data = entry.getValue();

    assert data != null;

    if (data.isLocked())
        return new PlatformDotNetSessionLockResult(false, null, data.lockTime(), data.lockId());

    // Not locked: lock and return result
    data = data.lock(lockNodeId, lockId, lockTime);

    // Apply.
    entry.setValue(data);

    return new PlatformDotNetSessionLockResult(true, data, null, data.lockId());
}
 
Example #14
Source File: IgniteCacheFailedUpdateResponseTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 */
private void testInvoke(final IgniteCache<Object, Object> cache) throws Exception {
    Class<? extends Exception> exp = grid("client").transactions().tx() == null || ((IgniteCacheProxy)cache).context().mvccEnabled()
        ? EntryProcessorException.class
        : NonSerializableException.class;

    //noinspection ThrowableNotThrown
    assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            cache.invoke("1", new UpdateProcessor());

            return null;
        }
    }, exp, null);

    if (ATOMIC_CACHE.equals(cache.getName())) {
        //noinspection ThrowableNotThrown
        assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                cache.invoke("1", new UpdateValueProcessor());

                return null;
            }
        }, CachePartialUpdateException.class, null);
    }
}
 
Example #15
Source File: IgfsMetaDirectoryListingRemoveProcessor.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Void process(MutableEntry<IgniteUuid, IgfsEntryInfo> e, Object... args)
    throws EntryProcessorException {
    IgfsEntryInfo fileInfo = e.getValue();

    assert fileInfo != null;
    assert fileInfo.isDirectory();

    Map<String, IgfsListingEntry> listing = new HashMap<>(fileInfo.listing());

    IgfsListingEntry oldEntry = listing.get(fileName);

    if (oldEntry == null || !oldEntry.fileId().equals(fileId))
        throw new IgniteException("Directory listing doesn't contain expected file" +
            " [listing=" + listing + ", fileName=" + fileName + "]");

    // Modify listing in-place.
    listing.remove(fileName);

    e.setValue(fileInfo.listing(listing));

    return null;
}
 
Example #16
Source File: IgfsMetaFileCreateProcessor.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args)
    throws EntryProcessorException {
    IgfsEntryInfo info = IgfsUtils.createFile(
        entry.getKey(),
        blockSize,
        len,
        affKey,
        lockId,
        evictExclude,
        props,
        accessTime,
        modificationTime
    );

    entry.setValue(info);

    return info;
}
 
Example #17
Source File: JCacheCache.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
	Callable<T> valueLoader = (Callable<T>) arguments[0];
	if (entry.exists()) {
		return (T) fromStoreValue(entry.getValue());
	}
	else {
		T value;
		try {
			value = valueLoader.call();
		}
		catch (Exception ex) {
			throw new EntryProcessorException("Value loader '" + valueLoader + "' failed " +
					"to compute  value for key '" + entry.getKey() + "'", ex);
		}
		entry.setValue(toStoreValue(value));
		return value;
	}
}
 
Example #18
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 */
private void cacheInvoke(IgniteCache cache) {
    Random rnd = ThreadLocalRandom.current();

    Integer key = rnd.nextInt();
    Integer val = rnd.nextInt();

    cache.put(key, val);

    int one = rnd.nextInt();
    int two = rnd.nextInt();

    Object res = cache.invoke(key, new CacheEntryProcessor<Integer, Integer, Integer>() {
        @Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException {
            assertEquals(arguments[0], entry.getValue());

            // Some calculation.
            return (Integer)arguments[1] + (Integer)arguments[2];
        }
    }, val, one, two);

    assertEquals(one + two, res);

    tearDown(cache);
}
 
Example #19
Source File: JCacheCache.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public T process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
	Callable<T> valueLoader = (Callable<T>) arguments[0];
	if (entry.exists()) {
		return (T) fromStoreValue(entry.getValue());
	}
	else {
		T value;
		try {
			value = valueLoader.call();
		}
		catch (Exception ex) {
			throw new EntryProcessorException("Value loader '" + valueLoader + "' failed " +
					"to compute value for key '" + entry.getKey() + "'", ex);
		}
		entry.setValue(toStoreValue(value));
		return value;
	}
}
 
Example #20
Source File: CacheEntryProcessorNonSerializableTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments)
    throws EntryProcessorException {
    entry.setValue(42);

    return null;
}
 
Example #21
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache.
 */
private void cacheInvokeAll(IgniteCache cache) {
    int keys = 100;
    Map<Integer, Integer> data = generateDataMap(keys);

    cache.putAll(data);

    Random rnd = ThreadLocalRandom.current();

    int one = rnd.nextInt();
    int two = rnd.nextInt();

    Map<Integer, CacheInvokeResult<Integer>> res = cache.invokeAll(data.keySet(), new CacheEntryProcessor<Integer, Integer, Integer>() {
        @Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException {
            Object expected = ((Map)arguments[0]).get(entry.getKey());

            assertEquals(expected, entry.getValue());

            // Some calculation.
            return (Integer)arguments[1] + (Integer)arguments[2];
        }
    }, data, one, two);

    assertEquals(keys, res.size());
    assertEquals(one + two, (Object)res.get(0).get());

    tearDown(cache);
}
 
Example #22
Source File: CacheEntryProcessorExternalizableFailedTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments)
    throws EntryProcessorException {
    entry.setValue(42);

    return null;
}
 
Example #23
Source File: GridCacheNearMetricsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes entry processor, which sets value "1" for key into cache.
 *
 * @param cache Cache.
 * @param key Key.
 */
private void setValue1ByEntryProcessor(IgniteCache<Integer, Integer> cache, int key) {
    cache.invoke(key, new CacheEntryProcessor<Integer, Integer, Object>() {
        @Override public Object process(MutableEntry<Integer, Integer> entry,
            Object... arguments) throws EntryProcessorException {
            entry.setValue(1);

            return null;
        }
    });
}
 
Example #24
Source File: CacheEntryProcessorExternalizableFailedTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer process(MutableEntry<Integer, Integer> entry, Object... arguments)
    throws EntryProcessorException {
    entry.setValue(42);

    return null;
}
 
Example #25
Source File: IgniteCacheFailedUpdateResponseTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache.
 */
private void testInvokeAll(final IgniteCache<Object, Object> cache) throws Exception {
    Map<Object, EntryProcessorResult<Object>> results = cache.invokeAll(Collections.singleton("1"), new UpdateProcessor());

    final EntryProcessorResult<Object> epRes = F.first(results.values());

    assertNotNull(epRes);

    // In transactions EP will be invoked locally.
    Class<? extends Exception> exp = grid("client").transactions().tx() == null || ((IgniteCacheProxy)cache).context().mvccEnabled()
        ? EntryProcessorException.class
        : NonSerializableException.class;

    //noinspection ThrowableNotThrown
    assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            epRes.get();

            return null;
        }
    }, exp, null);

    if (ATOMIC_CACHE.equals(cache.getName())) {
        //noinspection ThrowableNotThrown
        assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                cache.invokeAll(Collections.singleton("1"), new UpdateValueProcessor());

                return null;
            }
        }, CachePartialUpdateException.class, null);
    }
}
 
Example #26
Source File: CacheContinuousQueryOperationFromCallbackTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object process(MutableEntry<QueryTestKey, QueryTestValue> entry, Object... arguments)
    throws EntryProcessorException {
    if (entry.exists())
        entry.setValue(new QueryTestValue(entry.getValue().val1 + 1));
    else
        entry.setValue(new QueryTestValue(0));

    return null;
}
 
Example #27
Source File: GridCacheAtomicStampedImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Void process(MutableEntry<GridCacheInternalKey, GridCacheAtomicStampedValue<T, S>> e,
    Object... args) {
    GridCacheAtomicStampedValue val = e.getValue();

    if (val == null)
        throw new EntryProcessorException("Failed to find atomic stamped with given name: " + e.getKey().name());

    e.setValue(new GridCacheAtomicStampedValue<>(newVal, newStamp));

    return null;
}
 
Example #28
Source File: BinaryMetadataRegistrationInsideEntryProcessorTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object process(
    MutableEntry<Integer, Map<Integer, CustomObj>> entry,
    Object... objects) throws EntryProcessorException {
    Map<Integer, CustomObj> map = new HashMap<>();

    map.put(1, new CustomObj(new CustomInnerObject("test"), CustomEnum.ONE));

    entry.setValue(map);

    return null;
}
 
Example #29
Source File: AtomicOperationsInTxTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object process(MutableEntry<Integer, Integer> entry, Object... objects)
    throws EntryProcessorException {
    entry.setValue(entry.getKey());

    return null;
}
 
Example #30
Source File: IgfsDataPutProcessor.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Void process(MutableEntry<IgfsBlockKey, byte[]> entry, Object... args)
    throws EntryProcessorException {
    byte[] curVal = entry.getValue();

    if (curVal == null || newVal.length > curVal.length)
        entry.setValue(newVal);

    return null;
}