/** * Create replication options represented as {@link Map}. * * @return the replication options represented as {@link Map}. * @since 2.0.1 */ protected Map<Option, Object> getReplication() { Map<Option, Object> replicationStrategyMap = new HashMap<>(); if (hasReplicationOptions()) { replicationStrategyMap.put(new DefaultOption("class", String.class, true, false, true), replicationStrategy.getValue()); if (replicationStrategy == ReplicationStrategy.SIMPLE_STRATEGY) { replicationStrategyMap.put(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor); } if (replicationStrategy == ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY) { for (DataCenterReplication datacenter : replications) { replicationStrategyMap.put(new DefaultOption(datacenter.getDataCenter(), Long.class, true, false, false), datacenter.getReplicationFactor()); } } } return replicationStrategyMap; }
/** * Parses the keyspace replication options and adds them to the supplied {@link BeanDefinitionBuilder}. * * @param element {@link Element} to parse. * @param builder The {@link BeanDefinitionBuilder} to add the replication to */ private void parseReplication(@Nullable Element element, BeanDefinitionBuilder builder) { ManagedList<String> networkTopologyDataCenters = new ManagedList<>(); ManagedList<String> networkTopologyReplicationFactors = new ManagedList<>(); if (element != null) { addOptionalPropertyValue(builder, "replicationStrategy", element, "class", KeyspaceAttributes.DEFAULT_REPLICATION_STRATEGY.name()); addOptionalPropertyValue(builder, "replicationFactor", element, "replication-factor", String.valueOf(KeyspaceAttributes.DEFAULT_REPLICATION_FACTOR)); // DataCenters only apply to NetworkTopologyStrategy for (Element dataCenter : DomUtils.getChildElementsByTagName(element, "data-center")) { networkTopologyDataCenters.add(dataCenter.getAttribute("name")); networkTopologyReplicationFactors.add(dataCenter.getAttribute("replication-factor")); } } builder.addPropertyValue("networkTopologyDataCenters", networkTopologyDataCenters); builder.addPropertyValue("networkTopologyReplicationFactors", networkTopologyReplicationFactors); }
/** * Returns a {@link BeanDefinition} for a {@link KeyspaceActionSpecification} object. * * @param element Element being parsed. * @param parserContext XML parser context and state. * @return the {@link BeanDefinition} or {@literal null} if action is not given. */ private BeanDefinition newKeyspaceActionSpecificationBeanDefinition(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(KeyspaceActionSpecificationFactoryBean.class); // add required replication defaults addRequiredPropertyValue(builder, "replicationStrategy", KeyspaceAttributes.DEFAULT_REPLICATION_STRATEGY.name()); addRequiredPropertyValue(builder, "replicationFactor", String.valueOf(KeyspaceAttributes.DEFAULT_REPLICATION_FACTOR)); addRequiredPropertyValue(builder, "name", element, "name"); addOptionalPropertyValue(builder, "durableWrites", element, "durable-writes", "false"); addRequiredPropertyValue(builder, "action", element, "action"); parseReplication(DomUtils.getChildElementByTagName(element, "replication"), builder); return getSourceBeanDefinition(builder, parserContext, element); }
/** * Configure datacenter replication given {@link DataCenterReplication}. * * @return this. */ public CreateKeyspaceSpecification withNetworkReplication(DataCenterReplication... dcrs) { MapBuilder<Option, Object> builder = MapBuilder.map(Option.class, Object.class).entry( new DefaultOption("class", String.class, true, false, true), ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getValue()); for (DataCenterReplication dcr : dcrs) { builder.entry(new DefaultOption(dcr.getDataCenter(), Long.class, true, false, false), dcr.getReplicationFactor()); } return with(KeyspaceOption.REPLICATION, builder.build()); }
public String toString() { return getValue(); } }
/** * Returns a map of {@link Option}s suitable as the value of a {@link KeyspaceOption#REPLICATION} option with * replication strategy class "NetworkTopologyStrategy" and with data centers each with their corresponding * replication factors. */ public static Map<Option, Object> newNetworkReplication(DataCenterReplication... dataCenterReplications) { MapBuilder<Option, Object> builder = MapBuilder.map(Option.class, Object.class).entry( new DefaultOption("class", String.class, true, false, true), ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getValue()); for (DataCenterReplication dcr : dataCenterReplications) { builder.entry(new DefaultOption(dcr.getDataCenter(), Long.class, true, false, false), dcr.getReplicationFactor()); } return builder.build(); }
/** * Configure simple replication with a {@code replicationFactor}. * * @return this. */ public CreateKeyspaceSpecification withSimpleReplication(long replicationFactor) { return with(KeyspaceOption.REPLICATION, MapBuilder.map(Option.class, Object.class) .entry(new DefaultOption("class", String.class, true, false, true), ReplicationStrategy.SIMPLE_STRATEGY.getValue()) .entry(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor).build()); }
/** * Returns a map of {@link Option}s suitable as the value of a {@link KeyspaceOption#REPLICATION} option with * replication strategy class "SimpleStrategy" and with a replication factor equal to that given. */ public static Map<Option, Object> newSimpleReplication(long replicationFactor) { return MapBuilder.map(Option.class, Object.class) .entry(new DefaultOption("class", String.class, true, false, true), ReplicationStrategy.SIMPLE_STRATEGY.getValue()) .entry(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor).build(); }