// Path: src/main/java/org/rakam/cache/hazelcast/treemap/TreeMapService.java
// public class TreeMapService implements ManagedService, RemoteService, MigrationAwareService {
// 
//     public static final String SERVICE_NAME = "rakam:treeMapService";
// 
//     private NodeEngine nodeEngine;
//     private final ConcurrentMap<String, OrderedCounterMap> containers = new ConcurrentHashMap<String, OrderedCounterMap>();
//     private final ConstructorFunction<String, OrderedCounterMap> CountersConstructorFunction =
//             new ConstructorFunction<String, OrderedCounterMap>() {
//                 public OrderedCounterMap createNew(String key) {
//                     return new OrderedCounterMap();
//                 }
//             };
// 
//     public TreeMapService() {
//     }
// 
//     public OrderedCounterMap getHLL(String name) {
//         return getOrPutIfAbsent(containers, name, CountersConstructorFunction);
//     }
// 
//     public void setHLL(String name, OrderedCounterMap map) {
//         containers.put(name, map);
//     }
// 
//     @Override
//     public void init(NodeEngine nodeEngine, Properties properties) {
//         this.nodeEngine = nodeEngine;
//     }
// 
//     @Override
//     public void reset() {
//         containers.clear();
//     }
// 
//     @Override
//     public void shutdown(boolean terminate) {
//         reset();
//     }
// 
//     @Override
//     public TreeMapProxy createDistributedObject(String name) {
//         return new TreeMapProxy(name, nodeEngine, this);
//     }
// 
//     @Override
//     public void destroyDistributedObject(String name) {
//         containers.remove(name);
//     }
// 
//     @Override
//     public void beforeMigration(PartitionMigrationEvent partitionMigrationEvent) {
//     }
// 
//     @Override
//     public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
//         Map<String, OrderedCounterMap> data = new HashMap();
//         int partitionId = event.getPartitionId();
//         for (String name : containers.keySet()) {
//             if (partitionId == getPartitionId(name)) {
//                 OrderedCounterMap number = containers.get(name);
//                 data.put(name, number);
//             }
//         }
//         return data.isEmpty() ? null : new TreeMapReplicationOperation(data);
//     }
// 
//     private int getPartitionId(String name) {
//         InternalPartitionService partitionService = nodeEngine.getPartitionService();
//         String partitionKey = getPartitionKey(name);
//         return partitionService.getPartitionId(partitionKey);
//     }
// 
//     @Override
//     public void commitMigration(PartitionMigrationEvent partitionMigrationEvent) {
//         if (partitionMigrationEvent.getMigrationEndpoint() == MigrationEndpoint.SOURCE) {
//             removePartition(partitionMigrationEvent.getPartitionId());
//         }
//     }
// 
//     @Override
//     public void rollbackMigration(PartitionMigrationEvent partitionMigrationEvent) {
//         if (partitionMigrationEvent.getMigrationEndpoint() == MigrationEndpoint.DESTINATION) {
//             removePartition(partitionMigrationEvent.getPartitionId());
//         }
//     }
// 
//     @Override
//     public void clearPartitionReplica(int partitionId) {
//         removePartition(partitionId);
//     }
// 
//     public void removePartition(int partitionId) {
//         final Iterator<String> iterator = containers.keySet().iterator();
//         while (iterator.hasNext()) {
//             String name = iterator.next();
//             if (getPartitionId(name) == partitionId) {
//                 iterator.remove();
//             }
//         }
//     }
// }


import com.hazelcast.client.ClientEngine;
import com.hazelcast.client.PartitionClientRequest;
import com.hazelcast.client.SecureRequest;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.nio.serialization.Portable;
import com.hazelcast.nio.serialization.PortableReader;
import com.hazelcast.nio.serialization.PortableWriter;
import com.hazelcast.security.permission.ActionConstants;
import com.hazelcast.security.permission.AtomicLongPermission;
import org.rakam.cache.hazelcast.treemap.TreeMapService;
import java.io.IOException;
import java.security.Permission;
/**
 * Created by buremba <Burak Emre Kabakcı> on 10/07/14.
 */

package org.rakam.cache.hazelcast.treemap.client;



public abstract class ReadRequest extends PartitionClientRequest implements Portable, SecureRequest {

    protected String name;

    public ReadRequest() {
    }

    public ReadRequest(String name) {
        this.name = name;
    }

    @Override
    protected int getPartition() {
        ClientEngine clientEngine = getClientEngine();
        //Data key = serializationService.toData(name);
        Data key = clientEngine.getSerializationService().toData(name);
        return clientEngine.getPartitionService().getPartitionId(key);
    }

    @Override
    public String getServiceName() {
        return TreeMapService.SERVICE_NAME;
    }

