Java Code Examples for javax.cache.processor.MutableEntry#getKey()

The following examples show how to use javax.cache.processor.MutableEntry#getKey() . 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: 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 3
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 4
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 5
Source File: GridCacheReturnValueTransferSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Void process(MutableEntry<Integer, TestObject> entry, Object... args) {
    if (entry.getKey() < 100)
        assertNotNull(entry.getValue());
    else
        assertNull(entry.getValue());

    return null;
}
 
Example 6
Source File: IncludeSensitiveAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object process(MutableEntry<Long, String> entry, Object... args) {
    long key = entry.getKey();

    if (key % 2 == 0)
        entry.remove();
    else
        entry.setValue(entry.getValue() + "-");

    return null;
}
 
Example 7
Source File: GridCacheRebalancingOrderingTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public Result process(MutableEntry<IntegerKey, Integer> entry, Object... objects) {
    try {
        Ignite ignite = entry.unwrap(Ignite.class);

        PartitionObserver observer = ignite.services().service(PartitionObserver.class.getName());

        assertNotNull(observer);

        IgniteCache<IntegerKey, Integer> cache = ignite.cache(TEST_CACHE_NAME);

        Affinity<IntegerKey> affinity = ignite.affinity(TEST_CACHE_NAME);

        Set<IntegerKey> exp = this.keys;

        Set<IntegerKey> missing = getMissingKeys(cache, exp);

        IntegerKey key = entry.getKey();

        int part = affinity.partition(key);

        String ownership = affinity.isPrimary(ignite.cluster().localNode(), key) ? "primary" : "backup";

        // Wait for the local listener to sync past events.
        if (!observer.getIgniteLocalSyncListener().isSynced()) {
            ignite.log().info("Retrying validation for " + ownership + " partition " + part
                    + " due to initial sync");

            return Result.RETRY;
        }

        // Determine if the partition is being loaded and wait for it to load completely.
        if (observer.getLoadingMap().containsKey(part)) {
            ignite.log().info("Retrying validation due to forming partition [ownership=" + ownership +
                ", partition=" + part +
                ", expKeys=" + exp +
                ", loadedKeys=" + observer.getLoadingMap().get(part) +
                ", missingLocalKeys=" + missing + ']');

            return Result.RETRY;
        }

        if (!observer.getPartitionMap().containsKey(part)) {
            ignite.log().info("Retrying validation due to newly arrived partition [ownership=" + ownership +
                ", partition=" + part +
                ", missingLocalKeys=" + missing + ']');

            return Result.RETRY;
        }

        // Validate the key count.
        Set<IntegerKey> curr = observer.ensureKeySet(part);

        if (curr.equals(exp) && missing.isEmpty())
            return Result.OK;

        String msg = String.format("For %s partition %s:\n\texpected  %s,\n\t" +
            "but found %s;\n\tmissing local keys: %s",
            ownership, part, new TreeSet<>(exp), new TreeSet<>(curr), new TreeSet<>(missing));

        ignite.log().info(">>> " + msg);

        throw new EntryProcessorException(msg);
    }
    catch (NullPointerException e) {
        e.printStackTrace();

        throw e;
    }
}
 
Example 8
Source File: GetKeyEntryProcessor.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
@Override
public Integer process(MutableEntry<Integer, String> entry, Object... arguments) {
    return entry.getKey();
}
 
Example 9
Source File: TouchyJCacheAdapter.java    From cache2k with Apache License 2.0 4 votes vote down vote up
private <T> javax.cache.processor.EntryProcessor<K,V,T> wrapEntryProcessor(final javax.cache.processor.EntryProcessor<K,V,T> ep) {
  if (ep == null) {
    throw new NullPointerException("processor is null");
  }
  return new javax.cache.processor.EntryProcessor<K,V, T>() {
    boolean freshOrJustLoaded = false;
    @Override
    public T process(final MutableEntry<K, V> e0, Object... _args) throws EntryProcessorException {
      MutableEntry<K, V> me = new MutableEntry<K, V>() {

        @Override
        public boolean exists() {
          return e0.exists();
        }

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

        @Override
        public void setValue(V value) {
          checkNullValue(value);
          freshOrJustLoaded = true;
          e0.setValue(value);
        }

        @Override
        public K getKey() {
          return e0.getKey();
        }

        @Override
        public V getValue() {
          boolean _doNotCountCacheAccessIfEntryGetsLoaded = !exists();
          boolean _doNotCountCacheAccessIfEntryIsFresh = freshOrJustLoaded;
          if (_doNotCountCacheAccessIfEntryIsFresh || _doNotCountCacheAccessIfEntryGetsLoaded) {
            if (!cache.readThrough && !exists()) {
              return null;
            }
            freshOrJustLoaded = true;
            return e0.getValue();
          }
          return returnValue(e0.getKey(), e0.getValue());
        }

        @Override
        public <X> X unwrap(Class<X> clazz) {
          return null;
        }
      };
      return ep.process(me, _args);
    }
  };
}