Search in sources :

Example 1 with VersionResponsePair

use of com.hazelcast.replicatedmap.impl.operation.VersionResponsePair in project hazelcast by hazelcast.

the class ReplicatedMapReorderedReplicationTest method put.

private <K, V> V put(final NodeEngine nodeEngine, final String mapName, final int partitionId, K key, V value) {
    isNotNull(key, "key must not be null!");
    isNotNull(value, "value must not be null!");
    Data dataKey = nodeEngine.toData(key);
    Data dataValue = nodeEngine.toData(value);
    PutOperation putOperation = new PutOperation(mapName, dataKey, dataValue);
    InternalCompletableFuture<Object> future = nodeEngine.getOperationService().invokeOnPartition(ReplicatedMapService.SERVICE_NAME, putOperation, partitionId);
    VersionResponsePair result = (VersionResponsePair) future.join();
    return nodeEngine.toObject(result.getResponse());
}
Also used : PutOperation(com.hazelcast.replicatedmap.impl.operation.PutOperation) Data(com.hazelcast.nio.serialization.Data) VersionResponsePair(com.hazelcast.replicatedmap.impl.operation.VersionResponsePair)

Example 2 with VersionResponsePair

use of com.hazelcast.replicatedmap.impl.operation.VersionResponsePair in project hazelcast by hazelcast.

the class ReplicatedMapProxy method remove.

@Override
public V remove(Object key) {
    isNotNull(key, "key");
    Data dataKey = nodeEngine.toData(key);
    int partitionId = partitionService.getPartitionId(key);
    RemoveOperation removeOperation = new RemoveOperation(getName(), dataKey);
    InternalCompletableFuture<Object> future = getOperationService().invokeOnPartition(getServiceName(), removeOperation, partitionId);
    VersionResponsePair result = (VersionResponsePair) future.join();
    return nodeEngine.toObject(result.getResponse());
}
Also used : RemoveOperation(com.hazelcast.replicatedmap.impl.operation.RemoveOperation) Data(com.hazelcast.nio.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) VersionResponsePair(com.hazelcast.replicatedmap.impl.operation.VersionResponsePair)

Example 3 with VersionResponsePair

use of com.hazelcast.replicatedmap.impl.operation.VersionResponsePair in project hazelcast by hazelcast.

the class ReplicatedMapProxy method put.

@Override
public V put(K key, V value, long ttl, TimeUnit timeUnit) {
    isNotNull(key, "key");
    isNotNull(value, "value");
    isNotNull(timeUnit, "timeUnit");
    if (ttl < 0) {
        throw new IllegalArgumentException("ttl must be a positive integer");
    }
    long ttlMillis = timeUnit.toMillis(ttl);
    Data dataKey = nodeEngine.toData(key);
    Data dataValue = nodeEngine.toData(value);
    int partitionId = partitionService.getPartitionId(dataKey);
    PutOperation putOperation = new PutOperation(getName(), dataKey, dataValue, ttlMillis);
    InternalCompletableFuture<Object> future = getOperationService().invokeOnPartition(getServiceName(), putOperation, partitionId);
    VersionResponsePair result = (VersionResponsePair) future.join();
    return nodeEngine.toObject(result.getResponse());
}
Also used : PutOperation(com.hazelcast.replicatedmap.impl.operation.PutOperation) Data(com.hazelcast.nio.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) VersionResponsePair(com.hazelcast.replicatedmap.impl.operation.VersionResponsePair)

Example 4 with VersionResponsePair

use of com.hazelcast.replicatedmap.impl.operation.VersionResponsePair in project hazelcast by hazelcast.

the class ReplicatedMapProxy method put.

