2
* Copyright 2003-2010 Terracotta, Inc.
2
* Copyright Terracotta, Inc.
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
202
202
* Adds an entry and unlocks it
205
public void put(Element element) {
207
if (element == null) {
205
public void put(final Element element) {
207
doAndReleaseWriteLock(new PutAction<Void>(element) {
210
if (element.getObjectValue() != null) {
211
underlyingCache.put(element);
213
underlyingCache.remove(element.getObjectKey());
221
public void put(final Element element, final boolean doNotNotifyCacheReplicators)
222
throws IllegalArgumentException, IllegalStateException, CacheException {
223
doAndReleaseWriteLock(new PutAction<Void>(element) {
226
underlyingCache.put(element, doNotNotifyCacheReplicators);
233
public void putQuiet(final Element element) throws IllegalArgumentException, IllegalStateException, CacheException {
234
doAndReleaseWriteLock(new PutAction<Void>(element) {
237
underlyingCache.putQuiet(element);
244
public void putWithWriter(final Element element) throws IllegalArgumentException, IllegalStateException, CacheException {
245
doAndReleaseWriteLock(new PutAction<Void>(element) {
248
underlyingCache.putWithWriter(element);
255
public Element putIfAbsent(final Element element) throws NullPointerException {
256
return doAndReleaseWriteLock(new PutAction<Element>(element) {
258
public Element put() {
259
return underlyingCache.putIfAbsent(element);
265
public Element putIfAbsent(final Element element, final boolean doNotNotifyCacheReplicators) throws NullPointerException {
266
return doAndReleaseWriteLock(new PutAction<Element>(element) {
268
public Element put() {
269
return underlyingCache.putIfAbsent(element, doNotNotifyCacheReplicators);
274
private <V> V doAndReleaseWriteLock(PutAction<V> putAction) {
276
if (putAction.element == null) {
210
Object key = element.getObjectKey();
211
Object value = element.getObjectValue();
280
Object key = putAction.element.getObjectKey();
213
282
Sync lock = getLockForKey(key);
215
284
if (!lock.isHeldByCurrentThread(LockType.WRITE)) {
216
285
lock.lock(LockType.WRITE);
220
underlyingCache.put(element);
222
underlyingCache.remove(key);
288
return putAction.put();
225
//Release the readlock here. This will have been acquired in the get, where the element was null
290
//Release the writelock here. This will have been acquired in the get, where the element was null
226
291
lock.unlock(LockType.WRITE);
355
420
public void loadAll(Collection keys, Object argument) throws CacheException {
356
421
throw new CacheException("This method is not appropriate for a Blocking Cache");
425
* Callable like class to actually execute one of the many Ehcache.put* methods in the context of a BlockingCache
428
private abstract static class PutAction<V> {
430
private final Element element;
432
private PutAction(Element element) {
433
this.element = element;
437
* implement method with the put*
438
* @return the return value of the put*