Introduce ShardStrategy and related code
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / shardstrategy / ShardStrategyFactory.java
1 /*
2  * Copyright (c) 2014 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 com.google.common.base.Preconditions;
12 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
13
14 import java.util.Map;
15 import java.util.concurrent.ConcurrentHashMap;
16
17 public class ShardStrategyFactory {
18   private static final Map<String, ShardStrategy> moduleNameToStrategyMap = new ConcurrentHashMap();
19
20   private static final String UNKNOWN_MODULE_NAME = "unknown";
21
22   public static ShardStrategy getStrategy(InstanceIdentifier path){
23     Preconditions.checkNotNull(path, "path should not be null");
24
25     String moduleName = getModuleName(path);
26     ShardStrategy shardStrategy = moduleNameToStrategyMap.get(moduleName);
27     if(shardStrategy == null){
28       return new DefaultShardStrategy();
29     }
30
31     return shardStrategy;
32   }
33
34
35   private static String getModuleName(InstanceIdentifier path){
36     return UNKNOWN_MODULE_NAME;
37   }
38
39   /**
40    * This is to be used in the future to register a custom shard strategy
41    *
42    * @param moduleName
43    * @param shardStrategy
44    */
45   public static void registerShardStrategy(String moduleName, ShardStrategy shardStrategy){
46     throw new UnsupportedOperationException("registering a custom shard strategy not supported yet");
47   }
48 }

©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.