/** {@inheritDoc} */
  @Override
  protected GridConfiguration getConfiguration(String gridName) throws Exception {
    GridConfiguration cfg = super.getConfiguration(gridName);

    GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi();

    disco.setMaxMissedHeartbeats(Integer.MAX_VALUE);
    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    if (gridName.endsWith("1")) cfg.setCacheConfiguration(); // Empty cache configuration.
    else {
      assert gridName.endsWith("2");

      GridCacheConfiguration cacheCfg = defaultCacheConfiguration();

      cacheCfg.setCacheMode(PARTITIONED);
      cacheCfg.setBackups(1);

      cfg.setCacheConfiguration(cacheCfg);
    }

    return cfg;
  }
  /** {@inheritDoc} */
  @Override
  protected GridCacheConfiguration cacheConfiguration(String gridName) throws Exception {
    GridCacheConfiguration cfg = super.cacheConfiguration(gridName);

    cfg.setCacheMode(PARTITIONED);
    cfg.setBackups(1);
    cfg.setWriteSynchronizationMode(FULL_SYNC);

    return cfg;
  }
  /** @return Cache configuration. */
  private GridCacheConfiguration cacheConfiguration() {
    GridCacheConfiguration cfg = new GridCacheConfiguration();

    cfg.setBackups(backups);

    cfg.setCacheMode(GridCacheMode.PARTITIONED);

    cfg.setDistributionMode(GridCacheDistributionMode.PARTITIONED_ONLY);

    cfg.setAffinity(new GridCachePartitionFairAffinity(parts));

    return cfg;
  }
  /** {@inheritDoc} */
  protected GridCacheConfiguration cacheConfiguration(String cacheName) {
    GridCacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setName(cacheName);

    if (META_CACHE_NAME.equals(cacheName)) cacheCfg.setCacheMode(REPLICATED);
    else {
      cacheCfg.setCacheMode(PARTITIONED);
      cacheCfg.setDistributionMode(GridCacheDistributionMode.PARTITIONED_ONLY);

      cacheCfg.setBackups(0);
      cacheCfg.setAffinityMapper(new GridGgfsGroupDataBlocksKeyMapper(CFG_GRP_SIZE));
    }

    cacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setQueryIndexEnabled(false);

    return cacheCfg;
  }
  /**
   * @param cacheName Cache name.
   * @return Cache configuration.
   * @throws Exception In case of error.
   */
  private GridCacheConfiguration cacheConfiguration(@Nullable String cacheName) throws Exception {
    GridCacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setDistributionMode(NEAR_PARTITIONED);

    if (cacheName == null) cfg.setCacheMode(LOCAL);
    else if (PARTITIONED_CACHE_NAME.equals(cacheName)) {
      cfg.setCacheMode(PARTITIONED);

      cfg.setBackups(0);
    } else cfg.setCacheMode(REPLICATED);

    cfg.setName(cacheName);

    cfg.setWriteSynchronizationMode(
        REPLICATED_ASYNC_CACHE_NAME.equals(cacheName) ? FULL_ASYNC : FULL_SYNC);

    return cfg;
  }
  /**
   * Gets cache configuration.
   *
   * @return Cache configuration.
   */
  private GridCacheConfiguration[] cacheConfiguration() {
    GridCacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setName("partitioned");
    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setDistributionMode(GridCacheDistributionMode.PARTITIONED_ONLY);
    cacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setAffinityMapper(new GridGgfsGroupDataBlocksKeyMapper(GRP_SIZE));
    cacheCfg.setBackups(0);
    cacheCfg.setQueryIndexEnabled(false);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);

    GridCacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setName("replicated");
    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setQueryIndexEnabled(false);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    return new GridCacheConfiguration[] {metaCacheCfg, cacheCfg};
  }