25e1160c4513540e61341ae18b1812010b9b51ae
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / shardstrategy / PrefixShardStrategy.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.shardstrategy;
10
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12
13 /**
14  * Shard Strategy that resolves a path to a prefix shard name.
15  */
16 public class PrefixShardStrategy implements ShardStrategy {
17
18     public static final String NAME = "prefix";
19
20     private final String shardName;
21     private final YangInstanceIdentifier prefix;
22
23     public PrefixShardStrategy(final String shardName,
24                                final YangInstanceIdentifier prefix) {
25         this.shardName = shardName != null ? shardName : DefaultShardStrategy.DEFAULT_SHARD;
26         this.prefix = prefix;
27     }
28
29     @Override
30     public String findShard(final YangInstanceIdentifier path) {
31         return shardName;
32     }
33
34     @Override
35     public YangInstanceIdentifier getPrefixForPath(YangInstanceIdentifier path) {
36         return prefix;
37     }
38 }