net.sf.ehcache.Ehcache.acquireWriteLockOnKey()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中net.sf.ehcache.Ehcache.acquireWriteLockOnKey()方法的一些代码示例,展示了Ehcache.acquireWriteLockOnKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ehcache.acquireWriteLockOnKey()方法的具体详情如下:
包路径:net.sf.ehcache.Ehcache
类名称:Ehcache
方法名:acquireWriteLockOnKey

Ehcache.acquireWriteLockOnKey介绍

[英]Acquires the proper write lock for a given cache key
[中]获取给定缓存密钥的正确写锁

代码示例

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T get(Object key, Callable<T> valueLoader) {
  Element element = lookup(key);
  if (element != null) {
    return (T) element.getObjectValue();
  }
  else {
    this.cache.acquireWriteLockOnKey(key);
    try {
      element = lookup(key);  // one more attempt with the write lock
      if (element != null) {
        return (T) element.getObjectValue();
      }
      else {
        return loadValue(key, valueLoader);
      }
    }
    finally {
      this.cache.releaseWriteLockOnKey(key);
    }
  }
}

代码示例来源:origin: org.springframework/spring-context-support

@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T get(Object key, Callable<T> valueLoader) {
  Element element = lookup(key);
  if (element != null) {
    return (T) element.getObjectValue();
  }
  else {
    this.cache.acquireWriteLockOnKey(key);
    try {
      element = lookup(key);  // one more attempt with the write lock
      if (element != null) {
        return (T) element.getObjectValue();
      }
      else {
        return loadValue(key, valueLoader);
      }
    }
    finally {
      this.cache.releaseWriteLockOnKey(key);
    }
  }
}

代码示例来源:origin: apache/kylin

