All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.internal.communication.DistributedPartitioningStrategy Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
package com.alachisoft.ncache.client.internal.communication;

import Alachisoft.NCache.Common.Extensibility.Client.RPC.Partition;
import Alachisoft.NCache.Common.Extensibility.Client.RPC.PartitioningStrategy;
import Alachisoft.NCache.Common.Net.Address;

class DistributedPartitioningStrategy extends PartitioningStrategy {
    private Broker _broker;
    private java.util.HashMap _partitionMap = new java.util.HashMap();

    public DistributedPartitioningStrategy(Broker broker) {
        this._broker = broker;
    }

    @Override
    public Iterable GetAllPartitions() {
        _broker._hashMapStatus.WaitForAny(HashMapStatus.INITIALIZE);
        return _broker.getPool().getPartitins();
    }

    @Override
    public Partition GetDestinationPartition(String cacheKey) {
        _broker._hashMapStatus.WaitForAny(HashMapStatus.INITIALIZE);
        Address server = _broker.getPool().GetIp(cacheKey);
        Partition partition = null;

        //we are caching partition to avoid new object creation. This map does not represent actual current distribution and
        //servers as a cache only
        if (!((partition = _partitionMap.get(server)) != null)) {
            partition.setAddress(server);
            synchronized (_partitionMap) {
                if (!_partitionMap.containsKey(server)) {
                    _partitionMap.put(server, partition);
                }
            }
        }
        return partition;
    }

    @Override
    public boolean PartitionExists(Partition partition) {
        java.util.ArrayList pool = _broker.getPool().getPartitins();

        for (int i = 0; i < pool.size(); i++) {
            if (pool.get(i).getAddress().getIpAddress().toString().equals(partition.getAddress().getIpAddress().toString())) {
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy