blob: bf7971e8d34b433b0c1beb8a32072f515f2cf68c [file] [log] [blame]
Madan Jampani25461112015-02-17 14:17:29 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Madan Jampanif4c88502016-01-21 12:35:36 -080017package org.onosproject.store.primitives.impl;
Madan Jampani09342702015-02-05 23:32:40 -080018
Madan Jampanif1b8e172015-03-23 11:42:02 -070019import java.util.List;
Madan Jampani09342702015-02-05 23:32:40 -080020
21/**
Madan Jampani7804c992015-07-20 13:20:19 -070022 * A simple Partitioner that uses the map name hash to
Madan Jampani09342702015-02-05 23:32:40 -080023 * pick a partition.
24 * <p>
Madan Jampani7804c992015-07-20 13:20:19 -070025 * This class uses a md5 hash based hashing scheme for hashing the map name to
26 * a partition. This partitioner maps all keys for a map to the same database
Madan Jampani09342702015-02-05 23:32:40 -080027 * partition.
28 */
29public class SimpleTableHashPartitioner extends DatabasePartitioner {
30
Madan Jampanif1b8e172015-03-23 11:42:02 -070031 public SimpleTableHashPartitioner(List<Database> partitions) {
32 super(partitions);
Madan Jampani09342702015-02-05 23:32:40 -080033 }
34
35 @Override
Madan Jampani7804c992015-07-20 13:20:19 -070036 public Database getPartition(String mapName, String key) {
37 return partitions.get(hash(mapName) % partitions.size());
Madan Jampani09342702015-02-05 23:32:40 -080038 }
Madan Jampanibff6d8f2015-03-31 16:53:47 -070039}