/**
   * Version-dependent support for generating a dummy disk store from the given cache and disk store
   * configuration.
   */
  protected static void generateDummyDiskStore(
      Cache dummyCache, String diskStoreConfig, String fn, Map XmlDiskStoreConfigs) {
    DiskStoreDescription dsd = DiskStoreHelper.getDiskStoreDescription(diskStoreConfig);
    DiskStoreFactory dummyFactory = ((CacheCreation) dummyCache).createDiskStoreFactory();
    dsd.configure(dummyFactory);
    String diskStoreName = dsd.getName();
    DiskStore dummyDiskStore = null;
    try {
      dummyDiskStore = dummyFactory.create(diskStoreName);
    } catch (IllegalStateException e) {
      String msg = "A disk store named \"" + diskStoreName + "\" already exists.";
      if (e.getMessage().equals(msg)) {
        if (!XmlDiskStoreConfigs.values().contains(diskStoreConfig)) {
          String s =
              "DiskStore with configuration "
                  + diskStoreConfig
                  + " named "
                  + diskStoreName
                  + " was already created without CacheHelper XML using"
                  + " an unknown, and possibly different, configuration";
          throw new HydraRuntimeException(s);
        } // else the configuration was done here, which is fine
      } else {
        throw e;
      }
    }
    if (Log.getLogWriter().infoEnabled()) {
      Log.getLogWriter()
          .info("Added dummy disk store: " + DiskStoreHelper.diskStoreToString(dummyDiskStore));
    }

    // save the disk store config for future reference
    XmlDiskStoreConfigs.put(fn, diskStoreConfig);
  }
  /**
   * Version-dependent support for configuring a cache factory from the the given cache
   * configuration and distributed system.
   */
  protected static Cache configureAndCreateCache(
      String cacheConfig, CacheDescription cd, DistributedSystem ds) {
    // configure the cache factory
    CacheFactory f = new CacheFactory();
    Log.getLogWriter().info("Configuring cache factory from config: " + cacheConfig);
    cd.configure(f);

    // create the cache
    Log.getLogWriter().info("Creating cache");
    return f.create();
  }
  /**
   * Version-dependent support for generating a dummy gateway sender from the given cache and
   * gateway sender configuration.
   */
  protected static void generateDummyGatewaySender(
      Cache dummyCache, String gatewaySenderConfig, String fn, Map XmlGatewaySenderConfigs) {
    String localds = DistributedSystemHelper.getDistributedSystemName();
    GatewaySenderDescription gsd =
        GatewaySenderHelper.getGatewaySenderDescription(gatewaySenderConfig);
    Set<String> remoteDistributedSystems = gsd.getRemoteDistributedSystems();
    if (remoteDistributedSystems.size() > 0) {
      GatewaySenderFactory dummyFactory = ((CacheCreation) dummyCache).createGatewaySenderFactory();
      gsd.configure(dummyFactory);
      for (String remoteds : remoteDistributedSystems) {
        String id = gsd.getName() + "_" + localds + "_to_" + remoteds;
        int remoteid = DistributedSystemHelper.getDistributedSystemId(remoteds);
        GatewaySender dummyGatewaySender = null;
        try {
          dummyGatewaySender = dummyFactory.create(id, remoteid);
          GatewaySenderHelper.saveGatewaySenderId(gsd.getName(), gsd.getParallel(), id);
        } catch (IllegalStateException e) {
          String msg = "A gateway sender named \"" + id + "\" already exists.";
          if (e.getMessage().equals(msg)) {
            if (!XmlGatewaySenderConfigs.values().contains(gatewaySenderConfig)) {
              String s =
                  "GatewaySender with configuration "
                      + gatewaySenderConfig
                      + " named "
                      + id
                      + " was already created without CacheHelper XML using"
                      + " an unknown, and possibly different, configuration";
              throw new HydraRuntimeException(s);
            } // else the configuration was done here, which is fine
          } else {
            throw e;
          }
        }
        if (Log.getLogWriter().infoEnabled()) {
          Log.getLogWriter()
              .info(
                  "Added dummy gateway sender: "
                      + GatewaySenderHelper.gatewaySenderToString(dummyGatewaySender));
        }
      }
      // save the gateway sender config for future reference
      XmlGatewaySenderConfigs.put(fn, gatewaySenderConfig);

    } else {
      Log.getLogWriter().info("No remote distributed systems found");
    }
  }
 /**
  * Version-dependent support for generating a dummy async event queue from the given cache and
  * async event queue configuration.
  */
 protected static void generateDummyAsyncEventQueue(
     Cache dummyCache, String asyncEventQueueConfig, String fn, Map XmlAsyncEventQueueConfigs) {
   AsyncEventQueueDescription aeqd =
       AsyncEventQueueHelper.getAsyncEventQueueDescription(asyncEventQueueConfig);
   Log.getLogWriter().info("Creating dummy async event queue for " + aeqd.getName());
   AsyncEventQueueFactory dummyFactory =
       ((CacheCreation) dummyCache).createAsyncEventQueueFactory();
   aeqd.configure(dummyFactory);
   AsyncEventQueue dummyAsyncEventQueue =
       dummyFactory.create(aeqd.getName(), aeqd.getAsyncEventListenerInstance());
   if (Log.getLogWriter().infoEnabled()) {
     Log.getLogWriter()
         .info(
             "Added dummy async event queue: "
                 + AsyncEventQueueHelper.asyncEventQueueToString(dummyAsyncEventQueue));
   }
   // save the async event queue config for future reference
   XmlAsyncEventQueueConfigs.put(fn, asyncEventQueueConfig);
 }
 /**
  * Version-dependent support for generating a dummy gateway receiver from the given cache and
  * gateway receiver configuration.
  */
 protected static void generateDummyGatewayReceiver(
     Cache dummyCache, String gatewayReceiverConfig, String fn, Map XmlGatewayReceiverConfigs) {
   GatewayReceiverDescription grd =
       GatewayReceiverHelper.getGatewayReceiverDescription(gatewayReceiverConfig);
   int numInstances = grd.getNumInstances();
   Log.getLogWriter()
       .info("Creating " + numInstances + " dummy gateway receivers for " + grd.getName());
   GatewayReceiverFactory dummyFactory =
       ((CacheCreation) dummyCache).createGatewayReceiverFactory();
   grd.configure(dummyFactory);
   for (int i = 0; i < numInstances; i++) {
     GatewayReceiver dummyGatewayReceiver = dummyFactory.create();
     if (Log.getLogWriter().infoEnabled()) {
       Log.getLogWriter()
           .info(
               "Added dummy gateway receiver: "
                   + GatewayReceiverHelper.gatewayReceiverToString(dummyGatewayReceiver));
     }
   }
   // save the gateway receiver config for future reference
   XmlGatewayReceiverConfigs.put(fn, gatewayReceiverConfig);
 }
