// Path: src/main/java/org/rakam/cache/hazelcast/hyperloglog/operations/HyperLogLogReplicationOperation.java
// public class HyperLogLogReplicationOperation extends AbstractOperation implements IdentifiedDataSerializable {
// 
//     private Map<String, byte[]> migrationData;
// 
//     public HyperLogLogReplicationOperation() {
//     }
// 
//     public HyperLogLogReplicationOperation(Map<String, byte[]> migrationData) {
//         this.migrationData = migrationData;
//     }
// 
//     @Override
//     public void run() throws Exception {
//         HyperLogLogService service = getService();
//         for (Map.Entry<String, byte[]> longEntry : migrationData.entrySet()) {
//             String name = longEntry.getKey();
//             HLLWrapper number = service.getHLL(name);
//             byte[] value = longEntry.getValue();
//             number.set(value);
//         }
//     }
// 
//     @Override
//     public String getServiceName() {
//         return HyperLogLogService.SERVICE_NAME;
//     }
// 
//     @Override
//     public int getFactoryId() {
//         return HyperLogLogSerializerFactory.F_ID;
//     }
// 
//     @Override
//     public int getId() {
//         return HyperLogLogSerializerFactory.REPLICATION;
//     }
// 
//     @Override
//     protected void writeInternal(ObjectDataOutput out) throws IOException {
//         out.writeInt(migrationData.size());
//         for (Map.Entry<String, byte[]> entry : migrationData.entrySet()) {
//             out.writeUTF(entry.getKey());
//             byte[] val = entry.getValue();
//             out.writeInt(val.length);
//             out.write(val);
//         }
//     }
// 
//     @Override
//     protected void readInternal(ObjectDataInput in) throws IOException {
//         int mapSize = in.readInt();
//         migrationData = new HashMap<String, byte[]>(mapSize);
//         for (int i = 0; i < mapSize; i++) {
//             String name = in.readUTF();
//             int number = in.readInt();
//             byte[] a = new byte[number];
//             in.readFully(a);
//             migrationData.put(name, a);
//         }
//     }
// }
// 
// Path: src/main/java/org/rakam/util/HLLWrapper.java
// public class HLLWrapper {
//     final private static int SEED = 123456;
//     private HLL hll;
// 
//     public HLLWrapper() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// 
//     public HLLWrapper(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public long cardinality() {
//         return hll.cardinality();
//     }
// 
//     public void union(HLLWrapper hll) {
//         this.hll.union(hll.hll);
//     }
// 
//     public void addAll(Collection<String> coll) {
//         for (String a : coll) {
//             byte[] s = a.getBytes();
//             hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//         }
//     }
// 
//     public void add(String obj) {
//         if (obj == null)
//             throw new IllegalArgumentException();
//         byte[] s = obj.getBytes();
// 
//         hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//     }
// 
//     public void set(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public byte[] bytes() {
//         return hll.toBytes();
//     }
// 
//     public void reset() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// }


import com.hazelcast.partition.InternalPartitionService;
import com.hazelcast.partition.MigrationEndpoint;
import com.hazelcast.spi.*;
import com.hazelcast.util.ConstructorFunction;
import org.rakam.cache.hazelcast.hyperloglog.operations.HyperLogLogReplicationOperation;
import org.rakam.util.HLLWrapper;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import static com.hazelcast.partition.strategy.StringPartitioningStrategy.getPartitionKey;
import static com.hazelcast.util.ConcurrencyUtil.getOrPutIfAbsent;
/**
 * Created by buremba <Burak Emre Kabakcı> on 10/07/14.
 */

package org.rakam.cache.hazelcast.hyperloglog;




public class HyperLogLogService implements ManagedService, RemoteService, MigrationAwareService {

    public static final String SERVICE_NAME = "rakam:hyperLogLogService";

