/** {@inheritDoc} */ @Override public Cache.Entry<K, V> next() { try { List<?> row = iter.next(); return new CacheEntryImpl<>((K)row.get(0), (V)row.get(1)); } catch (CacheException e) { throw e; } catch (Exception e) { throw new CacheException(e); } }
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); ver = (GridCacheVersion)in.readObject(); }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); out.writeObject(ver); }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); out.writeObject(ver); }
/** {@inheritDoc} */ @Override public <T> T unwrap(Class<T> cls) { if (cls != null && cls.isAssignableFrom(getClass())) return cls.cast(this); if (cls.isAssignableFrom(CacheEntryImpl.class)) return (T)new CacheEntryImpl<>(getKey(), getValue()); if (cls.isAssignableFrom(CacheEntry.class)) return (T)new CacheEntryImplEx<>(getKey(), getValue(), null); throw new IllegalArgumentException("Unwrapping to class is not supported: " + cls); } }
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); ver = (GridCacheVersion)in.readObject(); }
/** {@inheritDoc} */ @Override public Iterator<Cache.Entry<?, ?>> query(@Nullable String cacheName, Collection<Object> params, @Nullable IndexingQueryFilter filters) { return idx.containsKey(GridIoPolicy.QUERY_POOL) ? Collections.<Cache.Entry<?, ?>>singletonList( new CacheEntryImpl<>(GridIoPolicy.QUERY_POOL, GridIoPolicy.QUERY_POOL)).iterator() : Collections.<Cache.Entry<?, ?>>emptyList().iterator(); }
/** * @param key Key. * @return Previous value. * @throws IgniteCheckedException If failed. */ protected V getAndRemove0(final K key) throws IgniteCheckedException { final boolean keepBinary = ctx.keepBinary(); return syncOp(new SyncOp<V>(true) { @Override public V op(GridNearTxLocal tx) throws IgniteCheckedException { K key0 = keepBinary ? (K)ctx.toCacheKeyObject(key) : key; IgniteInternalFuture<GridCacheReturn> fut = tx.removeAllAsync(ctx, null, Collections.singletonList(key0), /*retval*/true, null, /*singleRmv*/false); V ret = fut.get().value(); if (ctx.config().getInterceptor() != null) { K key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key0, true, false) : key0; return (V)ctx.config().getInterceptor().onBeforeRemove(new CacheEntryImpl(key, ret)).get2(); } return ret; } @Override public String toString() { return S.toString("remove", "key", key, true); } }); }
@Override public void run() { try { while (running.get()) { for (int i = 0; i < CACHE_SIZE; i++) { store.write(new CacheEntryImpl<>(i, "val-0")); store.write(new CacheEntryImpl<>(i, "val" + i)); } } } catch (Exception e) { error("Unexpected exception in put thread", e); assert false; } } }, 1, "put");
@Override public void run() { try { while (running.get()) { for (int i = 0; i < CACHE_SIZE; i++) { store.write(new CacheEntryImpl<>(i, "val-0")); actualPutCnt.incrementAndGet(); store.write(new CacheEntryImpl<>(i, "val" + i)); actualPutCnt.incrementAndGet(); } } } catch (Exception e) { error("Unexpected exception in put thread", e); assert false; } } }, 1, "put");
/** {@inheritDoc} */ @Override public Iterator<Cache.Entry<?, ?>> query(@Nullable String cacheName, Collection<Object> params, @Nullable IndexingQueryFilter filters) throws IgniteSpiException { if (params.size() < 2) throw new IgniteSpiException("Range parameters required."); Iterator<Object> paramsIt = params.iterator(); Object from = paramsIt.next(); Object to = paramsIt.next(); from = from instanceof BinaryObject ? ((BinaryObject)from).deserialize() : from; to = to instanceof BinaryObject ? ((BinaryObject)to).deserialize() : to; SortedMap<Object, Object> map = idx.subMap(from, to); Collection<Cache.Entry<?, ?>> res = new ArrayList<>(map.size()); for (Map.Entry<Object, Object> entry : map.entrySet()) res.add(new CacheEntryImpl<>(entry.getKey(), entry.getValue())); return res.iterator(); }
/** * @param entry Internal entry. * @param deserializeBinary Deserialize binary flag. * @return Public API entry. * @throws IgniteCheckedException If failed. * @throws GridCacheEntryRemovedException If entry removed. */ @Nullable private Cache.Entry<K, V> toCacheEntry(GridCacheEntryEx entry, boolean deserializeBinary) throws IgniteCheckedException, GridCacheEntryRemovedException { CacheObject val = entry.innerGet( /*ver*/null, /*tx*/null, /*readThrough*/false, /*metrics*/false, /*evt*/false, /*subjId*/null, /*transformClo*/null, /*taskName*/null, /*expiryPlc*/null, !deserializeBinary); if (val == null) return null; KeyCacheObject key = entry.key(); Object key0 = ctx.unwrapBinaryIfNeeded(key, !deserializeBinary, true); Object val0 = ctx.unwrapBinaryIfNeeded(val, !deserializeBinary, true); return new CacheEntryImpl<>((K)key0, (V)val0, entry.version()); }
store.write(new CacheEntryImpl<>(key, "val" + key)); set.add(key); store.write(new CacheEntryImpl<>(key, "broken")); store.write(new CacheEntryImpl<>(key, "val" + key));
/** {@inheritDoc} */ @Override public Iterable<Entry<K, V>> call() throws Exception { Collection<Entry<K, V>> res = new ArrayList<>(); for (Entry<K, V> e : cache().localEntries(peekModes)) res.add(new CacheEntryImpl<>(e.getKey(), e.getValue())); return res; } }
store.write(new CacheEntryImpl<>(key, val)); else { Collection<Cache.Entry<? extends Object, ? extends Object>> col = new ArrayList<>(); col.add(new CacheEntryImpl<>(key, val)); store.write(new CacheEntryImpl<>(key, key)); else { Collection<Cache.Entry<? extends Object, ? extends Object>> col = new ArrayList<>(); col.add(new CacheEntryImpl<>(key, key));
@Override public void run() { try { delegate.setShouldFail(true); initStore(2, writeCoalescing); try { store.write(new CacheEntryImpl<>(1, "val1")); store.write(new CacheEntryImpl<>(2, "val2")); } finally { shutdownStore(); delegate.setShouldFail(false); } } catch (Exception e) { err.set(e); } } }, 1).get();
store.write(new CacheEntryImpl<>(i, "val" + i));
/** * @throws Exception If failed. */ @Test public void testTimestamp() throws Exception { Timestamp k = new Timestamp(System.currentTimeMillis()); ses.newSession(null); Integer v = 5; store.write(new CacheEntryImpl<>(k, v)); assertEquals(v, store.load(k)); store.delete(k); assertNull(store.load(k)); }