/** {@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(); e.setValue(new GridCacheAtomicLongValue(newVal)); return curVal; }
@Override public T2<GridCacheAtomicLongEx, AtomicDataStructureValue> get(GridCacheInternalKey key, AtomicDataStructureValue val, IgniteInternalCache cache) throws IgniteCheckedException { // Check that atomic long hasn't been created in other thread yet. GridCacheAtomicLongEx a = cast(dsMap.get(key), GridCacheAtomicLongEx.class); if (a != null) { assert val != null; return new T2<>(a, null); } if (val == null && !create) return null; GridCacheAtomicLongValue retVal = (val == null ? new GridCacheAtomicLongValue(initVal) : null); a = new GridCacheAtomicLongImpl(name, key, cache); return new T2<GridCacheAtomicLongEx, AtomicDataStructureValue>(a, retVal); } }, cfg, name, ATOMIC_LONG, create, GridCacheAtomicLongEx.class);
/** * Test {@link GridCacheInternalKey}/{@link GridCacheAtomicLongValue}. * @param name Name. * @throws Exception If failed. */ private void checkCustom(String name) throws Exception { for (int i = INIT_GRID_NUM; i < 20; i++) { startGrid(i); assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode(); try (Transaction tx = grid(i).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { GridCacheInternalKey key = new GridCacheInternalKeyImpl(name, "testGroup"); GridCacheAtomicLongValue atomicVal = ((GridCacheAtomicLongValue) grid(i).cache(DEFAULT_CACHE_NAME).get(key)); assertNotNull(atomicVal); assertEquals("Custom check failed for node: " + i, (long) i, atomicVal.get()); atomicVal.set(i + 1); grid(i).cache(DEFAULT_CACHE_NAME).put(key, atomicVal); tx.commit(); } stopGrid(i); } }
/** {@inheritDoc} */ @Override public long get() { checkRemoved(); try { GridCacheAtomicLongValue val = cacheView.get(key); if (val == null) throw new IgniteException("Failed to find atomic long: " + name); return val.get(); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
((IgniteKernal)grid(0)).getCache(cacheName).getAndPut(new GridCacheInternalKeyImpl("LONG", ""), new GridCacheAtomicLongValue(0));
/** {@inheritDoc} */ @Override public long get() { checkRemoved(); try { GridCacheAtomicLongValue val = cacheView.get(key); if (val == null) throw new IgniteException("Failed to find atomic long: " + name); return val.get(); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@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 newVal = val.get() + delta; e.setValue(new GridCacheAtomicLongValue(newVal)); return newVal; }
/** * Prepare test environment. * @param key Key. * @throws Exception If failed. */ private void prepareCustom(String key) throws Exception { // Start nodes. for (int i = 0; i < INIT_GRID_NUM; i++) assert startGrid(i) != null; for (int i = 0; i < INIT_GRID_NUM; i++) assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode(); // Init cache data. try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { // Put custom data grid(0).cache(DEFAULT_CACHE_NAME).put(new GridCacheInternalKeyImpl(key, "testGroup"), new GridCacheAtomicLongValue(INIT_GRID_NUM)); tx.commit(); } stopGrid(0); }
/** {@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 newVal = val.get() + 1; e.setValue(new GridCacheAtomicLongValue(newVal)); return newVal; }
@Override public T2<GridCacheAtomicLongEx, AtomicDataStructureValue> get(GridCacheInternalKey key, AtomicDataStructureValue val, IgniteInternalCache cache) throws IgniteCheckedException { // Check that atomic long hasn't been created in other thread yet. GridCacheAtomicLongEx a = cast(dsMap.get(key), GridCacheAtomicLongEx.class); if (a != null) { assert val != null; return new T2<>(a, null); } if (val == null && !create) return null; GridCacheAtomicLongValue retVal = (val == null ? new GridCacheAtomicLongValue(initVal) : null); a = new GridCacheAtomicLongImpl(name, key, cache); return new T2<GridCacheAtomicLongEx, AtomicDataStructureValue>(a, retVal); } }, cfg, name, ATOMIC_LONG, create, GridCacheAtomicLongEx.class);
/** {@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 newVal = val.get() - 1; e.setValue(new GridCacheAtomicLongValue(newVal)); return newVal; }
/** {@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(); e.setValue(new GridCacheAtomicLongValue(curVal + delta)); return curVal; }
/** {@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; }
/** {@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 ret = val.get(); e.setValue(new GridCacheAtomicLongValue(ret + 1)); return ret; }
/** {@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 ret = val.get(); e.setValue(new GridCacheAtomicLongValue(ret - 1)); return ret; }
/** {@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 ret = val.get(); e.setValue(new GridCacheAtomicLongValue(ret + 1)); return ret; }
/** {@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 newVal = val.get() - 1; e.setValue(new GridCacheAtomicLongValue(newVal)); return newVal; }
/** {@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(); e.setValue(new GridCacheAtomicLongValue(newVal)); return curVal; }
/** {@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 newVal = val.get() + 1; e.setValue(new GridCacheAtomicLongValue(newVal)); return newVal; }
/** {@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 newVal = val.get() + delta; e.setValue(new GridCacheAtomicLongValue(newVal)); return newVal; }