Esempio n. 1
0
 public OSegment(final OStorageLocal iStorage, final String iName) {
   super(OGlobalConfiguration.ENVIRONMENT_CONCURRENT.getValueAsBoolean(), 0, true);
   storage = iStorage;
   name = iName;
 }
Esempio n. 2
0
/** @author <a href="mailto:[email protected]">Artem Orobets</a> */
public abstract class OAbstractMapCache<T extends Map<ORID, ?>> implements OCache {
  protected final OSharedResourceAdaptiveExternal lock =
      new OSharedResourceAdaptiveExternal(
          OGlobalConfiguration.ENVIRONMENT_CONCURRENT.getValueAsBoolean(), 0, true);
  protected final T cache;
  private final AtomicBoolean enabled = new AtomicBoolean(false);

  public OAbstractMapCache(T cache) {
    this.cache = cache;
  }

  @Override
  public void startup() {
    enable();
  }

  @Override
  public void shutdown() {
    disable();
  }

  @Override
  public boolean isEnabled() {
    return enabled.get();
  }

  @Override
  public boolean enable() {
    return enabled.compareAndSet(false, true);
  }

  @Override
  public boolean disable() {
    clear();
    return enabled.compareAndSet(true, false);
  }

  @Override
  public void clear() {
    if (!isEnabled()) return;

    lock.acquireExclusiveLock();
    try {
      cache.clear();
    } finally {
      lock.releaseExclusiveLock();
    }
  }

  @Override
  public int size() {
    lock.acquireSharedLock();
    try {
      return cache.size();
    } finally {
      lock.releaseSharedLock();
    }
  }

  @Override
  public Collection<ORID> keys() {
    lock.acquireExclusiveLock();
    try {
      return new ArrayList<ORID>(cache.keySet());
    } finally {
      lock.releaseExclusiveLock();
    }
  }

  @Override
  public void lock(final ORID id) {
    lock.acquireExclusiveLock();
  }

  @Override
  public void unlock(final ORID id) {
    lock.releaseExclusiveLock();
  }
}