Search in sources :

Example 6 with NearCachingHook

use of com.hazelcast.internal.nearcache.impl.NearCachingHook in project hazelcast by hazelcast.

the class TransactionalMapProxy method putIfAbsent.

@Override
public Object putIfAbsent(Object key, Object value) {
    checkTransactionState();
    checkNotNull(key, "key can't be null");
    checkNotNull(value, "value can't be null");
    Data keyData = mapServiceContext.toData(key, partitionStrategy);
    Data valueData = mapServiceContext.toData(value);
    NearCachingHook invalidationHook = newNearCachingHook();
    invalidationHook.beforeRemoteCall(key, keyData, value, valueData);
    TxnValueWrapper wrapper = txMap.get(keyData);
    boolean haveTxnPast = wrapper != null;
    if (haveTxnPast) {
        if (wrapper.type != Type.REMOVED) {
            return wrapper.value;
        }
        putInternal(keyData, valueData, UNSET, MILLISECONDS, invalidationHook);
        txMap.put(keyData, new TxnValueWrapper(value, Type.NEW));
        return null;
    } else {
        Data oldValue = putIfAbsentInternal(keyData, valueData, invalidationHook);
        if (oldValue == null) {
            txMap.put(keyData, new TxnValueWrapper(value, Type.NEW));
        }
        return toObjectIfNeeded(oldValue);
    }
}
Also used : NearCachingHook(com.hazelcast.internal.nearcache.impl.NearCachingHook) Data(com.hazelcast.internal.serialization.Data)

Aggregations

NearCachingHook (com.hazelcast.internal.nearcache.impl.NearCachingHook)6 Data (com.hazelcast.internal.serialization.Data)6 IterationType (com.hazelcast.internal.util.IterationType)2 Type (com.hazelcast.map.impl.tx.TxnValueWrapper.Type)2