/**
  * Shuts downs the caching service.
  *
  * @param container Reference to the container.
  */
 public static void shutdown(Container container) {
   // NB: this can't be called outside of container b/c agents have no refs
   // to the singleton container. So we can be sure this method is going to
   // create services just once.
   if (container == null) return;
   Registry reg = container.getRegistry();
   ((CacheServiceImpl) reg.getCacheService()).shutDown();
 }
  /**
   * Creates a new {@link CacheService}.
   *
   * @param container Reference to the container.
   * @return See above.
   */
  public static CacheService makeNew(Container container) {
    // NB: this can't be called outside of container b/c agents have no refs
    // to the singleton container. So we can be sure this method is going to
    // create services just once.
    if (container == null) return null;
    // If caching is off, then we return the no-op adapter.
    Registry reg = container.getRegistry();
    Boolean isCachingOn = (Boolean) reg.lookup(LookupNames.CACHE_ON);
    if (!isCachingOn.booleanValue()) return makeNoOpCache();

    // Ok we have to cache, so try and read the config file.
    InputStream config = loadConfig(container.getConfigFileRelative(CACHE_CONFIG_FILE));
    if (config == null) return makeNoOpCache();

    // We have a config file, set up ehcache.
    CacheService cache = new CacheServiceImpl(config, container.getRegistry().getLogger());
    try {
      config.close();
    } catch (Exception e) {
    }
    return cache;
  }
 /**
  * Creates a new instance. This can't be called outside of container b/c agents have no refs to
  * the singleton container. So we can be sure this method is going to create services just once.
  *
  * @param c Reference to the container.
  * @return The sole instance.
  * @throws NullPointerException If the reference to the {@link Container} is <code>null</code>.
  */
 public static PixelsServicesFactory getInstance(Container c) {
   if (c == null) throw new NullPointerException(); // An agent called this method?
   if (singleton == null) {
     registry = c.getRegistry();
     singleton = new PixelsServicesFactory();
     // Retrieve the maximum heap size.
     MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
     String message = "Heap memory usage: max " + usage.getMax();
     registry.getLogger().info(singleton, message);
     // percentage of memory used for caching.
     maxSize = (int) (RATIO * usage.getMax()) / FACTOR;
   }
   return singleton;
 }