Ejemplo n.º 1
0
  private List<Cache<?, ?>> getAllCaches(Session session) {
    List<Cache<?, ?>> caches = new ArrayList<Cache<?, ?>>();
    EmbeddedCacheManager container = session.getCacheManager();
    for (String cacheName : container.getCacheNames()) {
      if (container.isRunning(cacheName)) {
        caches.add(session.getCache(cacheName));
      }
    }
    caches.add(container.getCache());

    return caches;
  }
Ejemplo n.º 2
0
 @Override
 public Result execute(Session session) {
   Cache<Object, Object> cache;
   if (keyData.getCacheName() != null) {
     cache = (Cache<Object, Object>) session.getCache(keyData.getCacheName());
   } else {
     cache = (Cache<Object, Object>) session.getCache();
   }
   if (value == null) {
     cache.remove(keyData.getKey());
   } else {
     cache.remove(keyData.getKey(), value);
   }
   return EmptyResult.RESULT;
 }
Ejemplo n.º 3
0
  @Override
  public Result execute(Session session) throws StatementException {
    boolean all = false;
    UpgradeMode mode = UpgradeMode.NONE;
    String migratorName = null;

    for (Option opt : options) {
      switch (opt.toEnum(Options.class)) {
        case ALL:
          {
            all = true;
            break;
          }
        case DUMPKEYS:
          {
            mode = UpgradeMode.DUMPKEYS;
            break;
          }
        case SYNCHRONIZE:
          {
            mode = UpgradeMode.SYNCHRONIZE;
            migratorName = opt.getParameter();
            if (migratorName == null) {
              throw log.missingMigrator();
            }
            break;
          }
        case DISCONNECTSOURCE:
          {
            mode = UpgradeMode.DISCONNECTSOURCE;
            migratorName = opt.getParameter();
            if (migratorName == null) {
              throw log.missingMigrator();
            }
          }
      }
    }
    StringBuilder sb = new StringBuilder();
    switch (mode) {
      case DUMPKEYS:
        {
          for (Cache<?, ?> cache :
              all
                  ? getAllCaches(session)
                  : Collections.singletonList(session.getCache(cacheName))) {
            RollingUpgradeManager upgradeManager =
                cache
                    .getAdvancedCache()
                    .getComponentRegistry()
                    .getComponent(RollingUpgradeManager.class);
            upgradeManager.recordKnownGlobalKeyset();
            sb.append(MSG.dumpedKeys(cache.getName()));
            sb.append("\n");
          }
          break;
        }
      case SYNCHRONIZE:
        {
          for (Cache<?, ?> cache :
              all
                  ? getAllCaches(session)
                  : Collections.singletonList(session.getCache(cacheName))) {
            RollingUpgradeManager upgradeManager =
                cache
                    .getAdvancedCache()
                    .getComponentRegistry()
                    .getComponent(RollingUpgradeManager.class);
            try {
              long count = upgradeManager.synchronizeData(migratorName);
              sb.append(MSG.synchronizedEntries(count, migratorName, cache.getName()));
              sb.append("\n");
            } catch (Exception e) {
              throw log.dataSynchronizationError(e, migratorName, cache.getName());
            }
          }
          break;
        }
      case DISCONNECTSOURCE:
        {
          for (Cache<?, ?> cache :
              all
                  ? getAllCaches(session)
                  : Collections.singletonList(session.getCache(cacheName))) {
            RollingUpgradeManager upgradeManager =
                cache
                    .getAdvancedCache()
                    .getComponentRegistry()
                    .getComponent(RollingUpgradeManager.class);
            try {
              upgradeManager.disconnectSource(migratorName);
              sb.append(MSG.disonnectedSource(migratorName, cache.getName()));
              sb.append("\n");
            } catch (Exception e) {
              throw log.sourceDisconnectionError(e, migratorName, cache.getName());
            }
          }
          break;
        }
      default:
        {
          throw log.missingUpgradeAction();
        }
    }
    return new StringResult(sb.toString());
  }