Search in sources :

Example 1 with TransactionException

use of io.atomix.core.transaction.TransactionException 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);
}
Also used : PartitionGroup(io.atomix.primitive.partition.PartitionGroup) TransactionException(io.atomix.core.transaction.TransactionException) PrimitiveBuilder(io.atomix.primitive.PrimitiveBuilder) ProxyCompatibleBuilder(io.atomix.primitive.protocol.ProxyCompatibleBuilder) PrimitiveType(io.atomix.primitive.PrimitiveType) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) DistributedPrimitive(io.atomix.primitive.DistributedPrimitive)

Aggregations

TransactionException (io.atomix.core.transaction.TransactionException)1 DistributedPrimitive (io.atomix.primitive.DistributedPrimitive)1 PrimitiveBuilder (io.atomix.primitive.PrimitiveBuilder)1 PrimitiveType (io.atomix.primitive.PrimitiveType)1 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)1 PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)1 ProxyCompatibleBuilder (io.atomix.primitive.protocol.ProxyCompatibleBuilder)1