blob: c94090ac353bb17b0b5742835649c94f60375a94 [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 Jampani94c23532015-02-05 17:40:01 -080018
Madan Jampanif1b8e172015-03-23 11:42:02 -070019import java.util.List;
Madan Jampani94c23532015-02-05 17:40:01 -080020
Madan Jampani94c23532015-02-05 17:40:01 -080021/**
Madan Jampani09342702015-02-05 23:32:40 -080022 * A simple Partitioner for mapping keys to database partitions.
23 * <p>
24 * This class uses a md5 hash based hashing scheme for hashing the key to
25 * a partition.
Madan Jampani94c23532015-02-05 17:40:01 -080026 *
Madan Jampani94c23532015-02-05 17:40:01 -080027 */
Madan Jampani09342702015-02-05 23:32:40 -080028public class SimpleKeyHashPartitioner extends DatabasePartitioner {
Madan Jampani94c23532015-02-05 17:40:01 -080029
Madan Jampanif1b8e172015-03-23 11:42:02 -070030 public SimpleKeyHashPartitioner(List<Database> partitions) {
31 super(partitions);
Madan Jampani94c23532015-02-05 17:40:01 -080032 }
33
34 @Override
Madan Jampani7804c992015-07-20 13:20:19 -070035 public Database getPartition(String mapName, String key) {
Madan Jampanif1b8e172015-03-23 11:42:02 -070036 return partitions.get(hash(key) % partitions.size());
Madan Jampani94c23532015-02-05 17:40:01 -080037 }
Madan Jampani09342702015-02-05 23:32:40 -080038}