Search in sources :

Example 1 with NearCachingHook

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

the class TransactionalMapProxy method remove.

@Override
public Object remove(Object key) {
    checkTransactionState();
    checkNotNull(key, "key can't be null");
    Data keyData = mapServiceContext.toData(key, partitionStrategy);
    NearCachingHook invalidationHook = newNearCachingHook();
    invalidationHook.beforeRemoteCall(key, keyData, null, null);
    Object valueBeforeTxn = toObjectIfNeeded(removeInternal(keyData, invalidationHook));
    TxnValueWrapper wrapper = null;
    if (valueBeforeTxn != null || txMap.containsKey(keyData)) {
        wrapper = txMap.put(keyData, new TxnValueWrapper(valueBeforeTxn, Type.REMOVED));
    }
    return wrapper == null ? valueBeforeTxn : checkIfRemoved(wrapper);
}
Also used : NearCachingHook(com.hazelcast.internal.nearcache.impl.NearCachingHook) Data(com.hazelcast.internal.serialization.Data)

Example 2 with NearCachingHook

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

the class TransactionalMapProxy method delete.

@Override
public void delete(Object key) {
    checkTransactionState();
    checkNotNull(key, "key can't be null");
    Data keyData = mapServiceContext.toData(key, partitionStrategy);
    NearCachingHook invalidationHook = newNearCachingHook();
    invalidationHook.beforeRemoteCall(key, keyData, null, null);
    Data data = removeInternal(keyData, invalidationHook);
    if (data != null || txMap.containsKey(keyData)) {
        txMap.put(keyData, new TxnValueWrapper(toObjectIfNeeded(data), Type.REMOVED));
    }
}
Also used : NearCachingHook(com.hazelcast.internal.nearcache.impl.NearCachingHook) Data(com.hazelcast.internal.serialization.Data)

Example 3 with NearCachingHook

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

the class TransactionalMapProxy method set.

@Override
public void set(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);
    Data dataBeforeTxn = putInternal(keyData, valueData, UNSET, MILLISECONDS, invalidationHook);
    Type type = dataBeforeTxn == null ? Type.NEW : Type.UPDATED;
    TxnValueWrapper wrapper = new TxnValueWrapper(value, type);
    txMap.put(keyData, wrapper);
}
Also used : Type(com.hazelcast.map.impl.tx.TxnValueWrapper.Type) IterationType(com.hazelcast.internal.util.IterationType) NearCachingHook(com.hazelcast.internal.nearcache.impl.NearCachingHook) Data(com.hazelcast.internal.serialization.Data)

Example 4 with NearCachingHook

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

the class TransactionalMapProxy method put.

@Override
public Object put(Object key, Object value, long ttl, TimeUnit timeUnit) {
    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);
    Object valueBeforeTxn = toObjectIfNeeded(putInternal(keyData, valueData, ttl, timeUnit, invalidationHook));
    TxnValueWrapper currentValue = txMap.get(keyData);
    Type type = valueBeforeTxn == null ? Type.NEW : Type.UPDATED;
    TxnValueWrapper wrapper = new TxnValueWrapper(value, type);
    txMap.put(keyData, wrapper);
    return currentValue == null ? valueBeforeTxn : checkIfRemoved(currentValue);
}
Also used : Type(com.hazelcast.map.impl.tx.TxnValueWrapper.Type) IterationType(com.hazelcast.internal.util.IterationType) NearCachingHook(com.hazelcast.internal.nearcache.impl.NearCachingHook) Data(com.hazelcast.internal.serialization.Data)

Example 5 with NearCachingHook

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

the class TransactionalMapProxy method replace.

@Override
public Object replace(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 null;
        }
        putInternal(keyData, valueData, UNSET, MILLISECONDS, invalidationHook);
        txMap.put(keyData, new TxnValueWrapper(value, Type.UPDATED));
        return wrapper.value;
    } else {
        Data oldValue = replaceInternal(keyData, valueData, invalidationHook);
        if (oldValue != null) {
            txMap.put(keyData, new TxnValueWrapper(value, Type.UPDATED));
        }
        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