private Chain getChainFromOperations(List<Operation<Long, String>> operations) { ChainBuilder chainBuilder = new ChainBuilder(); for(Operation<Long, String> operation: operations) { chainBuilder = chainBuilder.add(codec.encode(operation)); } return chainBuilder.build(); }
@Test public void testCompactEmptyChain() throws Exception { Chain chain = (new ChainBuilder()).build(); EternalChainResolver<Long, String> resolver = new EternalChainResolver<>(codec); Chain compacted = resolver.applyOperation(chain, 0L); assertThat(compacted, emptyIterable()); }
public ChainBuilder add(final ByteBuffer payload) { List<ByteBuffer> newList = new ArrayList<>(buffers.size() + 1); newList.addAll(buffers); newList.add(payload); return new ChainBuilder(newList); }
@Test public void testCompactEmptyChain() throws Exception { Chain chain = (new ChainBuilder()).build(); ExpiryChainResolver<Long, String> resolver = new ExpiryChainResolver<>(codec, ExpiryPolicyBuilder.noExpiration()); Chain compacted = resolver.applyOperation(chain, 0L); assertThat(compacted, emptyIterable()); }
public ChainBuilder add(final ByteBuffer payload) { List<ByteBuffer> newList = new ArrayList<>(buffers.size() + 1); newList.addAll(buffers); newList.add(payload); return new ChainBuilder(newList); }
@SafeVarargs private final Chain getChainFromOperations(Operation<Long, String> ... operations) { ChainBuilder chainBuilder = new ChainBuilder(); for(Operation<Long, String> operation: operations) { chainBuilder = chainBuilder.add(codec.encode(operation)); } return chainBuilder.build(); }
@SafeVarargs private final Chain getChainFromOperations(Operation<Long, String> ... operations) { ChainBuilder chainBuilder = new ChainBuilder(); for(Operation<Long, String> operation: operations) { chainBuilder = chainBuilder.add(codec.encode(operation)); } return chainBuilder.build(); }
/** * Compacts the given chain by resolving every key within. * * @param chain a compacted heterogenous {@code Chain} * @param now time when the chain is being resolved * @return a compacted chain */ public Chain applyOperation(Chain chain, long now) { //absent hash-collisions this should always be a 1 entry map Map<K, PutOperation<K, V>> compacted = new HashMap<>(2); for (Element element : chain) { ByteBuffer payload = element.getPayload(); Operation<K, V> operation = codec.decode(payload); compacted.compute(operation.getKey(), (k, v) -> applyOperation(k, v, operation, now)); } ChainBuilder builder = new ChainBuilder(); for (PutOperation<K, V> operation : compacted.values()) { builder = builder.add(codec.encode(operation)); } return builder.build(); }
@Test public void testChainBuilder() { ChainBuilder cb1 = new ChainBuilder(); ChainBuilder cb2 = cb1.add(Util.createPayload(1L)) .add(Util.createPayload(3L)) .add(Util.createPayload(4L)); ChainBuilder cb3 = cb2.add(Util.createPayload(2L)); Chain chain1 = cb1.build(); Chain chain2 = cb2.build(); Chain chain3 = cb3.build(); assertChainHas(chain1); assertChainHas(chain2, 1L, 3L, 4L); assertChainHas(chain3, 1L, 3L, 4L, 2L); }
ChainBuilder newChainBuilder = new ChainBuilder(); boolean matched = false; for (Element element : chain) { } else { payload.rewind(); newChainBuilder = newChainBuilder.add(payload); Chain newChain = newChainBuilder.build(); return new ResolvedChain.Impl<>(newChain, key, null, chain.length() - newChain.length(), Long.MAX_VALUE); } else { Chain newChain = newChainBuilder.add(codec.encode(result)).build(); return new ResolvedChain.Impl<>(newChain, key, result, chain.length() - newChain.length(), result.expirationTime());
ChainBuilder builder = new ChainBuilder(); for (PutOperation<K, V> operation : currentState.values()) { builder = builder.add(codec.encode(operation)); clusteredWriteBehindStore.replaceAtHead(hash, chain, builder.build());
/** * Compacts the given chain by resolving every key within. * * @param chain a compacted heterogenous {@code Chain} * @param now time when the chain is being resolved * @return a compacted chain */ public Chain applyOperation(Chain chain, long now) { //absent hash-collisions this should always be a 1 entry map Map<K, PutOperation<K, V>> compacted = new HashMap<>(2); for (Element element : chain) { ByteBuffer payload = element.getPayload(); Operation<K, V> operation = codec.decode(payload); compacted.compute(operation.getKey(), (k, v) -> applyOperation(k, v, operation, now)); } ChainBuilder builder = new ChainBuilder(); for (PutOperation<K, V> operation : compacted.values()) { builder = builder.add(codec.encode(operation)); } return builder.build(); }
ChainBuilder newChainBuilder = new ChainBuilder(); boolean matched = false; for (Element element : chain) { } else { payload.rewind(); newChainBuilder = newChainBuilder.add(payload); Chain newChain = newChainBuilder.build(); return new ResolvedChain.Impl<>(newChain, key, null, chain.length() - newChain.length(), Long.MAX_VALUE); } else { Chain newChain = newChainBuilder.add(codec.encode(result)).build(); return new ResolvedChain.Impl<>(newChain, key, result, chain.length() - newChain.length(), result.expirationTime());