    private NodeEngine nodeEngine;
// Path: src/main/java/org/rakam/cache/hazelcast/hyperloglog/operations/HyperLogLogReplicationOperation.java
// public class HyperLogLogReplicationOperation extends AbstractOperation implements IdentifiedDataSerializable {
// 
//     private Map<String, byte[]> migrationData;
// 
//     public HyperLogLogReplicationOperation() {
//     }
// 
//     public HyperLogLogReplicationOperation(Map<String, byte[]> migrationData) {
//         this.migrationData = migrationData;
//     }
// 
//     @Override
//     public void run() throws Exception {
//         HyperLogLogService service = getService();
//         for (Map.Entry<String, byte[]> longEntry : migrationData.entrySet()) {
//             String name = longEntry.getKey();
//             HLLWrapper number = service.getHLL(name);
//             byte[] value = longEntry.getValue();
//             number.set(value);
//         }
//     }
// 
//     @Override
//     public String getServiceName() {
//         return HyperLogLogService.SERVICE_NAME;
//     }
// 
//     @Override
//     public int getFactoryId() {
//         return HyperLogLogSerializerFactory.F_ID;
//     }
// 
//     @Override
//     public int getId() {
//         return HyperLogLogSerializerFactory.REPLICATION;
//     }
// 
//     @Override
//     protected void writeInternal(ObjectDataOutput out) throws IOException {
//         out.writeInt(migrationData.size());
//         for (Map.Entry<String, byte[]> entry : migrationData.entrySet()) {
//             out.writeUTF(entry.getKey());
//             byte[] val = entry.getValue();
//             out.writeInt(val.length);
//             out.write(val);
//         }
//     }
// 
//     @Override
//     protected void readInternal(ObjectDataInput in) throws IOException {
//         int mapSize = in.readInt();
//         migrationData = new HashMap<String, byte[]>(mapSize);
//         for (int i = 0; i < mapSize; i++) {
//             String name = in.readUTF();
//             int number = in.readInt();
//             byte[] a = new byte[number];
//             in.readFully(a);
//             migrationData.put(name, a);
//         }
//     }
// }
// 
// Path: src/main/java/org/rakam/util/HLLWrapper.java
// public class HLLWrapper {
//     final private static int SEED = 123456;
//     private HLL hll;
// 
//     public HLLWrapper() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// 
//     public HLLWrapper(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public long cardinality() {
//         return hll.cardinality();
//     }
// 
//     public void union(HLLWrapper hll) {
//         this.hll.union(hll.hll);
//     }
// 
//     public void addAll(Collection<String> coll) {
//         for (String a : coll) {
//             byte[] s = a.getBytes();
//             hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//         }
//     }
// 
//     public void add(String obj) {
//         if (obj == null)
//             throw new IllegalArgumentException();
//         byte[] s = obj.getBytes();
// 
//         hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//     }
// 
//     public void set(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public byte[] bytes() {
//         return hll.toBytes();
//     }
// 
//     public void reset() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// }


// Path: src/main/java/org/rakam/cache/hazelcast/hyperloglog/HyperLogLogService.java
import com.hazelcast.partition.InternalPartitionService;
import com.hazelcast.partition.MigrationEndpoint;
import com.hazelcast.spi.*;
import com.hazelcast.util.ConstructorFunction;
import org.rakam.cache.hazelcast.hyperloglog.operations.HyperLogLogReplicationOperation;
import org.rakam.util.HLLWrapper;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import static com.hazelcast.partition.strategy.StringPartitioningStrategy.getPartitionKey;
import static com.hazelcast.util.ConcurrencyUtil.getOrPutIfAbsent;

/**
 * Created by buremba <Burak Emre Kabakcı> on 10/07/14.
 */

package org.rakam.cache.hazelcast.hyperloglog;




public class HyperLogLogService implements ManagedService, RemoteService, MigrationAwareService {

    public static final String SERVICE_NAME = "rakam:hyperLogLogService";

    private NodeEngine nodeEngine;
    private final ConcurrentMap<String, HLLWrapper> containers = new ConcurrentHashMap<String, HLLWrapper>();