/** Provides support for async event queues running in hydra-managed client VMs. */
public class AsyncEventQueueHelper {

  private static LogWriter log = Log.getLogWriter();

  // ------------------------------------------------------------------------------
  // AsyncEventQueue
  // ------------------------------------------------------------------------------

  /**
   * Creates and starts an async event queue in the current cache. The queue is configured using the
   * {@link AsyncEventQueueDescription} corresponding to the given configuration from {@link
   * AsyncEventQueuePrms#names}. The id for the queue is the same as the queue configuration name.
   *
   * <p>This method is thread-safe. The async event queues for a given logical queue configuration
   * will only be created once.
   *
   * @throws HydraRuntimeException if an attempt is made to reconfigure an existing async event
   *     queue.
   */
  public static synchronized AsyncEventQueue createAndStartAsyncEventQueue(
      String asyncEventQueueConfig) {
    AsyncEventQueue queue = getAsyncEventQueue(asyncEventQueueConfig);
    if (queue == null) {

      // get the cache
      Cache cache = CacheHelper.getCache();
      if (cache == null) {
        String s = "Cache has not been created yet";
        throw new HydraRuntimeException(s);
      }

      // look up the async event queue configuration
      AsyncEventQueueDescription aeqd = getAsyncEventQueueDescription(asyncEventQueueConfig);

      // create the disk store
      DiskStoreHelper.createDiskStore(aeqd.getDiskStoreDescription().getName());

      // create the async event queue
      queue = createAsyncEventQueue(aeqd, cache);
    }
    return queue;
  }

