Search in sources :

Example 1 with TaskSubscriptionRequest

use of io.zeebe.broker.task.processor.TaskSubscriptionRequest in project zeebe by zeebe-io.

the class AddTaskSubscriptionHandler method handle.

@Override
public void handle(final ActorControl actor, final int partitionId, final DirectBuffer buffer, final BrokerEventMetadata eventMetada) {
    final TaskSubscriptionRequest request = new TaskSubscriptionRequest();
    request.wrap(cloneBuffer(buffer));
    final long requestId = eventMetada.getRequestId();
    final int requestStreamId = eventMetada.getRequestStreamId();
    final TaskSubscription taskSubscription = new TaskSubscription(partitionId, request.getLockTaskType(), request.getLockDuration(), request.getLockOwner(), requestStreamId);
    taskSubscription.setCredits(request.getCredits());
    final ActorFuture<Void> future = manager.addSubscription(taskSubscription);
    actor.runOnCompletion(future, ((aVoid, throwable) -> {
        if (throwable == null) {
            final long subscriberKey = taskSubscription.getSubscriberKey();
            request.setSubscriberKey(subscriberKey);
            sendResponse(actor, requestStreamId, requestId, request);
        } else {
            sendErrorResponse(actor, requestStreamId, requestId, "Cannot add task subscription. %s", throwable.getMessage());
        }
    }));
}
Also used : TaskSubscriptionRequest(io.zeebe.broker.task.processor.TaskSubscriptionRequest) ActorControl(io.zeebe.util.sched.ActorControl) ActorFuture(io.zeebe.util.sched.future.ActorFuture) BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) TaskSubscriptionManager(io.zeebe.broker.task.TaskSubscriptionManager) ServerOutput(io.zeebe.transport.ServerOutput) TaskSubscriptionRequest(io.zeebe.broker.task.processor.TaskSubscriptionRequest) BufferUtil.cloneBuffer(io.zeebe.util.buffer.BufferUtil.cloneBuffer) DirectBuffer(org.agrona.DirectBuffer) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription)

Aggregations

TaskSubscriptionManager (io.zeebe.broker.task.TaskSubscriptionManager)1 TaskSubscription (io.zeebe.broker.task.processor.TaskSubscription)1 TaskSubscriptionRequest (io.zeebe.broker.task.processor.TaskSubscriptionRequest)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 BrokerEventMetadata (io.zeebe.protocol.impl.BrokerEventMetadata)1 ServerOutput (io.zeebe.transport.ServerOutput)1 BufferUtil.cloneBuffer (io.zeebe.util.buffer.BufferUtil.cloneBuffer)1 ActorControl (io.zeebe.util.sched.ActorControl)1 ActorFuture (io.zeebe.util.sched.future.ActorFuture)1 DirectBuffer (org.agrona.DirectBuffer)1