Search in sources :

Example 1 with TypedBatchWriter

use of io.zeebe.broker.logstreams.processor.TypedBatchWriter in project zeebe by zeebe-io.

the class ExpirePartitionCreationProcessor method writeEvent.

@Override
public long writeEvent(TypedEvent<PartitionEvent> event, TypedStreamWriter writer) {
    final PartitionEvent value = event.getValue();
    final TypedBatchWriter batchWriter = writer.newBatch().addFollowUpEvent(event.getKey(), value);
    if (value.getState() == PartitionState.CREATE_EXPIRED) {
        // create a new partition
        final SocketAddress nextCreator = creatorStrategy.selectBrokerForNewPartition();
        if (nextCreator == null) {
            return -1;
        }
        newEvent.reset();
        newEvent.setState(PartitionState.CREATE);
        newEvent.setTopicName(value.getTopicName());
        newEvent.setId(idGenerator.currentId());
        newEvent.setCreator(nextCreator.getHostBuffer(), nextCreator.port());
        batchWriter.addNewEvent(newEvent);
    }
    return batchWriter.write();
}
Also used : TypedBatchWriter(io.zeebe.broker.logstreams.processor.TypedBatchWriter) SocketAddress(io.zeebe.transport.SocketAddress)

Example 2 with TypedBatchWriter

use of io.zeebe.broker.logstreams.processor.TypedBatchWriter in project zeebe by zeebe-io.

the class CreateTopicProcessor method writeEvent.

@Override
public long writeEvent(TypedEvent<TopicEvent> event, TypedStreamWriter writer) {
    final TopicEvent value = event.getValue();
    if (value.getState() == TopicState.CREATE_REJECTED) {
        return writer.writeFollowupEvent(event.getKey(), event.getValue());
    } else {
        final TypedBatchWriter batchWriter = writer.newBatch();
        for (int i = 0; i < value.getPartitions(); i++) {
            // in contrast to choosing the partition ID, choosing the creator
            // does not have to be deterministic (e.g. when this method is invoked multiple times due to backpressure),
            // so it is ok to choose the creator here and not in #processEvent
            final SocketAddress nextCreator = creatorStrategy.selectBrokerForNewPartition();
            if (nextCreator == null) {
                return -1;
            }
            partitionEvent.reset();
            partitionEvent.setState(PartitionState.CREATE);
            partitionEvent.setTopicName(value.getName());
            partitionEvent.setId(idGenerator.currentId(i));
            partitionEvent.setCreator(nextCreator.getHostBuffer(), nextCreator.port());
            batchWriter.addNewEvent(partitionEvent);
        }
        return batchWriter.write();
    }
}
Also used : TypedBatchWriter(io.zeebe.broker.logstreams.processor.TypedBatchWriter) SocketAddress(io.zeebe.transport.SocketAddress)

Example 3 with TypedBatchWriter

use of io.zeebe.broker.logstreams.processor.TypedBatchWriter in project zeebe by zeebe-io.

the class DeploymentCreateProcessor method writeEvent.

@Override
public long writeEvent(TypedEvent<DeploymentEvent> event, TypedStreamWriter writer) {
    final DeploymentEvent deploymentEvent = event.getValue();
    if (deploymentEvent.getState() == REJECTED) {
        return writer.writeFollowupEvent(event.getKey(), deploymentEvent);
    } else {
        final TypedBatchWriter batch = writer.newBatch();
        batch.addFollowUpEvent(event.getKey(), deploymentEvent, addRequestMetadata(event));
        final DeployedWorkflowIterator deployedWorkflowIterator = deploymentResourceIterator.getDeployedWorkflows();
        while (deployedWorkflowIterator.hasNext()) {
            final DeployedWorkflow deployedWorkflow = deployedWorkflowIterator.next();
            workflowEvent.setState(WorkflowState.CREATE).setBpmnProcessId(deployedWorkflow.getBpmnProcessId()).setVersion(deployedWorkflow.getVersion()).setBpmnXml(deployedWorkflowIterator.getDeploymentResource().getResource()).setDeploymentKey(event.getKey());
            batch.addNewEvent(workflowEvent);
        }
        return batch.write();
    }
}
Also used : TypedBatchWriter(io.zeebe.broker.logstreams.processor.TypedBatchWriter) DeployedWorkflow(io.zeebe.broker.workflow.data.DeployedWorkflow) DeploymentEvent(io.zeebe.broker.workflow.data.DeploymentEvent)

Aggregations

TypedBatchWriter (io.zeebe.broker.logstreams.processor.TypedBatchWriter)3 SocketAddress (io.zeebe.transport.SocketAddress)2 DeployedWorkflow (io.zeebe.broker.workflow.data.DeployedWorkflow)1 DeploymentEvent (io.zeebe.broker.workflow.data.DeploymentEvent)1