/** * Sets the primitive to read-only. * * @return the primitive builder */ @SuppressWarnings("unchecked") public B withReadOnly() { config.setReadOnly(); return (B) this; }
@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); }
/** * Returns the primitive protocol. * * @return the primitive protocol */ protected PrimitiveProtocol protocol() { PrimitiveProtocol protocol = this.protocol; if (protocol == null) { PrimitiveProtocolConfig<?> protocolConfig = config.getProtocolConfig(); if (protocolConfig == null) { Collection<PartitionGroup> partitionGroups = managementService.getPartitionService().getPartitionGroups(); if (partitionGroups.size() == 1) { protocol = partitionGroups.iterator().next().newProtocol(); } else { String groups = Joiner.on(", ").join(partitionGroups.stream() .map(group -> group.name()) .collect(Collectors.toList())); throw new ConfigurationException(String.format("Primitive protocol is ambiguous: %d partition groups found (%s)", partitionGroups.size(), groups)); } } else { protocol = protocolConfig.getType().newProtocol(protocolConfig); } } return protocol; }
/** * Returns the protocol serializer. * * @return the protocol serializer */ protected Serializer serializer() { Serializer serializer = this.serializer; if (serializer == null) { synchronized (this) { serializer = this.serializer; if (serializer == null) { NamespaceConfig config = this.config.getNamespaceConfig(); if (config == null) { serializer = Serializer.using(Namespaces.BASIC); } else { serializer = Serializer.using(Namespace.builder() .register(Namespaces.BASIC) .nextId(Namespaces.BEGIN_USER_CUSTOM_ID) .register(new Namespace(config)) .build()); } this.serializer = serializer; } } } return serializer; }
@Override @SuppressWarnings("unchecked") public <C extends PrimitiveConfig<C>, P extends SyncPrimitive> CompletableFuture<P> getPrimitiveAsync( String name, PrimitiveType<?, C, P> primitiveType, C primitiveConfig) { return cache.getPrimitive(name, () -> { C config = primitiveConfig; if (config == null) { config = configService.getConfig(name, primitiveType); } return primitiveType.newBuilder(name, config, managementService).buildAsync(); }); }
/** * Sets whether the primitive is read-only. * * @param readOnly whether the primitive is read-only * @return the primitive builder */ @SuppressWarnings("unchecked") public B withReadOnly(boolean readOnly) { config.setReadOnly(readOnly); return (B) this; }
@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); }
/** * Sets the primitive to read-only. * * @return the primitive configuration */ public C setReadOnly() { return setReadOnly(true); }
@Override @SuppressWarnings("unchecked") public <C extends PrimitiveConfig<C>, P extends SyncPrimitive> CompletableFuture<P> getPrimitiveAsync( String name, PrimitiveType<?, C, P> primitiveType, C primitiveConfig) { return cache.getPrimitive(name, () -> { C config = primitiveConfig; if (config == null) { config = configService.getConfig(name, primitiveType); } return primitiveType.newBuilder(name, config, managementService).buildAsync(); }); }