Package org.infinispan.distribution

Examples of org.infinispan.distribution.DistributionManager


        this.isLocal(DataLocality.NOT_LOCAL, false);
        this.isLocal(DataLocality.NOT_LOCAL_UNCERTAIN, true);
    }

    private void isLocal(DataLocality locality, boolean local) {
        DistributionManager distManager = mock(DistributionManager.class);
        String sessionId = "ABC123";

        when(this.cache.getAdvancedCache()).thenReturn(this.cache);

        if (locality != null) {
            when(this.cache.getDistributionManager()).thenReturn(distManager);
            when(distManager.getLocality(sessionId)).thenReturn(locality);
        } else {
            when(this.cache.getDistributionManager()).thenReturn(null);
        }

        boolean result = this.manager.isLocal(sessionId);
View Full Code Here


        String result = this.manager.locate(sessionId);

        assertSame(expected, result);

        // Test rehash in progress
        DistributionManager distManager = mock(DistributionManager.class);

        when(this.cache.getAdvancedCache()).thenReturn(this.cache);
        when(this.cache.getDistributionManager()).thenReturn(distManager);
        when(distManager.getLocality(sessionId)).thenReturn(DataLocality.NOT_LOCAL_UNCERTAIN);
        when(this.sessionManager.getJvmRoute()).thenReturn(expected);

        result = this.manager.locate(sessionId);

        assertSame(expected, result);

        // Test session hashes locally
        EmbeddedCacheManager container = mock(EmbeddedCacheManager.class);
        Address address1 = mock(Address.class);
        Address address2 = mock(Address.class);
        Address localAddress = mock(Address.class);
        List<Address> addresses = Arrays.asList(address1, address2, localAddress);

        when(this.cache.getAdvancedCache()).thenReturn(this.cache);
        when(this.cache.getDistributionManager()).thenReturn(distManager);
        when(distManager.getLocality(sessionId)).thenReturn(DataLocality.LOCAL);
        when(distManager.locate(same(sessionId))).thenReturn(addresses);
        when(this.cache.getCacheManager()).thenReturn(container);
        when(container.getAddress()).thenReturn(address2);
        when(this.sessionManager.getJvmRoute()).thenReturn(expected);

        result = this.manager.locate(sessionId);

        assertSame(expected, result);

        // Test session does not hash locally
        addresses = Arrays.asList(address1, address2);
        ArgumentCaptor<Address> capturedAddress = ArgumentCaptor.forClass(Address.class);

        when(this.cache.getAdvancedCache()).thenReturn(this.cache);
        when(this.cache.getDistributionManager()).thenReturn(distManager);
        when(distManager.getLocality(sessionId)).thenReturn(DataLocality.NOT_LOCAL);
        when(distManager.locate(same(sessionId))).thenReturn(addresses);
        when(this.cache.getCacheManager()).thenReturn(container);
        when(container.getAddress()).thenReturn(localAddress);
        when(this.registry.getRemoteEntry(capturedAddress.capture())).thenReturn(new AbstractMap.SimpleImmutableEntry<String, Void>(expected, null));
        when(this.cache.withFlags(Flag.FORCE_SYNCHRONOUS)).thenReturn(this.cache);
View Full Code Here

   public JoinHandle howToHandle(CacheRpcCommand cmd) {
      Configuration localConfig = cmd.getConfiguration();
      ComponentRegistry cr = cmd.getComponentRegistry();

      if (localConfig.getCacheMode().isDistributed()) {
         DistributionManager dm = cr.getComponent(DistributionManager.class);
         if (dm.isJoinComplete())
            return JoinHandle.OK;
         else {
            // no point in enqueueing clustered GET commands - just ignore these and hope someone else in the cluster responds.
            if (!(cmd instanceof ClusteredGetCommand))
               return JoinHandle.QUEUE;
View Full Code Here

        }
        return (entry != null) ? entry.getKey() : null;
    }

    private Address locatePrimaryOwner(String sessionId) {
        DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager();
        return (dist != null) ? dist.getPrimaryLocation(sessionId) : this.cache.getCacheManager().getAddress();
    }
View Full Code Here

            MapCombineCommand<KIn, VIn, KOut, VOut> mcc) throws InterruptedException {
      Cache<KIn, VIn> cache = cacheManager.getCache(mcc.getCacheName());
      Set<KIn> keys = mcc.getKeys();
      Set<KIn> inputKeysCopy = null;
      Mapper<KIn, VIn, KOut, VOut> mapper = mcc.getMapper();
      DistributionManager dm = cache.getAdvancedCache().getDistributionManager();     
      boolean inputKeysSpecified = keys != null && !keys.isEmpty();
      Set <KIn> inputKeys = keys;     
      if (!inputKeysSpecified) {
         inputKeys = filterLocalPrimaryOwner(cache.keySet(), dm);
      } else {
View Full Code Here

      }
      if (tmpCache == null) {
         throw new IllegalStateException("Temporary cache for MapReduceTask " + taskId
                  + " not found on " + localAddress);
      }
      DistributionManager dm = tmpCache.getAdvancedCache().getDistributionManager();

      if (combiner != null) {
         Cache<?, ?> cache = cacheManager.getCache(mcc.getCacheName());
         log.tracef("For m/r task %s invoking combiner %s at %s",  taskId, mcc, localAddress);
         MapReduceTaskLifecycleService taskLifecycleService = MapReduceTaskLifecycleService.getInstance();
View Full Code Here

   private List<Address> getExistingNodes() {
      return cache.getAdvancedCache().getRpcManager().getTransport().getMembers();
   }

   private Address getAddressForKey(Object key) {
      DistributionManager distributionManager = getDistributionManager();
      ConsistentHash hash = distributionManager.getConsistentHash();
      return hash.locatePrimaryOwner(key);
   }
View Full Code Here

      ConsistentHash hash = distributionManager.getConsistentHash();
      return hash.locatePrimaryOwner(key);
   }

   private boolean isNodeInConsistentHash(Address address) {
      DistributionManager distributionManager = getDistributionManager();
      ConsistentHash hash = distributionManager.getConsistentHash();
      return hash.getMembers().contains(address);
   }
View Full Code Here

      DistributionManager distributionManager = getDistributionManager();
      ConsistentHash hash = distributionManager.getConsistentHash();
      return hash.getMembers().contains(address);
   }
   private DistributionManager getDistributionManager() {
      DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager();
      if (distributionManager == null) {
         throw new IllegalStateException("Null distribution manager. Is this an distributed(v.s. replicated) cache?");
      }
      return distributionManager;
   }
View Full Code Here

         throw new IllegalStateException("Temporary cache for MapReduceTask " + taskId
                  + " named " + tmpCacheName + " not found on " + cdl.getAddress());
      }

      Set<KOut> mapPhaseKeys = new HashSet<KOut>();
      DistributionManager dm = tmpCache.getAdvancedCache().getDistributionManager();
      Map<Address, List<KOut>> keysToNodes = mapKeysToNodes(dm, taskId, collectedValues.keySet());
      long start = log.isTraceEnabled() ? timeService.time() : 0;
      tmpCache = tmpCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES);
      try {
         for (Entry<Address, List<KOut>> entry : keysToNodes.entrySet()) {
View Full Code Here

TOP

Related Classes of org.infinispan.distribution.DistributionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.