Search in sources :

Example 1 with ActorControl

use of io.zeebe.util.sched.ActorControl 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)

Example 2 with ActorControl

use of io.zeebe.util.sched.ActorControl in project zeebe by zeebe-io.

the class RemoveTopicSubscriptionHandler method handle.

@Override
public void handle(final ActorControl actor, final int partitionId, final DirectBuffer buffer, final BrokerEventMetadata metadata) {
    final int requestStreamId = metadata.getRequestStreamId();
    final long requestId = metadata.getRequestId();
    final CloseSubscriptionRequest request = new CloseSubscriptionRequest();
    request.wrap(cloneBuffer(buffer));
    final ActorFuture<Void> future = subscriptionService.closeSubscriptionAsync(partitionId, request.getSubscriberKey());
    actor.runOnCompletion(future, ((aVoid, throwable) -> {
        if (throwable == null) {
            sendResponse(actor, requestStreamId, requestId, request);
        } else {
            sendErrorResponse(actor, requestStreamId, requestId, "Cannot close topic subscription. %s", throwable.getMessage());
        }
    }));
}
Also used : AbstractControlMessageHandler(io.zeebe.broker.transport.controlmessage.AbstractControlMessageHandler) ActorControl(io.zeebe.util.sched.ActorControl) ActorFuture(io.zeebe.util.sched.future.ActorFuture) BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata) TopicSubscriptionService(io.zeebe.broker.event.processor.TopicSubscriptionService) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) ServerOutput(io.zeebe.transport.ServerOutput) BufferUtil.cloneBuffer(io.zeebe.util.buffer.BufferUtil.cloneBuffer) CloseSubscriptionRequest(io.zeebe.broker.event.processor.CloseSubscriptionRequest) DirectBuffer(org.agrona.DirectBuffer) CloseSubscriptionRequest(io.zeebe.broker.event.processor.CloseSubscriptionRequest)

Aggregations

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