@Override public boolean isEmpty() { return wrapped.isEmpty(); }
/** * Drains all elements into the provided {@link Collection}. * * @param target the collection to drain this object's items into * @return the number of elements actually drained */ default <E> int drainTo(Collection<E> target) { int drained = 0; for (E o; (o = (E) poll()) != null; drained++) { target.add(o); } return drained; }
@Override public void process(int ordinal, @Nonnull Inbox inbox) { checkError(); inbox.drain((Object item) -> { // Note: send() method can block even though it is declared to not. This is true for Kafka 1.0 and probably // will stay so, unless they change API. producer.send(toRecordFn.apply((T) item), callback); }); }
@Override public void remove() { wrapped.remove(); }
@Override public Object peek() { return unwrapPayload(wrapped.peek()); }
@Override public void process(int ordinal, @Nonnull Inbox inbox) { inbox.drainTo(itemList); while (!itemList.isEmpty()) { if (!reconnectIfNecessary()) { continue; } try { for (T item : itemList) { bindFn.accept(statement, item); addBatchOrExecute(); } executeBatch(); connection.commit(); itemList.clear(); idleCount = 0; } catch (Exception e) { if (e instanceof SQLNonTransientException || e.getCause() instanceof SQLNonTransientException) { throw ExceptionUtil.rethrow(e); } else { logger.warning("Exception during update", e.getCause()); idleCount++; } } } }
@Override public void restoreFromSnapshot(@Nonnull Inbox inbox) { inbox.drain(DistributedConsumer.noop()); } }
@Override public void process(int ordinal, @Nonnull Inbox inbox) { checkError(); inbox.drain((Object item) -> { // Note: send() method can block even though it is declared to not. This is true for Kafka 1.0 and probably // will stay so, unless they change API. producer.send(toRecordFn.apply((T) item), callback); }); }
/** * Passes each of this object's items to the supplied consumer until it is empty. * * @return the number of elements drained */ default <E> int drain(Consumer<E> consumer) { int consumed = 0; for (E o; (o = (E) poll()) != null; consumed++) { consumer.accept(o); } return consumed; } }
@Override public void process(int ordinal, @Nonnull Inbox inbox) { inbox.drain(DistributedConsumer.noop()); }
/** * Implements the boilerplate of polling the inbox, casting the items to * {@code Map.Entry}, and extracting the key and value. Forwards each * key-value pair to {@link #restoreFromSnapshot(Object, Object)}. */ @Override public final void restoreFromSnapshot(@Nonnull Inbox inbox) { for (Map.Entry entry; (entry = (Map.Entry) inbox.poll()) != null; ) { restoreFromSnapshot(entry.getKey(), entry.getValue()); } }
@Override public void process(int ordinal, @Nonnull Inbox inbox) { inbox.drain(item -> onReceiveFn.accept(buffer, (T) item)); flushFn.accept(buffer); }
@Override public Object poll() { return unwrapPayload(wrapped.poll()); }