1e08a989d550057b28d6a80ceae009463acd565e
[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.controller.cluster.datastore.config.Configuration;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13
14 /**
15  * Shard Strategy that resolves a path to a prefix shard name.
16  */
17 public class PrefixShardStrategy implements ShardStrategy {
18
19     public static final String NAME = "prefix";
20
21     private final String shardName;
22     private final Configuration configuration;
23
24     public PrefixShardStrategy(final String shardName, final Configuration configuration) {
25         this.shardName = shardName;
26         this.configuration = configuration;
27     }
28
29     @Override
30     public String findShard(final YangInstanceIdentifier path) {
31         final String shardNameForPrefix = configuration.getShardNameForPrefix(path);
32         return shardNameForPrefix != null ? shardName : DefaultShardStrategy.DEFAULT_SHARD;
33     }
34 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.