Search in sources :

Example 1 with PutOperation

use of com.hazelcast.replicatedmap.impl.operation.PutOperation 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 PutOperation

use of com.hazelcast.replicatedmap.impl.operation.PutOperation 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 3 with PutOperation

use of com.hazelcast.replicatedmap.impl.operation.PutOperation 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)

Aggregations

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