/** * 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; }
/** * 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 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()); }