@Override protected <E> CacheStream<E> createStream(CacheCollection<E> entries) { return entries.stream(); }
@Override protected <E> CacheStream<E> createStream(CacheCollection<E> entries) { // This forces parallel distribution since iterator defaults to sequential return entries.stream().parallelDistribution(); } }
@Override protected <E> CacheStream<E> createStream(CacheCollection<E> entries) { return entries.stream().sequentialDistribution(); } }
@Override protected <E> CacheStream<E> createStream(CacheCollection<E> entries) { return entries.stream().sequentialDistribution().disableRehashAware(); } }
@Override protected <E> CacheStream<E> createStream(CacheCollection<E> entries) { return entries.stream().disableRehashAware().parallelDistribution(); } }
@Override public Object call() throws Exception { Cache<Integer, SpotPrice> cache = getCache(); String action = getParam(ACTION_PARAM); if (action.equals(AVG_PRICE)) { String ticker = getParam(TICKER_PARAM); return cache.values().stream() .filter(byTicker(ticker)) .mapToDouble(SpotPrice::getPriceUSD) .average().orElseThrow(() -> new IllegalStateException("Cannot calculate average")); } if (action.equals(TOP_PRICE_ACTION)) { String ticker = getParam(TICKER_PARAM); return cache.values().stream() .filter(byTicker(ticker)) .sorted(comparing(SpotPrice::getPriceUSD)) .collect(Collectors.toList()); } throw new IllegalStateException("Invalid or missing 'action' param"); }
@Test public void testValuesStreamRemove() { Map<Object, String> values = putValuesInCache(); final Cache<Object, Object> cache = cache(0, CACHE_NAME); cache.getAdvancedCache().addInterceptor(new BaseCustomInterceptor() { @Override public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable { assertTrue(command.hasAnyFlag(FlagBitSets.SKIP_CACHE_STORE)); return super.visitRemoveCommand(ctx, command); } }, 0); Iterator<Object> it = cache(0, CACHE_NAME).getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE) .values() .stream() .iterator(); assertTrue(it.hasNext()); assertTrue(values.containsValue(it.next())); // We don't support remove on stream iterator Exceptions.expectException(UnsupportedOperationException.class, it::remove); }