    @Override
    public int getFactoryId() {
        return TreeMapPortableFactory.F_ID;
    }

// Path: src/main/java/org/rakam/cache/hazelcast/treemap/TreeMapService.java
// public class TreeMapService implements ManagedService, RemoteService, MigrationAwareService {
// 
//     public static final String SERVICE_NAME = "rakam:treeMapService";
// 
//     private NodeEngine nodeEngine;
//     private final ConcurrentMap<String, OrderedCounterMap> containers = new ConcurrentHashMap<String, OrderedCounterMap>();
//     private final ConstructorFunction<String, OrderedCounterMap> CountersConstructorFunction =
//             new ConstructorFunction<String, OrderedCounterMap>() {
//                 public OrderedCounterMap createNew(String key) {
//                     return new OrderedCounterMap();
//                 }
//             };
// 
//     public TreeMapService() {
//     }
// 
//     public OrderedCounterMap getHLL(String name) {
//         return getOrPutIfAbsent(containers, name, CountersConstructorFunction);
//     }
// 
//     public void setHLL(String name, OrderedCounterMap map) {
//         containers.put(name, map);
//     }
// 
//     @Override
//     public void init(NodeEngine nodeEngine, Properties properties) {
//         this.nodeEngine = nodeEngine;
//     }
// 
//     @Override
//     public void reset() {
//         containers.clear();
//     }
// 
//     @Override
//     public void shutdown(boolean terminate) {
//         reset();
//     }
// 
//     @Override
//     public TreeMapProxy createDistributedObject(String name) {
//         return new TreeMapProxy(name, nodeEngine, this);
//     }
// 
//     @Override
//     public void destroyDistributedObject(String name) {
//         containers.remove(name);
//     }
// 
//     @Override
//     public void beforeMigration(PartitionMigrationEvent partitionMigrationEvent) {
//     }
// 
//     @Override
//     public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
//         Map<String, OrderedCounterMap> data = new HashMap();
//         int partitionId = event.getPartitionId();
//         for (String name : containers.keySet()) {
//             if (partitionId == getPartitionId(name)) {
//                 OrderedCounterMap number = containers.get(name);
//                 data.put(name, number);
//             }
//         }
//         return data.isEmpty() ? null : new TreeMapReplicationOperation(data);
//     }
// 
//     private int getPartitionId(String name) {
//         InternalPartitionService partitionService = nodeEngine.getPartitionService();
//         String partitionKey = getPartitionKey(name);
//         return partitionService.getPartitionId(partitionKey);
//     }
// 
//     @Override
//     public void commitMigration(PartitionMigrationEvent partitionMigrationEvent) {
//         if (partitionMigrationEvent.getMigrationEndpoint() == MigrationEndpoint.SOURCE) {
//             removePartition(partitionMigrationEvent.getPartitionId());
//         }
//     }
// 
//     @Override
//     public void rollbackMigration(PartitionMigrationEvent partitionMigrationEvent) {
//         if (partitionMigrationEvent.getMigrationEndpoint() == MigrationEndpoint.DESTINATION) {
//             removePartition(partitionMigrationEvent.getPartitionId());
//         }
//     }
// 
//     @Override
//     public void clearPartitionReplica(int partitionId) {
//         removePartition(partitionId);
//     }
// 
//     public void removePartition(int partitionId) {
//         final Iterator<String> iterator = containers.keySet().iterator();
//         while (iterator.hasNext()) {
//             String name = iterator.next();
//             if (getPartitionId(name) == partitionId) {
//                 iterator.remove();
//             }
//         }
//     }
// }


// Path: src/main/java/org/rakam/cache/hazelcast/treemap/client/ReadRequest.java
import com.hazelcast.client.ClientEngine;
import com.hazelcast.client.PartitionClientRequest;
import com.hazelcast.client.SecureRequest;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.nio.serialization.Portable;
import com.hazelcast.nio.serialization.PortableReader;
import com.hazelcast.nio.serialization.PortableWriter;
import com.hazelcast.security.permission.ActionConstants;
import com.hazelcast.security.permission.AtomicLongPermission;
import org.rakam.cache.hazelcast.treemap.TreeMapService;
import java.io.IOException;
import java.security.Permission;

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

package org.rakam.cache.hazelcast.treemap.client;



public abstract class ReadRequest extends PartitionClientRequest implements Portable, SecureRequest {

    protected String name;

    public ReadRequest() {
    }

    public ReadRequest(String name) {
        this.name = name;
    }

    @Override
    protected int getPartition() {
        ClientEngine clientEngine = getClientEngine();
        //Data key = serializationService.toData(name);
        Data key = clientEngine.getSerializationService().toData(name);
        return clientEngine.getPartitionService().getPartitionId(key);
    }

    @Override
    public String getServiceName() {
        return TreeMapService.SERVICE_NAME;
    }

    @Override
    public int getFactoryId() {
        return TreeMapPortableFactory.F_ID;
    }

    @Override