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);
}
};
}
Aggregations