use of io.atomix.primitive.PrimitiveBuilder in project atomix by atomix.
the class CoreTransactionService method completeParticipant.
/**
* Completes an individual participant in a transaction by loading the primitive by type/protocol/partition group and
* applying the given completion function to it.
*/
@SuppressWarnings("unchecked")
private CompletableFuture<Void> completeParticipant(ParticipantInfo participantInfo, Function<Transactional<?>, CompletableFuture<Void>> completionFunction) {
// Look up the primitive type for the participant. If the primitive type is not found, return an exception.
PrimitiveType primitiveType = managementService.getPrimitiveTypeRegistry().getPrimitiveType(participantInfo.type());
if (primitiveType == null) {
return Futures.exceptionalFuture(new TransactionException("Failed to locate primitive type " + participantInfo.type() + " for participant " + participantInfo.name()));
}
// Look up the protocol type for the participant.
PrimitiveProtocol.Type protocolType = managementService.getProtocolTypeRegistry().getProtocolType(participantInfo.protocol());
if (protocolType == null) {
return Futures.exceptionalFuture(new TransactionException("Failed to locate protocol type for participant " + participantInfo.name()));
}
// Look up the partition group in which the primitive is stored.
PartitionGroup partitionGroup;
if (participantInfo.group() == null) {
partitionGroup = managementService.getPartitionService().getPartitionGroup(protocolType);
} else {
partitionGroup = managementService.getPartitionService().getPartitionGroup(participantInfo.group());
}
// If the partition group is not found, return an exception.
if (partitionGroup == null) {
return Futures.exceptionalFuture(new TransactionException("Failed to locate partition group for participant " + participantInfo.name()));
}
PrimitiveBuilder builder = primitiveType.newBuilder(participantInfo.name(), primitiveType.newConfig(), managementService);
((ProxyCompatibleBuilder) builder).withProtocol(partitionGroup.newProtocol());
DistributedPrimitive primitive = builder.build();
return completionFunction.apply((Transactional<?>) primitive);
}
Aggregations