Search in sources :

Example 1 with LockTaskStreamProcessor

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);
                }
            });
        }
    });
}
Also used : LockTaskStreamProcessor(io.zeebe.broker.task.processor.LockTaskStreamProcessor)

Example 2 with LockTaskStreamProcessor

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;
}
Also used : CompletableActorFuture(io.zeebe.util.sched.future.CompletableActorFuture) LockTaskStreamProcessor(io.zeebe.broker.task.processor.LockTaskStreamProcessor)

Example 3 with LockTaskStreamProcessor

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;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) StreamProcessorService(io.zeebe.broker.logstreams.processor.StreamProcessorService) TransportListener(io.zeebe.transport.TransportListener) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription) LogStream(io.zeebe.logstreams.log.LogStream) ArrayList(java.util.ArrayList) LockTaskStreamProcessor(io.zeebe.broker.task.processor.LockTaskStreamProcessor) RemoteAddress(io.zeebe.transport.RemoteAddress) Long2ObjectHashMap(org.agrona.collections.Long2ObjectHashMap) HeapBufferAllocator(io.zeebe.util.allocation.HeapBufferAllocator) CompletableActorFuture(io.zeebe.util.sched.future.CompletableActorFuture) TypedStreamProcessor(io.zeebe.broker.logstreams.processor.TypedStreamProcessor) ServiceName(io.zeebe.servicecontainer.ServiceName) StreamProcessorController(io.zeebe.logstreams.processor.StreamProcessorController) CompactList(io.zeebe.util.collection.CompactList) Iterator(java.util.Iterator) Int2ObjectHashMap(org.agrona.collections.Int2ObjectHashMap) Set(java.util.Set) ServerTransport(io.zeebe.transport.ServerTransport) TASK_LOCK_STREAM_PROCESSOR_ID(io.zeebe.broker.logstreams.processor.StreamProcessorIds.TASK_LOCK_STREAM_PROCESSOR_ID) TaskQueueServiceNames.taskQueueLockStreamProcessorServiceName(io.zeebe.broker.task.TaskQueueServiceNames.taskQueueLockStreamProcessorServiceName) ActorFuture(io.zeebe.util.sched.future.ActorFuture) List(java.util.List) TypedStreamEnvironment(io.zeebe.broker.logstreams.processor.TypedStreamEnvironment) Actor(io.zeebe.util.sched.Actor) ServiceStartContext(io.zeebe.servicecontainer.ServiceStartContext) BufferUtil(io.zeebe.util.buffer.BufferUtil) BufferUtil.bufferAsString(io.zeebe.util.buffer.BufferUtil.bufferAsString) SNAPSHOT_STORAGE_SERVICE(io.zeebe.broker.logstreams.LogStreamServiceNames.SNAPSHOT_STORAGE_SERVICE) Entry(java.util.Map.Entry) Loggers(io.zeebe.broker.Loggers) DirectBuffer(org.agrona.DirectBuffer) CompletableActorFuture(io.zeebe.util.sched.future.CompletableActorFuture) LockTaskStreamProcessor(io.zeebe.broker.task.processor.LockTaskStreamProcessor)

Aggregations

LockTaskStreamProcessor (io.zeebe.broker.task.processor.LockTaskStreamProcessor)3 CompletableActorFuture (io.zeebe.util.sched.future.CompletableActorFuture)2 Loggers (io.zeebe.broker.Loggers)1 SNAPSHOT_STORAGE_SERVICE (io.zeebe.broker.logstreams.LogStreamServiceNames.SNAPSHOT_STORAGE_SERVICE)1 TASK_LOCK_STREAM_PROCESSOR_ID (io.zeebe.broker.logstreams.processor.StreamProcessorIds.TASK_LOCK_STREAM_PROCESSOR_ID)1 StreamProcessorService (io.zeebe.broker.logstreams.processor.StreamProcessorService)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1 TypedStreamProcessor (io.zeebe.broker.logstreams.processor.TypedStreamProcessor)1 TaskQueueServiceNames.taskQueueLockStreamProcessorServiceName (io.zeebe.broker.task.TaskQueueServiceNames.taskQueueLockStreamProcessorServiceName)1 TaskSubscription (io.zeebe.broker.task.processor.TaskSubscription)1 LogStream (io.zeebe.logstreams.log.LogStream)1 StreamProcessorController (io.zeebe.logstreams.processor.StreamProcessorController)1 ServiceName (io.zeebe.servicecontainer.ServiceName)1 ServiceStartContext (io.zeebe.servicecontainer.ServiceStartContext)1 RemoteAddress (io.zeebe.transport.RemoteAddress)1 ServerTransport (io.zeebe.transport.ServerTransport)1 TransportListener (io.zeebe.transport.TransportListener)1 HeapBufferAllocator (io.zeebe.util.allocation.HeapBufferAllocator)1 BufferUtil (io.zeebe.util.buffer.BufferUtil)1 BufferUtil.bufferAsString (io.zeebe.util.buffer.BufferUtil.bufferAsString)1