  private static AsyncEventQueue createAsyncEventQueue(
      AsyncEventQueueDescription aeqd, Cache cache) {
    // configure the factory
    AsyncEventQueueFactory f = cache.createAsyncEventQueueFactory();
    log.info("Configuring async event queue factory");
    aeqd.configure(f);
    log.info("Configured async event queue factory " + f);

    // create the async event queue
    log.info("Creating and starting async event queue " + aeqd.getName());
    AsyncEventQueue queue = f.create(aeqd.getName(), aeqd.getAsyncEventListenerInstance());
    log.info("Created and started async event queue: " + asyncEventQueueToString(queue));
    return queue;
  }

  /**
   * Returns the async event queues for the current cache, or null if no async event queues or cache
   * exists.
   */
  public static Set<AsyncEventQueue> getAsyncEventQueues() {
    Cache cache = CacheHelper.getCache();
    if (cache == null) {
      return null;
    } else {
      Set<AsyncEventQueue> queues = cache.getAsyncEventQueues();
      return (queues == null || queues.size() == 0) ? null : queues;
    }
  }

  /**
   * Returns the async event queue for the current cache matching the given async event queue id, or
   * null if no matching id exists.
   */
  public static AsyncEventQueue getAsyncEventQueue(String queueID) {
    Set<AsyncEventQueue> queues = getAsyncEventQueues();
    if (queues != null) {
      for (AsyncEventQueue queue : queues) {
        if (queue.getId().equals(queueID)) {
          return queue;
        }
      }
    }
    return null;
  }

  /** Returns the given async event queue as a string. */
  public static String asyncEventQueueToString(AsyncEventQueue aeq) {
    return AsyncEventQueueDescription.asyncEventQueueToString(aeq);
  }

  // ------------------------------------------------------------------------------
  // AsyncEventQueueDescription
  // ------------------------------------------------------------------------------

  /**
   * Returns the {@link AsyncEventQueueDescription} with the given configuration name from {@link
   * AsyncEventQueuePrms#names}.
   */
  public static AsyncEventQueueDescription getAsyncEventQueueDescription(
      String asyncEventQueueConfig) {
    if (asyncEventQueueConfig == null) {
      throw new IllegalArgumentException("asyncEventQueueConfig cannot be null");
    }
    log.info("Looking up async event queue config: " + asyncEventQueueConfig);
    AsyncEventQueueDescription aeqd =
        TestConfig.getInstance().getAsyncEventQueueDescription(asyncEventQueueConfig);
    if (aeqd == null) {
      String s =
          asyncEventQueueConfig + " not found in " + BasePrms.nameForKey(AsyncEventQueuePrms.names);
      throw new HydraRuntimeException(s);
    }
    log.info("Looked up async event queue config:\n" + aeqd);
    return aeqd;
  }
}
Пример #7
0
 /** Convenience method for reading the list of operations for the current client thread. */
 public static OpList getOpList() {
   Object key = OpListKey + Thread.currentThread().getName();
   OpList opList = (OpList) (AsyncMsgBB.getBB().getSharedMap().get(key));
   Log.getLogWriter().info("AsyncBB read from shared map key " + key + ", value " + opList);
   return opList;
 }
Пример #8
0
 /** Convenience method for writing a list of operations for the current client thread. */
 public static void putOpList(OpList opList) {
   Object key = OpListKey + Thread.currentThread().getName();
   AsyncMsgBB.getBB().getSharedMap().put(key, opList);
   Log.getLogWriter().info("AsyncBB put into shared map key " + key + ", value " + opList);
 }