public ExecuteCommandRequest setKey(long key) { this.key = key; this.partitionId = Protocol.decodePartitionId(key); return this; }
/** * Initializes the key state with the corresponding partition id, so that unique keys are * generated over all partitions. * * @param partitionId the partition to determine the key start value */ public KeyState(int partitionId, ZeebeDb zeebeDb) { keyStartValue = Protocol.encodePartitionId(partitionId, INITIAL_VALUE); nextValueManager = new NextValueManager(keyStartValue, zeebeDb, ZbColumnFamilies.KEY); }
@Override public void transform(FlowElement element, TransformContext context) { final ExecutableWorkflow workflow = context.getCurrentWorkflow(); final Class<?> elementType = element.getElementType().getInstanceType(); final Function<String, AbstractFlowElement> elementFactory = ELEMENT_FACTORIES.get(elementType); if (elementFactory == null) { throw new IllegalStateException("no transformer found for element type: " + elementType); } final AbstractFlowElement executableElement = elementFactory.apply(element.getId()); executableElement.setElementType( BpmnElementType.bpmnElementTypeFor(element.getElementType().getTypeName())); workflow.addFlowElement(executableElement); } }
public boolean closeWorkflowInstanceSubscription( final long workflowInstanceKey, final long elementInstanceKey, final DirectBuffer messageName) { final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); closeWorkflowInstanceSubscriptionCommand.setSubscriptionPartitionId(partitionId); closeWorkflowInstanceSubscriptionCommand.setWorkflowInstanceKey(workflowInstanceKey); closeWorkflowInstanceSubscriptionCommand.setElementInstanceKey(elementInstanceKey); closeWorkflowInstanceSubscriptionCommand.setMessageName(messageName); return sendSubscriptionCommand( workflowInstancePartitionId, closeWorkflowInstanceSubscriptionCommand); }
@Override public void transform(FlowElement element, TransformContext context) { final ExecutableWorkflow workflow = context.getCurrentWorkflow(); final Class<?> elementType = element.getElementType().getInstanceType(); final Function<String, AbstractFlowElement> elementFactory = ELEMENT_FACTORIES.get(elementType); if (elementFactory == null) { throw new IllegalStateException("no transformer found for element type: " + elementType); } final AbstractFlowElement executableElement = elementFactory.apply(element.getId()); executableElement.setElementType( BpmnElementType.bpmnElementTypeFor(element.getElementType().getTypeName())); workflow.addFlowElement(executableElement); } }
/** * Initializes the key state with the corresponding partition id, so that unique keys are * generated over all partitions. * * @param partitionId the partition to determine the key start value */ public KeyState(int partitionId, ZeebeDb zeebeDb) { keyStartValue = Protocol.encodePartitionId(partitionId, INITIAL_VALUE); nextValueManager = new NextValueManager(keyStartValue, zeebeDb, ZbColumnFamilies.KEY); }
public boolean closeWorkflowInstanceSubscription( final long workflowInstanceKey, final long elementInstanceKey, final DirectBuffer messageName) { final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); closeWorkflowInstanceSubscriptionCommand.setSubscriptionPartitionId(partitionId); closeWorkflowInstanceSubscriptionCommand.setWorkflowInstanceKey(workflowInstanceKey); closeWorkflowInstanceSubscriptionCommand.setElementInstanceKey(elementInstanceKey); closeWorkflowInstanceSubscriptionCommand.setMessageName(messageName); return sendSubscriptionCommand( workflowInstancePartitionId, closeWorkflowInstanceSubscriptionCommand); }
@Override public void transform(Process element, TransformContext context) { final String id = element.getId(); final ExecutableWorkflow workflow = new ExecutableWorkflow(id); workflow.setElementType( BpmnElementType.bpmnElementTypeFor(element.getElementType().getTypeName())); context.addWorkflow(workflow); context.setCurrentWorkflow(workflow); workflow.bindLifecycleState(WorkflowInstanceIntent.ELEMENT_READY, BpmnStep.ACTIVATE_FLOW_NODE); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_ACTIVATED, BpmnStep.TRIGGER_START_EVENT); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_COMPLETING, BpmnStep.COMPLETE_PROCESS); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_TERMINATING, BpmnStep.TERMINATE_CONTAINED_INSTANCES); } }
public boolean openWorkflowInstanceSubscription( final long workflowInstanceKey, final long elementInstanceKey, final DirectBuffer messageName, final boolean closeOnCorrelate) { final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); openWorkflowInstanceSubscriptionCommand.setSubscriptionPartitionId(partitionId); openWorkflowInstanceSubscriptionCommand.setWorkflowInstanceKey(workflowInstanceKey); openWorkflowInstanceSubscriptionCommand.setElementInstanceKey(elementInstanceKey); openWorkflowInstanceSubscriptionCommand.getMessageName().wrap(messageName); openWorkflowInstanceSubscriptionCommand.setCloseOnCorrelate(closeOnCorrelate); return sendSubscriptionCommand( workflowInstancePartitionId, openWorkflowInstanceSubscriptionCommand); }
@Override public void transform(Process element, TransformContext context) { final String id = element.getId(); final ExecutableWorkflow workflow = new ExecutableWorkflow(id); workflow.setElementType( BpmnElementType.bpmnElementTypeFor(element.getElementType().getTypeName())); context.addWorkflow(workflow); context.setCurrentWorkflow(workflow); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_ACTIVATING, BpmnStep.ELEMENT_ACTIVATING); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_ACTIVATED, BpmnStep.CONTAINER_ELEMENT_ACTIVATED); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_COMPLETING, BpmnStep.ELEMENT_COMPLETING); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_COMPLETED, BpmnStep.ELEMENT_COMPLETED); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_TERMINATING, BpmnStep.CONTAINER_ELEMENT_TERMINATING); workflow.bindLifecycleState( WorkflowInstanceIntent.ELEMENT_TERMINATED, BpmnStep.ELEMENT_TERMINATED); } }
public boolean openWorkflowInstanceSubscription( final long workflowInstanceKey, final long elementInstanceKey, final DirectBuffer messageName, final boolean closeOnCorrelate) { final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); openWorkflowInstanceSubscriptionCommand.setSubscriptionPartitionId(partitionId); openWorkflowInstanceSubscriptionCommand.setWorkflowInstanceKey(workflowInstanceKey); openWorkflowInstanceSubscriptionCommand.setElementInstanceKey(elementInstanceKey); openWorkflowInstanceSubscriptionCommand.getMessageName().wrap(messageName); openWorkflowInstanceSubscriptionCommand.setCloseOnCorrelate(closeOnCorrelate); return sendSubscriptionCommand( workflowInstancePartitionId, openWorkflowInstanceSubscriptionCommand); }
public boolean correlateWorkflowInstanceSubscription( final long workflowInstanceKey, final long elementInstanceKey, final DirectBuffer messageName, final DirectBuffer payload) { final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); correlateWorkflowInstanceSubscriptionCommand.setSubscriptionPartitionId(partitionId); correlateWorkflowInstanceSubscriptionCommand.setWorkflowInstanceKey(workflowInstanceKey); correlateWorkflowInstanceSubscriptionCommand.setElementInstanceKey(elementInstanceKey); correlateWorkflowInstanceSubscriptionCommand.getMessageName().wrap(messageName); correlateWorkflowInstanceSubscriptionCommand.getPayload().wrap(payload); return sendSubscriptionCommand( workflowInstancePartitionId, correlateWorkflowInstanceSubscriptionCommand); }
public boolean correlateWorkflowInstanceSubscription( final long workflowInstanceKey, final long elementInstanceKey, final DirectBuffer messageName, final DirectBuffer payload) { final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); correlateWorkflowInstanceSubscriptionCommand.setSubscriptionPartitionId(partitionId); correlateWorkflowInstanceSubscriptionCommand.setWorkflowInstanceKey(workflowInstanceKey); correlateWorkflowInstanceSubscriptionCommand.setElementInstanceKey(elementInstanceKey); correlateWorkflowInstanceSubscriptionCommand.getMessageName().wrap(messageName); correlateWorkflowInstanceSubscriptionCommand.getPayload().wrap(payload); return sendSubscriptionCommand( workflowInstancePartitionId, correlateWorkflowInstanceSubscriptionCommand); }
@Test public void shouldGetUniqueValuesOverPartitions() throws Exception { // given final ZeebeDb<ZbColumnFamilies> newDb = stateRule.createNewDb(); final ZeebeState otherZeebeState = new ZeebeState(1, newDb); final KeyGenerator keyGenerator2 = otherZeebeState.getKeyGenerator(); final long keyOfFirstPartition = keyGenerator.nextKey(); // when final long keyOfSecondPartition = keyGenerator2.nextKey(); // then assertThat(keyOfFirstPartition).isNotEqualTo(keyOfSecondPartition); assertThat(Protocol.decodePartitionId(keyOfFirstPartition)).isEqualTo(0); assertThat(Protocol.decodePartitionId(keyOfSecondPartition)).isEqualTo(1); newDb.close(); } }
private boolean onCloseWorkflowInstanceSubscription(DirectBuffer buffer, int offset, int length) { closeWorkflowInstanceSubscriptionCommand.wrap(buffer, offset, length); final long workflowInstanceKey = closeWorkflowInstanceSubscriptionCommand.getWorkflowInstanceKey(); final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); workflowInstanceSubscriptionRecord.reset(); workflowInstanceSubscriptionRecord .setSubscriptionPartitionId( closeWorkflowInstanceSubscriptionCommand.getSubscriptionPartitionId()) .setWorkflowInstanceKey(workflowInstanceKey) .setElementInstanceKey(closeWorkflowInstanceSubscriptionCommand.getElementInstanceKey()) .setMessageName(closeWorkflowInstanceSubscriptionCommand.getMessageName()); return writeCommand( workflowInstancePartitionId, ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION, WorkflowInstanceSubscriptionIntent.CLOSE, workflowInstanceSubscriptionRecord); }
private boolean onCloseWorkflowInstanceSubscription(DirectBuffer buffer, int offset, int length) { closeWorkflowInstanceSubscriptionCommand.wrap(buffer, offset, length); final long workflowInstanceKey = closeWorkflowInstanceSubscriptionCommand.getWorkflowInstanceKey(); final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); workflowInstanceSubscriptionRecord.reset(); workflowInstanceSubscriptionRecord .setSubscriptionPartitionId( closeWorkflowInstanceSubscriptionCommand.getSubscriptionPartitionId()) .setWorkflowInstanceKey(workflowInstanceKey) .setElementInstanceKey(closeWorkflowInstanceSubscriptionCommand.getElementInstanceKey()) .setMessageName(closeWorkflowInstanceSubscriptionCommand.getMessageName()); return writeCommand( workflowInstancePartitionId, ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION, WorkflowInstanceSubscriptionIntent.CLOSE, workflowInstanceSubscriptionRecord); }
private boolean onCorrelateWorkflowInstanceSubscription( DirectBuffer buffer, int offset, int length) { correlateWorkflowInstanceSubscriptionCommand.wrap(buffer, offset, length); final long workflowInstanceKey = correlateWorkflowInstanceSubscriptionCommand.getWorkflowInstanceKey(); final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); workflowInstanceSubscriptionRecord .setSubscriptionPartitionId( correlateWorkflowInstanceSubscriptionCommand.getSubscriptionPartitionId()) .setWorkflowInstanceKey(workflowInstanceKey) .setElementInstanceKey(correlateWorkflowInstanceSubscriptionCommand.getElementInstanceKey()) .setMessageName(correlateWorkflowInstanceSubscriptionCommand.getMessageName()) .setPayload(correlateWorkflowInstanceSubscriptionCommand.getPayload()); return writeCommand( workflowInstancePartitionId, ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION, WorkflowInstanceSubscriptionIntent.CORRELATE, workflowInstanceSubscriptionRecord); }
private boolean onCorrelateWorkflowInstanceSubscription( DirectBuffer buffer, int offset, int length) { correlateWorkflowInstanceSubscriptionCommand.wrap(buffer, offset, length); final long workflowInstanceKey = correlateWorkflowInstanceSubscriptionCommand.getWorkflowInstanceKey(); final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); workflowInstanceSubscriptionRecord .setSubscriptionPartitionId( correlateWorkflowInstanceSubscriptionCommand.getSubscriptionPartitionId()) .setWorkflowInstanceKey(workflowInstanceKey) .setElementInstanceKey(correlateWorkflowInstanceSubscriptionCommand.getElementInstanceKey()) .setMessageName(correlateWorkflowInstanceSubscriptionCommand.getMessageName()) .setPayload(correlateWorkflowInstanceSubscriptionCommand.getPayload()); return writeCommand( workflowInstancePartitionId, ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION, WorkflowInstanceSubscriptionIntent.CORRELATE, workflowInstanceSubscriptionRecord); }
private boolean onOpenWorkflowInstanceSubscription(DirectBuffer buffer, int offset, int length) { openWorkflowInstanceSubscriptionCommand.wrap(buffer, offset, length); final long workflowInstanceKey = openWorkflowInstanceSubscriptionCommand.getWorkflowInstanceKey(); final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); workflowInstanceSubscriptionRecord.reset(); workflowInstanceSubscriptionRecord .setSubscriptionPartitionId( openWorkflowInstanceSubscriptionCommand.getSubscriptionPartitionId()) .setWorkflowInstanceKey(workflowInstanceKey) .setElementInstanceKey(openWorkflowInstanceSubscriptionCommand.getElementInstanceKey()) .setMessageName(openWorkflowInstanceSubscriptionCommand.getMessageName()) .setCloseOnCorrelate(openWorkflowInstanceSubscriptionCommand.shouldCloseOnCorrelate()); return writeCommand( workflowInstancePartitionId, ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION, WorkflowInstanceSubscriptionIntent.OPEN, workflowInstanceSubscriptionRecord); }
private boolean onOpenWorkflowInstanceSubscription(DirectBuffer buffer, int offset, int length) { openWorkflowInstanceSubscriptionCommand.wrap(buffer, offset, length); final long workflowInstanceKey = openWorkflowInstanceSubscriptionCommand.getWorkflowInstanceKey(); final int workflowInstancePartitionId = Protocol.decodePartitionId(workflowInstanceKey); workflowInstanceSubscriptionRecord.reset(); workflowInstanceSubscriptionRecord .setSubscriptionPartitionId( openWorkflowInstanceSubscriptionCommand.getSubscriptionPartitionId()) .setWorkflowInstanceKey(workflowInstanceKey) .setElementInstanceKey(openWorkflowInstanceSubscriptionCommand.getElementInstanceKey()) .setMessageName(openWorkflowInstanceSubscriptionCommand.getMessageName()) .setCloseOnCorrelate(openWorkflowInstanceSubscriptionCommand.shouldCloseOnCorrelate()); return writeCommand( workflowInstancePartitionId, ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION, WorkflowInstanceSubscriptionIntent.OPEN, workflowInstanceSubscriptionRecord); }