Search in sources :

Example 1 with ForwardingObserver

use of cz.o2.proxima.direct.commitlog.CommitLogObservers.ForwardingObserver in project proxima-platform by O2-Czech-Republic.

the class TransactionResourceManager method repartitionHookForBeingActive.

private CommitLogObserver repartitionHookForBeingActive(DirectAttributeFamilyDescriptor stateFamily, int numPartitions, CommitLogObserver delegate) {
    activeForFamily.putIfAbsent(stateFamily.getDesc(), new AtomicBoolean());
    return new ForwardingObserver(delegate) {

        @Override
        public boolean onNext(StreamElement ingest, OnNextContext context) {
            Preconditions.checkArgument(activeForFamily.get(stateFamily.getDesc()).get());
            if (ingest.getStamp() > System.currentTimeMillis() - 2 * transactionTimeoutMs) {
                super.onNext(ingest, context);
            } else {
                log.warn("Skipping request {} due to timeout. Current timeout specified as {}", ingest, transactionTimeoutMs);
                context.confirm();
            }
            return true;
        }

        @Override
        public void onRepartition(OnRepartitionContext context) {
            Preconditions.checkArgument(context.partitions().isEmpty() || context.partitions().size() == numPartitions, "At least all or none partitions need to be assigned to the consumer. Got %s partitions from %s", context.partitions().size(), numPartitions);
            if (!context.partitions().isEmpty()) {
                transitionToActive(stateFamily);
            } else {
                transitionToInactive(stateFamily);
            }
            super.onRepartition(context);
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ForwardingObserver(cz.o2.proxima.direct.commitlog.CommitLogObservers.ForwardingObserver) StreamElement(cz.o2.proxima.storage.StreamElement)

Aggregations

ForwardingObserver (cz.o2.proxima.direct.commitlog.CommitLogObservers.ForwardingObserver)1 StreamElement (cz.o2.proxima.storage.StreamElement)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1