Add partition map reload

This commit is contained in:
calzoneman 2016-06-08 22:54:16 -07:00
parent 7faf2829b2
commit 6e772c6837
5 changed files with 109 additions and 57 deletions

View file

@ -2,27 +2,28 @@ import { murmurHash1 } from '../util/murmur';
class PartitionDecider {
constructor(config) {
this.identity = config.getIdentity();
this.partitionMap = config.getPartitionMap();
this.pool = config.getPool();
this.overrideMap = config.getOverrideMap();
this.config = config;
}
getPartitionForChannel(channel) {
return this.partitionMap[this.getPartitionIdentityForChannel(channel)];
const partitionMap = this.config.getPartitionMap();
return partitionMap[this.getPartitionIdentityForChannel(channel)];
}
getPartitionIdentityForChannel(channel) {
if (this.overrideMap.hasOwnProperty(channel)) {
return this.overrideMap[channel];
const overrideMap = this.config.getOverrideMap();
if (overrideMap.hasOwnProperty(channel)) {
return overrideMap[channel];
} else {
const i = murmurHash1(channel) % this.pool.length;
return this.pool[i];
const pool = this.config.getPool();
const i = murmurHash1(channel) % pool.length;
return pool[i];
}
}
isChannelOnThisPartition(channel) {
return this.getPartitionIdentityForChannel(channel) === this.identity;
return this.getPartitionIdentityForChannel(channel) ===
this.config.getIdentity();
}
}