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);
}
}
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");
}
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;
}
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;
}
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;
}
Aggregations