Java Code Examples for io.atomix.primitive.PrimitiveType#newBuilder()

The following examples show how to use io.atomix.primitive.PrimitiveType#newBuilder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreTransactionService.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: CorePrimitivesService.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public <B extends PrimitiveBuilder<B, C, P>, C extends PrimitiveConfig<C>, P extends SyncPrimitive> B primitiveBuilder(
    String name, PrimitiveType<B, C, P> primitiveType) {
  return primitiveType.newBuilder(name, configService.getConfig(name, primitiveType), managementService);
}