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); }
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); }
/** * 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); }
@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(); } }
@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(); } }
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 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); }
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); }
@Test public void shouldStartWorkflowInstanceAtNoneStartEvent() { // given apiRule .partitionClient() .deploy(Bpmn.createExecutableProcess("process").startEvent("foo").endEvent().done()); // when TestUtil.waitUntil(() -> RecordingExporter.deploymentRecords().withPartitionId(2).exists()); final ExecuteCommandResponse workflowInstanceWithResponse = apiRule.partitionClient(2).createWorkflowInstanceWithResponse("process"); // then partition id is encoded in the returned getKey final long key = workflowInstanceWithResponse.getKey(); final int partitionId = Protocol.decodePartitionId(key); assertThat(partitionId).isEqualTo(2); } }
@Test public void shouldStartWorkflowInstanceAtNoneStartEvent() { // given apiRule .partitionClient() .deploy(Bpmn.createExecutableProcess("process").startEvent("foo").endEvent().done()); // when TestUtil.waitUntil(() -> RecordingExporter.deploymentRecords().withPartitionId(2).exists()); final ExecuteCommandResponse workflowInstanceWithResponse = apiRule.partitionClient(2).createWorkflowInstanceWithResponse("process"); // then partition id is encoded in the returned getKey final long key = workflowInstanceWithResponse.getKey(); final int partitionId = Protocol.decodePartitionId(key); assertThat(partitionId).isEqualTo(2); } }