@Override
@SuppressWarnings("unchecked")
public <T> T get(Object key, Callable<T> valueLoader) {
  Element element = lookup(key);
  if (element != null) {
    return (T) element.getObjectValue();
  } else {
    this.cache.acquireWriteLockOnKey(key);
    try {
      element = lookup(key); // One more attempt with the write lock
      if (element != null) {
        return (T) element.getObjectValue();
      } else {
        return loadValue(key, valueLoader);
      }
    } finally {
      this.cache.releaseWriteLockOnKey(key);
    }
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public void acquireWriteLockOnKey(Object key) {
  underlyingCache.acquireWriteLockOnKey(key);
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
* {@inheritDoc}
*/
public void acquireWriteLockOnKey(Object arg0) {
  // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  Thread t = Thread.currentThread();
  ClassLoader prev = t.getContextClassLoader();
  t.setContextClassLoader(this.classLoader);
  try {
    this.cache.acquireWriteLockOnKey(arg0);
  } finally {
    t.setContextClassLoader(prev);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache

/**
 * {@inheritDoc}
 */
public void acquireWriteLockOnKey(Object key) {
  underlyingCache.acquireWriteLockOnKey(key);
}

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

/**
 * {@inheritDoc}
 */
public void acquireWriteLockOnKey(Object key) {
  underlyingCache.acquireWriteLockOnKey(key);
}

代码示例来源:origin: net.sf.ehcache.internal/ehcache-core

/**
 * {@inheritDoc}
 */
public void acquireWriteLockOnKey(Object key) {
  underlyingCache.acquireWriteLockOnKey(key);
}

代码示例来源:origin: suninformation/ymate-platform-v2

@Override
public void writeLock(Object key) {
  __ehcache.acquireWriteLockOnKey(key);
}

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

/**
* {@inheritDoc}
*/
public void acquireWriteLockOnKey(Object arg0) {
  // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  Thread t = Thread.currentThread();
  ClassLoader prev = t.getContextClassLoader();
  t.setContextClassLoader(this.classLoader);
  try {
    this.cache.acquireWriteLockOnKey(arg0);
  } finally {
    t.setContextClassLoader(prev);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache

/**
* {@inheritDoc}
*/
public void acquireWriteLockOnKey(Object arg0) {
  // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  Thread t = Thread.currentThread();
  ClassLoader prev = t.getContextClassLoader();
  t.setContextClassLoader(this.classLoader);
  try {
    this.cache.acquireWriteLockOnKey(arg0);
  } finally {
    t.setContextClassLoader(prev);
  }
}

代码示例来源:origin: net.sf.ehcache.internal/ehcache-core

/**
* {@inheritDoc}
*/
public void acquireWriteLockOnKey(Object arg0) {
  // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  Thread t = Thread.currentThread();
  ClassLoader prev = t.getContextClassLoader();
  t.setContextClassLoader(this.classLoader);
  try {
    this.cache.acquireWriteLockOnKey(arg0);
  } finally {
    t.setContextClassLoader(prev);
  }
}

代码示例来源:origin: ehcache/ehcache-jcache

@Override
public V getAndRemove(final K key) {
  checkNotClosed();
  if(key == null) throw new NullPointerException();
  ehcache.acquireWriteLockOnKey(key);
  try {
    Element previousElement;
    previousElement = ehcache.get(key);
    removeAndWriteIfNeeded(key);
    return previousElement == null ? null : (V) previousElement.getObjectValue();
  } finally {
    ehcache.releaseWriteLockOnKey(key);
  }
}

代码示例来源:origin: org.ehcache/jcache

@Override
public V getAndRemove(final K key) {
  checkNotClosed();
  if(key == null) throw new NullPointerException();
  ehcache.acquireWriteLockOnKey(key);
  try {
    Element previousElement;
    previousElement = ehcache.get(key);
    removeAndWriteIfNeeded(key);
    return previousElement == null ? null : (V) previousElement.getObjectValue();
  } finally {
    ehcache.releaseWriteLockOnKey(key);
  }
}

代码示例来源:origin: apache/servicemix-bundles

@SuppressWarnings("unchecked")
@Override
public <T> T get(Object key, Callable<T> valueLoader) {
  Element element = lookup(key);
  if (element != null) {
    return (T) element.getObjectValue();
  }
  else {
    this.cache.acquireWriteLockOnKey(key);
    try {
      element = lookup(key);  // one more attempt with the write lock
      if (element != null) {
        return (T) element.getObjectValue();
      }
      else {
        return loadValue(key, valueLoader);
      }
    }
    finally {
      this.cache.releaseWriteLockOnKey(key);
    }
  }
}

代码示例来源:origin: org.ehcache/jcache

@Override
public void remove() {
  if(current == null) {
    throw new IllegalStateException();
  }
  jCache.ehcache.acquireWriteLockOnKey(current.getKey());
  try {
    final Element element = jCache.ehcache.getQuiet(current.getKey());
    if(element != null && element.getObjectValue().equals(current.getValue())) {
      jCache.removeAndWriteIfNeeded(current.getKey());
    }
  } finally {
    jCache.ehcache.releaseWriteLockOnKey(current.getKey());
  }
}

代码示例来源:origin: ehcache/ehcache-jcache

@Override
public void remove() {
  if(current == null) {
    throw new IllegalStateException();
  }
  jCache.ehcache.acquireWriteLockOnKey(current.getKey());
  try {
    final Element element = jCache.ehcache.getQuiet(current.getKey());
    if(element != null && element.getObjectValue().equals(current.getValue())) {
      jCache.removeAndWriteIfNeeded(current.getKey());
    }
  } finally {
    jCache.ehcache.releaseWriteLockOnKey(current.getKey());
  }
}

代码示例来源:origin: org.ehcache/jcache

@Override
public boolean putIfAbsent(final K key, final V value) {
  checkNotClosed();
  if(key == null) throw new NullPointerException();
  if(value == null) throw new NullPointerException();
  ehcache.acquireWriteLockOnKey(key);
  try {
    if (!ehcache.isKeyInCache(key)) {
      final Element element = new Element(key, value);
      final Duration expiryForCreation;
      expiryForCreation = cfg.getExpiryPolicy().getExpiryForCreation();
      if(setTimeTo(cfg.overrideDefaultExpiry(), expiryForCreation, element)) {
        putAndWriteIfNeeded(element);
      }
      return true;
    }
  } finally {
    ehcache.releaseWriteLockOnKey(key);
  }
  return false;
}

代码示例来源:origin: org.ehcache/jcache

void putWithoutWriter(final K key, final V value) {
  checkNotClosed();
  if(key == null) throw new NullPointerException();
  if(value == null) throw new NullPointerException();
  ehcache.acquireWriteLockOnKey(key);
  try {
    final Duration expiry;
    final boolean inCache = ehcache.isKeyInCache(key);
    if(inCache) {
      expiry = cfg.getExpiryPolicy().getExpiryForUpdate();
    } else {
      expiry = cfg.getExpiryPolicy().getExpiryForCreation();
    }
    final Element element = new Element(key, value);
    if(setTimeTo(cfg.overrideDefaultExpiry(), expiry, element)) {
      ehcache.put(element);
    } else if(inCache) {
      ehcache.remove(key);
    }
  } finally {
    ehcache.releaseWriteLockOnKey(key);
  }
}

代码示例来源:origin: ehcache/ehcache-jcache

private boolean removeAndWriteIfNeeded(final K key) {
  if (cfg.isWriteThrough()) {
    ehcache.acquireWriteLockOnKey(key);
    final Element previous = ehcache.getQuiet(key);
    try {
      return ehcache.removeWithWriter(key);
    } catch (RuntimeException e) {
      if(previous != null) {
        ehcache.putQuiet(previous);
      }
      throw new CacheWriterException(e);
    }
  } else {
    if (ehcache.isKeyInCache(key)) {
      return ehcache.remove(key);
    }
    return false;
  }
}

相关文章

Ehcache类方法