use of io.zeebe.broker.task.processor.LockTaskStreamProcessor in project zeebe by zeebe-io.
the class TaskSubscriptionManager method onClientChannelCloseAsync.
public void onClientChannelCloseAsync(int channelId) {
actor.call(() -> {
final Iterator<LockTaskStreamProcessor> processorIt = streamProcessorBySubscriptionId.values().iterator();
while (processorIt.hasNext()) {
final LockTaskStreamProcessor processor = processorIt.next();
final ActorFuture<Boolean> closeFuture = processor.onClientChannelCloseAsync(channelId);
actor.runOnCompletion(closeFuture, (hasSubscriptions, throwable) -> {
if (throwable == null) {
if (!hasSubscriptions) {
removeStreamProcessorService(processor);
}
} else {
Loggers.SYSTEM_LOGGER.debug("Problem on closing LockTaskStreamProcessor.", throwable);
}
});
}
});
}
use of io.zeebe.broker.task.processor.LockTaskStreamProcessor in project zeebe by zeebe-io.
the class TaskSubscriptionManager method removeSubscription.
public ActorFuture<Void> removeSubscription(long subscriptionId) {
final CompletableActorFuture<Void> future = new CompletableActorFuture<>();
actor.call(() -> {
final LockTaskStreamProcessor streamProcessor = streamProcessorBySubscriptionId.remove(subscriptionId);
if (streamProcessor != null) {
final ActorFuture<Boolean> removeFuture = streamProcessor.removeSubscription(subscriptionId);
actor.runOnCompletion(removeFuture, (hasSubscriptions, throwable) -> {
if (throwable == null) {
if (!hasSubscriptions) {
final ActorFuture<Void> removeProcessorFuture = removeStreamProcessorService(streamProcessor);
actor.runOnCompletion(removeProcessorFuture, (b, t) -> {
if (t == null) {
future.complete(null);
} else {
future.completeExceptionally(t);
}
});
} else {
future.complete(null);
}
} else {
future.completeExceptionally(throwable);
}
});
} else {
future.complete(null);
}
});
return future;
}
use of io.zeebe.broker.task.processor.LockTaskStreamProcessor in project zeebe by zeebe-io.
the class TaskSubscriptionManager method addSubscription.
public ActorFuture<Void> addSubscription(final TaskSubscription subscription) {
final CompletableActorFuture<Void> future = new CompletableActorFuture<>();
actor.call(() -> {
final DirectBuffer taskType = subscription.getLockTaskType();
final int partitionId = subscription.getPartitionId();
final LogStreamBucket logStreamBucket = logStreamBuckets.get(partitionId);
if (logStreamBucket == null) {
future.completeExceptionally(new RuntimeException(String.format("Partition with id '%d' not found.", partitionId)));
return;
}
final long subscriptionId = nextSubscriptionId++;
subscription.setSubscriberKey(subscriptionId);
final LockTaskStreamProcessor streamProcessor = logStreamBucket.getStreamProcessorByTaskType(taskType);
if (streamProcessor != null) {
streamProcessorBySubscriptionId.put(subscriptionId, streamProcessor);
final ActorFuture<Void> addFuture = streamProcessor.addSubscription(subscription);
actor.runOnCompletion(addFuture, (aVoid, throwable) -> {
if (throwable == null) {
actor.submit(this::handleCreditRequests);
future.complete(null);
} else {
future.completeExceptionally(throwable);
}
});
} else {
final LockTaskStreamProcessor processor = new LockTaskStreamProcessor(taskType);
final ActorFuture<Void> processorFuture = createStreamProcessorService(processor, taskType, logStreamBucket, taskType);
actor.runOnCompletion(processorFuture, (v, t) -> {
if (t == null) {
streamProcessorBySubscriptionId.put(subscriptionId, processor);
logStreamBucket.addStreamProcessor(processor);
final ActorFuture<Void> addFuture = processor.addSubscription(subscription);
actor.runOnCompletion(addFuture, ((aVoid, throwable) -> {
if (throwable == null) {
actor.submit(this::handleCreditRequests);
future.complete(null);
} else {
future.completeExceptionally(throwable);
}
}));
} else {
future.completeExceptionally(t);
}
});
}
});
return future;
}
Aggregations