javax.cache.processor.MutableEntry Java Examples

The following examples show how to use javax.cache.processor.MutableEntry. 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: 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 #2
Source File: GridCacheAtomicReferenceImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Boolean process(MutableEntry<GridCacheInternalKey, GridCacheAtomicReferenceValue<T>> e,
    Object... args) {
    GridCacheAtomicReferenceValue<T> val = e.getValue();

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

    T curVal = val.get();

    if (F.eq(expVal, curVal)) {
        e.setValue(new GridCacheAtomicReferenceValue<T>(newVal));

        return true;
    }

    return false;
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
Source File: IgniteTxConfigCacheSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #8
Source File: PlatformCacheEntryProcessorImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Writes mutable entry and entry processor to the stream.
 *
 * @param entry Entry to process.
 * @param writer Writer.
 */
private void writeEntryAndProcessor(MutableEntry entry, BinaryRawWriter writer) {
    if (ptr != 0) {
        // Execute locally - we have a pointer to native processor.
        writer.writeBoolean(true);
        writer.writeLong(ptr);
    }
    else {
        // We are on a remote node. Send processor holder back to native.
        writer.writeBoolean(false);
        writer.writeObject(proc);
    }

    writer.writeObject(entry.getKey());
    writer.writeObject(entry.getValue());
}
 
Example #9
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 #10
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 #11
Source File: IgnteCacheClientWriteBehindStoreNonCoalescingTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #12
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 #13
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 #14
Source File: IgfsMetaDirectoryListingAddProcessor.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) {
    IgfsEntryInfo fileInfo = e.getValue();

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

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

    // Modify listing in-place.
    IgfsListingEntry oldEntry = listing.put(fileName, entry);

    if (oldEntry != null && !oldEntry.fileId().equals(entry.fileId())) {
        throw new IgniteException("Directory listing contains unexpected file" +
            " [listing=" + listing + ", fileName=" + fileName + ", entry=" + entry +
            ", oldEntry=" + oldEntry + ']');
    }

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

    return null;
}
 
Example #15
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 #16
Source File: IgniteCacheInvokeAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer process(MutableEntry<Integer, Integer> e,
    Object... arguments) throws EntryProcessorException {
    assertTrue(e.exists());

    if (expVal != null)
        assertEquals(expVal, e.getValue());

    throw new EntryProcessorException("Test processor exception.");
}
 
Example #17
Source File: CombineEntryProcessor.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] process(MutableEntry<K, V> entry, Object... arguments) {
    Object[] results = new Object[processors.length];

    for (int i = 0; i < processors.length; i++) {
        results[i] = processors[i].process(entry, arguments);
    }
    return results;
}
 
Example #18
Source File: GridCacheAtomicLongImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Long process(MutableEntry<GridCacheInternalKey, GridCacheAtomicLongValue> e, Object... args) {
    GridCacheAtomicLongValue val = e.getValue();

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

    long curVal = val.get();

    if (curVal == expVal)
        e.setValue(new GridCacheAtomicLongValue(newVal));

    return curVal;
}
 
Example #19
Source File: CombineEntryProcessor.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] process(MutableEntry<K, V> entry, Object... arguments) {
    Object[] results = new Object[processors.length];

    for (int i = 0; i < processors.length; i++) {
        results[i] = processors[i].process(entry, arguments);
    }
    return results;
}
 
Example #20
Source File: InitStateProcessor.java    From bucket4j with Apache License 2.0 5 votes vote down vote up
@Override
public CommandResult<Nothing> process(MutableEntry<K, GridBucketState> mutableEntry, Object... arguments) {
    if (mutableEntry.exists()) {
        return CommandResult.success(null);
    }
    long currentTimeNanos = currentTimeNanos();
    BucketState bucketState = BucketState.createInitialState(configuration, currentTimeNanos);
    GridBucketState gridBucketState = new GridBucketState(configuration, bucketState);
    mutableEntry.setValue(gridBucketState);
    return CommandResult.success(null);
}
 
Example #21
Source File: IgniteCacheCrossCacheTxFailoverTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public TestValue process(MutableEntry<TestKey, TestValue> e, Object... args) {
    TestValue old = e.getValue();

    if (val != null)
        e.setValue(new TestValue(val));

    return old;
}
 
Example #22
Source File: IntBytesICacheCircuitBreakerTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException {
    try {
        Thread.sleep(stallTime);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(e);
    }

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

    if (expVal != null)
        assertEquals(expVal, e.getValue());

    e.remove();

    assertFalse(e.exists());

    return null;
}
 
Example #24
Source File: IgniteCachePutRetryAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer process(MutableEntry<Integer, Integer> e, Object... args) {
    Integer old = e.getValue();

    e.setValue(val);

    return old == null ? 0 : old;
}
 
Example #25
Source File: TransformingCacheProxy.java    From cache2k with Apache License 2.0 5 votes vote down vote up
private MutableEntry<K, V> wrapMutableEntry(final MutableEntry<K0, V0> entry) {
  return new MutableEntry<K, V>() {
    @Override
    public boolean exists() {
      return entry.exists();
    }

    @Override
    public void remove() {
      entry.remove();
    }

    @Override
    public void setValue(V value) {
      entry.setValue(valueTransformer.compact(value));
    }

    @Override
    public K getKey() {
      return keyTransformer.expand(entry.getKey());
    }

    @Override
    public V getValue() {
      return valueTransformer.expand(entry.getValue());
    }

    @Override
    public <T> T unwrap(Class<T> clazz) {
      return entry.unwrap(clazz);
    }
  };
}
 
Example #26
Source File: CrossCacheTxRandomOperationsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public TestValue process(MutableEntry<TestKey, TestValue> e, Object... args) {
    TestValue old = e.getValue();

    if (val != null)
        e.setValue(new TestValue(val));

    return old;
}
 
Example #27
Source File: MultiArgumentHandlingEntryProcessor.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Override
public T process(MutableEntry<K, V> entry, Object... arguments) {
    Assert.assertEquals("These", arguments[0]);
    Assert.assertEquals("are", arguments[1]);
    Assert.assertEquals("arguments", arguments[2]);
    Assert.assertEquals(1L, arguments[3]);

    return ret;
}
 
Example #28
Source File: CacheDeploymentBinaryEntryProcessor.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Boolean process(MutableEntry<String, String> entry, Object... arguments)
    throws EntryProcessorException {
    String val = entry.getKey();

    return true;
}
 
Example #29
Source File: EntryProcessorICacheTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public Object process(MutableEntry<Integer, Long> entry, Object... arguments) {
    if (delayMs > 0) {
        sleepMillis(delayMs);
    }
    long newValue = entry.getValue() + increment;
    entry.setValue(newValue);
    return null;
}
 
Example #30
Source File: CacheDeploymentBinaryObjectEntryProcessor.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Boolean process(MutableEntry<String, BinaryObject> entry,
    Object... arguments) throws EntryProcessorException {
    BinaryObject val = entry.getValue();

    return true;
}