@Override
public V put(K key, V value) {
    isNotNull(key, "key");
    isNotNull(value, "value");
    Data dataKey = nodeEngine.toData(key);
    Data dataValue = nodeEngine.toData(value);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
    PutOperation putOperation = new PutOperation(getName(), dataKey, dataValue);
    InternalCompletableFuture<Object> future = getOperationService().invokeOnPartition(getServiceName(), putOperation, partitionId);
    VersionResponsePair result = (VersionResponsePair) future.join();
    return nodeEngine.toObject(result.getResponse());
}
Also used : PutOperation(com.hazelcast.replicatedmap.impl.operation.PutOperation) Data(com.hazelcast.nio.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) VersionResponsePair(com.hazelcast.replicatedmap.impl.operation.VersionResponsePair)

Example 5 with VersionResponsePair

use of com.hazelcast.replicatedmap.impl.operation.VersionResponsePair in project hazelcast by hazelcast.

the class AbstractReplicatedRecordStore method merge.

@Override
public boolean merge(Object key, ReplicatedMapEntryView mergingEntry, ReplicatedMapMergePolicy policy) {
    Object marshalledKey = marshall(key);
    InternalReplicatedMapStorage<K, V> storage = getStorage();
    ReplicatedRecord<K, V> record = storage.get(marshalledKey);
    Object newValue;
    if (record == null) {
        ReplicatedMapEntryView nullEntryView = new ReplicatedMapEntryView(unmarshall(key), null);
        newValue = policy.merge(getName(), mergingEntry, nullEntryView);
        if (newValue == null) {
            return false;
        }
        record = buildReplicatedRecord((K) marshalledKey, (V) newValue, 0);
        storage.put((K) marshalledKey, record);
        storage.incrementVersion();
        Data dataKey = serializationService.toData(marshalledKey);
        Data dataValue = serializationService.toData(newValue);
        VersionResponsePair responsePair = new VersionResponsePair(mergingEntry.getValue(), getVersion());
        sendReplicationOperation(false, getName(), dataKey, dataValue, record.getTtlMillis(), responsePair);
    } else {
        Object oldValue = record.getValueInternal();
        ReplicatedMapEntryView existingEntry = new ReplicatedMapEntryView(unmarshall(key), unmarshall(oldValue));
        existingEntry.setCreationTime(record.getCreationTime());
        existingEntry.setLastUpdateTime(record.getUpdateTime());
        existingEntry.setLastAccessTime(record.getLastAccessTime());
        existingEntry.setHits(record.getHits());
        existingEntry.setTtl(record.getTtlMillis());
        newValue = policy.merge(getName(), mergingEntry, existingEntry);
        if (newValue == null) {
            storage.remove((K) marshalledKey, record);
            storage.incrementVersion();
            Data dataKey = serializationService.toData(marshalledKey);
            VersionResponsePair responsePair = new VersionResponsePair(mergingEntry.getValue(), getVersion());
            sendReplicationOperation(true, getName(), dataKey, null, record.getTtlMillis(), responsePair);
            return false;
        }
        record.setValueInternal((V) newValue, record.getTtlMillis());
        storage.incrementVersion();
        Data dataKey = serializationService.toData(marshalledKey);
        Data dataValue = serializationService.toData(newValue);
        VersionResponsePair responsePair = new VersionResponsePair(mergingEntry.getValue(), getVersion());
        sendReplicationOperation(false, getName(), dataKey, dataValue, record.getTtlMillis(), responsePair);
    }
    return true;
}
Also used : Data(com.hazelcast.nio.serialization.Data) VersionResponsePair(com.hazelcast.replicatedmap.impl.operation.VersionResponsePair)

Aggregations

Data (com.hazelcast.nio.serialization.Data)5 VersionResponsePair (com.hazelcast.replicatedmap.impl.operation.VersionResponsePair)5 PutOperation (com.hazelcast.replicatedmap.impl.operation.PutOperation)3 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)3 InitializingObject (com.hazelcast.spi.InitializingObject)3 RemoveOperation (com.hazelcast.replicatedmap.impl.operation.RemoveOperation)1