Search in sources :

Example 11 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class WorkflowInstanceStreamProcessor method getCurrentActivity.

protected <T extends FlowElement> T getCurrentActivity() {
    final long workflowKey = workflowInstanceEvent.getWorkflowKey();
    final DeployedWorkflow deployedWorkflow = workflowDeploymentCache.getWorkflow(workflowKey);
    if (deployedWorkflow != null) {
        final DirectBuffer currentActivityId = workflowInstanceEvent.getActivityId();
        final Workflow workflow = deployedWorkflow.getWorkflow();
        return workflow.findFlowElementById(currentActivityId);
    } else {
        throw new RuntimeException("No workflow found for key: " + workflowKey);
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) DeployedWorkflow(io.zeebe.broker.workflow.map.DeployedWorkflow) DeployedWorkflow(io.zeebe.broker.workflow.map.DeployedWorkflow)

Example 12 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class WorkflowDeploymentCache method getWorkflowIndex.

private int getWorkflowIndex(WorkflowEvent event) {
    final DirectBuffer bpmnProcessId = event.getBpmnProcessId();
    final DirectBuffer bpmnXml = event.getBpmnXml();
    int index = 0;
    final WorkflowDefinition workflowDefinition = bpmn.readFromXmlBuffer(bpmnXml);
    final Iterator<Workflow> workflows = workflowDefinition.getWorkflows().iterator();
    while (workflows.hasNext()) {
        final Workflow workflow = workflows.next();
        if (BufferUtil.equals(bpmnProcessId, workflow.getBpmnProcessId())) {
            return index;
        }
        index += 1;
    }
    throw new RuntimeException("workflow not found");
}
Also used : DirectBuffer(org.agrona.DirectBuffer) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) Workflow(io.zeebe.model.bpmn.instance.Workflow)

Example 13 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class WorkflowDeploymentCache method lookupWorkflow.

private DeployedWorkflow lookupWorkflow(long key) {
    DeployedWorkflow deployedWorkflow = null;
    final DirectBuffer positionWorkflowBuffer = keyToPositionWorkflowMap.get(key);
    if (positionWorkflowBuffer != null) {
        final long eventPosition = positionWorkflowBuffer.getLong(POSITION_OFFSET, BYTE_ORDER);
        final int workflowIndex = positionWorkflowBuffer.getInt(WORKFLOW_INDEX_OFFSET, BYTE_ORDER);
        final boolean found = logStreamReader.seek(eventPosition);
        if (found && logStreamReader.hasNext()) {
            final LoggedEvent event = logStreamReader.next();
            workflowEvent.reset();
            event.readValue(workflowEvent);
            final WorkflowDefinition workflowDefinition = bpmn.readFromXmlBuffer(workflowEvent.getBpmnXml());
            final Workflow workflow = getWorkflowAt(workflowDefinition, workflowIndex);
            deployedWorkflow = new DeployedWorkflow(workflow, workflowEvent.getVersion());
        }
    }
    return deployedWorkflow;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) Workflow(io.zeebe.model.bpmn.instance.Workflow)

Example 14 with DirectBuffer

use of org.agrona.DirectBuffer 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)

Example 15 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class TaskInstanceMap method wrapTaskInstanceKey.

public TaskInstanceMap wrapTaskInstanceKey(long key) {
    final DirectBuffer result = map.get(key);
    if (result != null) {
        buffer.putBytes(0, result, 0, result.capacity());
    }
    this.isRead = result != null;
    this.key = key;
    return this;
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Aggregations

DirectBuffer (org.agrona.DirectBuffer)102 Header (io.aeron.logbuffer.Header)18 MutableDirectBuffer (org.agrona.MutableDirectBuffer)16 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)15 File (java.io.File)14 MappedByteBuffer (java.nio.MappedByteBuffer)11 Test (org.junit.Test)11 MediaDriver (io.aeron.driver.MediaDriver)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 ClusteredService (io.aeron.cluster.service.ClusteredService)8 Publication (io.aeron.Publication)7 ClientSession (io.aeron.cluster.service.ClientSession)7 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)7 ThreadingMode (io.aeron.driver.ThreadingMode)6 FragmentHandler (io.aeron.logbuffer.FragmentHandler)6 ByteBuffer (java.nio.ByteBuffer)6 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)5 InterruptAfter (io.aeron.test.InterruptAfter)5 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)5 LogBufferDescriptor (io.aeron.logbuffer.LogBufferDescriptor)4