2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore.shardstrategy;
11 import org.opendaylight.controller.cluster.datastore.config.Configuration;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 * Shard Strategy that resolves a path to a prefix shard name.
17 public class PrefixShardStrategy implements ShardStrategy {
19 public static final String NAME = "prefix";
21 private final String shardName;
22 private final Configuration configuration;
24 public PrefixShardStrategy(final String shardName, final Configuration configuration) {
25 this.shardName = shardName;
26 this.configuration = configuration;
30 public String findShard(final YangInstanceIdentifier path) {
31 final String shardNameForPrefix = configuration.getShardNameForPrefix(path);
32 return shardNameForPrefix != null ? shardName : DefaultShardStrategy.DEFAULT_SHARD;