Package er.extensions.concurrency

Source Code of er.extensions.concurrency.ERXTaskObjectStoreCoordinatorPool

package er.extensions.concurrency;

import com.webobjects.eocontrol.EOObjectStoreCoordinator;
import com.webobjects.foundation.NSMutableArray;

import er.extensions.eof.ERXObjectStoreCoordinator;
import er.extensions.foundation.ERXProperties;
import er.extensions.foundation.ERXRoundRobinCollection;

/**
* A class that manages a pool of object store coordinators for background tasks.
* Such a pool is useful to prevent intensive EOF activity of background tasks
* interfering with normal use page browsing.
*
* The default pool size is one. More can be set using the property
* <code>er.extensions.concurrency.ERXTaskObjectStoreCoordinatorPool.maxCoordinators</code>
*
* @author kieran
*
*/
public class ERXTaskObjectStoreCoordinatorPool {
  private static class Pool {
    static final ERXRoundRobinCollection<EOObjectStoreCoordinator> COLLECTION = initializePool();
   
    static ERXRoundRobinCollection<EOObjectStoreCoordinator> initializePool() {
      int maxCoordinators = ERXProperties.intForKeyWithDefault("er.extensions.concurrency.ERXTaskObjectStoreCoordinatorPool.maxCoordinators", 1);
      NSMutableArray<EOObjectStoreCoordinator> coordinators = new NSMutableArray<EOObjectStoreCoordinator>(maxCoordinators);
      for (int i = 0; i < maxCoordinators; i++) {
        int poolItemID = i + 1;
        ERXObjectStoreCoordinator osc = new ERXObjectStoreCoordinator(true);
        osc.setName("TaskPool-" + poolItemID + "/" + maxCoordinators);
        coordinators.add(osc);
      }
      return new ERXRoundRobinCollection<EOObjectStoreCoordinator>(coordinators.immutableClone());
    }
  }
 
  /**
   * @return a OSC from the pool in Round Robin fashion
   */
  public static EOObjectStoreCoordinator objectStoreCoordinator() {
    return Pool.COLLECTION.next();
  }

}
TOP

Related Classes of er.extensions.concurrency.ERXTaskObjectStoreCoordinatorPool

TOP
Copyright © 2018 www.massapi.com. 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.
ners.html" title="Examples of org.radargun.traits.CacheListeners">org.radargun.traits.CacheListeners
  • java.security.ProviderException
  • java.util.ListIterator
  • java.util.concurrent.Semaphore
  • java.util.Iterator
  • TOP
    Copyright © 2018 www.massapi.com. 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.