
com.hazelcast.client.impl.proxy.ClientMapProxy Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.client.impl.proxy;
import com.hazelcast.aggregation.Aggregator;
import com.hazelcast.client.impl.ClientDelegatingFuture;
import com.hazelcast.client.impl.clientside.ClientLockReferenceIdGenerator;
import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerCodec;
import com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerToKeyCodec;
import com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerToKeyWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapAddIndexCodec;
import com.hazelcast.client.impl.protocol.codec.MapAddInterceptorCodec;
import com.hazelcast.client.impl.protocol.codec.MapAddPartitionLostListenerCodec;
import com.hazelcast.client.impl.protocol.codec.MapAggregateCodec;
import com.hazelcast.client.impl.protocol.codec.MapAggregateWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapClearCodec;
import com.hazelcast.client.impl.protocol.codec.MapContainsKeyCodec;
import com.hazelcast.client.impl.protocol.codec.MapContainsValueCodec;
import com.hazelcast.client.impl.protocol.codec.MapDeleteCodec;
import com.hazelcast.client.impl.protocol.codec.MapEntriesWithPagingPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapEntrySetCodec;
import com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec;
import com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec;
import com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec.ResponseParameters;
import com.hazelcast.client.impl.protocol.codec.MapEvictAllCodec;
import com.hazelcast.client.impl.protocol.codec.MapEvictCodec;
import com.hazelcast.client.impl.protocol.codec.MapExecuteOnAllKeysCodec;
import com.hazelcast.client.impl.protocol.codec.MapExecuteOnKeyCodec;
import com.hazelcast.client.impl.protocol.codec.MapExecuteOnKeysCodec;
import com.hazelcast.client.impl.protocol.codec.MapExecuteWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapFlushCodec;
import com.hazelcast.client.impl.protocol.codec.MapForceUnlockCodec;
import com.hazelcast.client.impl.protocol.codec.MapGetAllCodec;
import com.hazelcast.client.impl.protocol.codec.MapGetCodec;
import com.hazelcast.client.impl.protocol.codec.MapGetEntryViewCodec;
import com.hazelcast.client.impl.protocol.codec.MapIsEmptyCodec;
import com.hazelcast.client.impl.protocol.codec.MapIsLockedCodec;
import com.hazelcast.client.impl.protocol.codec.MapKeySetCodec;
import com.hazelcast.client.impl.protocol.codec.MapKeySetWithPagingPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapLoadAllCodec;
import com.hazelcast.client.impl.protocol.codec.MapLoadGivenKeysCodec;
import com.hazelcast.client.impl.protocol.codec.MapLockCodec;
import com.hazelcast.client.impl.protocol.codec.MapProjectCodec;
import com.hazelcast.client.impl.protocol.codec.MapProjectWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutAllCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutAllWithMetadataCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutIfAbsentCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutIfAbsentWithMaxIdleCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutTransientCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutTransientWithMaxIdleCodec;
import com.hazelcast.client.impl.protocol.codec.MapPutWithMaxIdleCodec;
import com.hazelcast.client.impl.protocol.codec.MapRemoveAllCodec;
import com.hazelcast.client.impl.protocol.codec.MapRemoveCodec;
import com.hazelcast.client.impl.protocol.codec.MapRemoveEntryListenerCodec;
import com.hazelcast.client.impl.protocol.codec.MapRemoveIfSameCodec;
import com.hazelcast.client.impl.protocol.codec.MapRemoveInterceptorCodec;
import com.hazelcast.client.impl.protocol.codec.MapRemovePartitionLostListenerCodec;
import com.hazelcast.client.impl.protocol.codec.MapReplaceAllCodec;
import com.hazelcast.client.impl.protocol.codec.MapReplaceCodec;
import com.hazelcast.client.impl.protocol.codec.MapReplaceIfSameCodec;
import com.hazelcast.client.impl.protocol.codec.MapSetCodec;
import com.hazelcast.client.impl.protocol.codec.MapSetTtlCodec;
import com.hazelcast.client.impl.protocol.codec.MapSetWithMaxIdleCodec;
import com.hazelcast.client.impl.protocol.codec.MapSizeCodec;
import com.hazelcast.client.impl.protocol.codec.MapSubmitToKeyCodec;
import com.hazelcast.client.impl.protocol.codec.MapTryLockCodec;
import com.hazelcast.client.impl.protocol.codec.MapTryPutCodec;
import com.hazelcast.client.impl.protocol.codec.MapTryRemoveCodec;
import com.hazelcast.client.impl.protocol.codec.MapUnlockCodec;
import com.hazelcast.client.impl.protocol.codec.MapValuesCodec;
import com.hazelcast.client.impl.protocol.codec.MapValuesWithPagingPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec;
import com.hazelcast.client.impl.protocol.codec.holder.PagingPredicateHolder;
import com.hazelcast.client.impl.spi.ClientContext;
import com.hazelcast.client.impl.spi.ClientPartitionService;
import com.hazelcast.client.impl.spi.ClientProxy;
import com.hazelcast.client.impl.spi.EventHandler;
import com.hazelcast.client.impl.spi.impl.ClientInvocation;
import com.hazelcast.client.impl.spi.impl.ClientInvocationFuture;
import com.hazelcast.client.impl.spi.impl.ListenerMessageCodec;
import com.hazelcast.client.map.impl.iterator.ClientMapIterable;
import com.hazelcast.client.map.impl.iterator.ClientMapIterator;
import com.hazelcast.client.map.impl.iterator.ClientMapPartitionIterable;
import com.hazelcast.client.map.impl.iterator.ClientMapPartitionIterator;
import com.hazelcast.client.map.impl.iterator.ClientMapQueryIterable;
import com.hazelcast.client.map.impl.iterator.ClientMapQueryPartitionIterable;
import com.hazelcast.client.map.impl.iterator.ClientMapQueryPartitionIterator;
import com.hazelcast.cluster.Member;
import com.hazelcast.config.IndexConfig;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryEventType;
import com.hazelcast.core.EntryView;
import com.hazelcast.core.ManagedContext;
import com.hazelcast.core.ReadOnly;
import com.hazelcast.internal.journal.EventJournalInitialSubscriberState;
import com.hazelcast.internal.journal.EventJournalReader;
import com.hazelcast.internal.monitor.impl.LocalMapStatsImpl;
import com.hazelcast.internal.serialization.Data;
import com.hazelcast.internal.serialization.SerializationService;
import com.hazelcast.internal.serialization.impl.SerializationUtil;
import com.hazelcast.internal.util.CollectionUtil;
import com.hazelcast.internal.util.ConcurrencyUtil;
import com.hazelcast.internal.util.IterationType;
import com.hazelcast.map.EntryProcessor;
import com.hazelcast.map.EventJournalMapEvent;
import com.hazelcast.map.IMap;
import com.hazelcast.map.IMapEvent;
import com.hazelcast.map.LocalMapStats;
import com.hazelcast.map.MapEvent;
import com.hazelcast.map.MapInterceptor;
import com.hazelcast.map.MapPartitionLostEvent;
import com.hazelcast.map.impl.DataAwareEntryEvent;
import com.hazelcast.map.impl.ListenerAdapter;
import com.hazelcast.map.impl.SimpleEntryView;
import com.hazelcast.map.listener.MapListener;
import com.hazelcast.map.listener.MapPartitionLostListener;
import com.hazelcast.projection.Projection;
import com.hazelcast.query.PagingPredicate;
import com.hazelcast.query.PartitionPredicate;
import com.hazelcast.query.Predicate;
import com.hazelcast.query.impl.IndexUtils;
import com.hazelcast.query.impl.predicates.PagingPredicateImpl;
import com.hazelcast.ringbuffer.ReadResultSet;
import com.hazelcast.ringbuffer.impl.ReadResultSetImpl;
import com.hazelcast.spi.impl.InternalCompletableFuture;
import com.hazelcast.spi.impl.UnmodifiableLazyList;
import com.hazelcast.spi.impl.UnmodifiableLazySet;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import static com.hazelcast.internal.util.CollectionUtil.objectToDataCollection;
import static com.hazelcast.internal.util.ExceptionUtil.rethrow;
import static com.hazelcast.internal.util.MapUtil.createHashMap;
import static com.hazelcast.internal.util.Preconditions.checkNotNull;
import static com.hazelcast.internal.util.Preconditions.checkPositive;
import static com.hazelcast.internal.util.ThreadUtil.getThreadId;
import static com.hazelcast.internal.util.TimeUtil.timeInMsOrOneIfResultIsZero;
import static com.hazelcast.internal.util.TimeUtil.timeInMsOrTimeIfNullUnit;
import static com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter;
import static com.hazelcast.map.impl.MapListenerFlagOperator.setAndGetListenerFlags;
import static com.hazelcast.query.impl.predicates.PredicateUtils.checkDoesNotContainPagingPredicate;
import static com.hazelcast.query.impl.predicates.PredicateUtils.containsPagingPredicate;
import static com.hazelcast.query.impl.predicates.PredicateUtils.unwrapPagingPredicate;
import static java.lang.Thread.currentThread;
import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.stream.Collectors.groupingBy;
/**
* Proxy implementation of {@link IMap}.
*
* @param key
* @param value
*/
@SuppressWarnings({"checkstyle:classdataabstractioncoupling", "ClassFanOutComplexity", "MethodCount"})
public class ClientMapProxy extends ClientProxy
implements IMap, EventJournalReader> {
public static final int UNSET = -1;
protected static final String NULL_LISTENER_IS_NOT_ALLOWED = "Null listener is not allowed!";
protected static final String NULL_KEY_IS_NOT_ALLOWED = "Null key is not allowed!";
protected static final String NULL_VALUE_IS_NOT_ALLOWED = "Null value is not allowed!";
protected static final String NULL_PREDICATE_IS_NOT_ALLOWED = "Predicate should not be null!";
protected static final String NULL_AGGREGATOR_IS_NOT_ALLOWED = "Aggregator should not be null!";
protected static final String NULL_PROJECTION_IS_NOT_ALLOWED = "Projection should not be null!";
protected static final String NULL_ENTRY_PROCESSOR_IS_NOT_ALLOWED = "Null entry processor is not allowed!";
protected static final String NULL_TTL_UNIT_IS_NOT_ALLOWED = "Null ttlUnit is not allowed!";
protected static final String NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED = "Null maxIdleUnit is not allowed!";
protected static final String NULL_TIMEUNIT_IS_NOT_ALLOWED = "Null timeunit is not allowed!";
protected static final String NULL_BIFUNCTION_IS_NOT_ALLOWED = "Null BiFunction is not allowed!";
protected static final String NULL_FUNCTION_IS_NOT_ALLOWED = "Null Function is not allowed!";
private ClientLockReferenceIdGenerator lockReferenceIdGenerator;
//todo implement query cache
//private ClientQueryCacheContext queryCacheContext;
private boolean useDefaultReplaceAllOperation;
public ClientMapProxy(String serviceName, String name, ClientContext context) {
super(serviceName, name, context);
}
@Override
protected void onInitialize() {
super.onInitialize();
lockReferenceIdGenerator = getClient().getLockReferenceIdGenerator();
//todo implement query cache
//queryCacheContext = getContext().getQueryCacheContext();
}
@Override
public boolean containsKey(@Nonnull Object key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return containsKeyInternal(key);
}
protected boolean containsKeyInternal(Object key) {
Data keyData = toData(key);
ClientMessage message = MapContainsKeyCodec.encodeRequest(name, keyData, getThreadId());
ClientMessage result = invoke(message, keyData);
return MapContainsKeyCodec.decodeResponse(result);
}
@Override
public boolean containsValue(@Nonnull Object value) {
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
Data valueData = toData(value);
ClientMessage request = MapContainsValueCodec.encodeRequest(name, valueData);
ClientMessage response = invoke(request);
return MapContainsValueCodec.decodeResponse(response);
}
@Override
public V get(@Nonnull Object key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return toObject(getInternal(key));
}
protected Object getInternal(Object key) {
Data keyData = toData(key);
ClientMessage request = MapGetCodec.encodeRequest(name, keyData, getThreadId());
ClientMessage response = invoke(request, keyData);
return MapGetCodec.decodeResponse(response);
}
@Override
public V put(@Nonnull K key, @Nonnull V value) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
return putInternal(UNSET, MILLISECONDS, null, null, key, value);
}
@Override
public V put(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
checkNotNull(maxIdleUnit, NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED);
return putInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
@Override
public V remove(@Nonnull Object key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return toObject(removeInternal(key));
}
protected Data removeInternal(Object key) {
Data keyData = toData(key);
ClientMessage request = MapRemoveCodec.encodeRequest(name, keyData, getThreadId());
ClientMessage response = invoke(request, keyData);
return MapRemoveCodec.decodeResponse(response);
}
@Override
public boolean remove(@Nonnull Object key, @Nonnull Object value) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
return removeInternal(key, value);
}
protected boolean removeInternal(Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
ClientMessage request = MapRemoveIfSameCodec.encodeRequest(name, keyData, valueData, getThreadId());
ClientMessage response = invoke(request, keyData);
return MapRemoveIfSameCodec.decodeResponse(response);
}
@Override
public void removeAll(@Nonnull Predicate predicate) {
checkNotNull(predicate, "predicate cannot be null");
checkDoesNotContainPagingPredicate(predicate, "removeAll");
removeAllInternal(predicate);
}
protected void removeAllInternal(Predicate predicate) {
ClientMessage request = MapRemoveAllCodec.encodeRequest(name, toData(predicate));
invokeWithPredicate(request, predicate);
}
@Override
public void delete(@Nonnull Object key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
deleteInternal(key);
}
protected void deleteInternal(Object key) {
Data keyData = toData(key);
ClientMessage request = MapDeleteCodec.encodeRequest(name, keyData, getThreadId());
invoke(request, keyData);
}
@Override
public void flush() {
ClientMessage request = MapFlushCodec.encodeRequest(name);
invoke(request);
}
@Override
public InternalCompletableFuture getAsync(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return new ClientDelegatingFuture<>(getAsyncInternal(key),
getSerializationService(), MapGetCodec::decodeResponse);
}
protected ClientInvocationFuture getAsyncInternal(Object key) {
try {
Data keyData = toData(key);
ClientMessage request = MapGetCodec.encodeRequest(name, keyData, getThreadId());
return invokeOnKeyOwner(request, keyData);
} catch (Exception e) {
throw rethrow(e);
}
}
private ClientInvocationFuture invokeOnKeyOwner(ClientMessage request, Data keyData) {
int partitionId = getContext().getPartitionService().getPartitionId(keyData);
ClientInvocation clientInvocation = new ClientInvocation(getClient(), request, getName(), partitionId);
return clientInvocation.invoke();
}
@Override
public InternalCompletableFuture putAsync(@Nonnull K key, @Nonnull V value) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
return putAsyncInternal(UNSET, MILLISECONDS, null, null, key, value);
}
@Override
public InternalCompletableFuture putAsync(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
return putAsyncInternal(ttl, timeunit, null, null, key, value);
}
@Override
public InternalCompletableFuture putAsync(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
checkNotNull(maxIdleUnit, NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED);
return putAsyncInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
protected InternalCompletableFuture putAsyncInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit,
Object key, Object value) {
try {
Data keyData = toData(key);
Data valueData = toData(value);
long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
ClientMessage request;
if (maxIdle != null) {
request = MapPutWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(),
ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
} else {
request = MapPutCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
}
ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
SerializationService ss = getSerializationService();
return new ClientDelegatingFuture<>(future, ss, MapPutCodec::decodeResponse);
} catch (Exception e) {
throw rethrow(e);
}
}
@Override
public InternalCompletableFuture setAsync(@Nonnull K key, @Nonnull V value) {
return setAsync(key, value, UNSET, MILLISECONDS);
}
@Override
public InternalCompletableFuture setAsync(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
return setAsyncInternal(ttl, timeunit, null, null, key, value);
}
@Override
public InternalCompletableFuture setAsync(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
checkNotNull(maxIdleUnit, NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED);
return setAsyncInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
protected InternalCompletableFuture setAsyncInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit,
Object key, Object value) {
try {
Data keyData = toData(key);
Data valueData = toData(value);
long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
ClientMessage request;
if (maxIdle != null) {
request = MapSetWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(),
ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
} else {
request = MapSetCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
}
ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
return new ClientDelegatingFuture<>(future, getSerializationService(), clientMessage -> null);
} catch (Exception e) {
throw rethrow(e);
}
}
@Override
public InternalCompletableFuture removeAsync(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return removeAsyncInternal(key);
}
protected InternalCompletableFuture removeAsyncInternal(Object key) {
try {
Data keyData = toData(key);
ClientMessage request = MapRemoveCodec.encodeRequest(name, keyData, getThreadId());
ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
SerializationService ss = getSerializationService();
return new ClientDelegatingFuture<>(future, ss, MapRemoveCodec::decodeResponse);
} catch (Exception e) {
throw rethrow(e);
}
}
@Override
public InternalCompletableFuture deleteAsync(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return deleteAsyncInternal(key);
}
protected InternalCompletableFuture deleteAsyncInternal(Object key) {
try {
Data keyData = toData(key);
ClientMessage request = MapDeleteCodec.encodeRequest(name, keyData, getThreadId());
ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
SerializationService ss = getSerializationService();
return new ClientDelegatingFuture<>(future, ss,
clientMessage -> MapDeleteCodec.decodeResponse(clientMessage).response);
} catch (Exception e) {
throw rethrow(e);
}
}
@Override
public boolean tryRemove(@Nonnull K key, long timeout, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
return tryRemoveInternal(timeout, timeunit, key);
}
protected boolean tryRemoveInternal(long timeout, TimeUnit timeunit, Object key) {
Data keyData = toData(key);
ClientMessage request = MapTryRemoveCodec.encodeRequest(name, keyData, getThreadId(), timeunit.toMillis(timeout));
ClientMessage response = invoke(request, keyData);
return MapTryRemoveCodec.decodeResponse(response);
}
@Override
public boolean tryPut(@Nonnull K key, @Nonnull V value, long timeout, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
return tryPutInternal(timeout, timeunit, key, value);
}
protected boolean tryPutInternal(long timeout, TimeUnit timeunit, Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
long timeoutMillis = timeInMsOrOneIfResultIsZero(timeout, timeunit);
ClientMessage request = MapTryPutCodec.encodeRequest(name, keyData, valueData, getThreadId(), timeoutMillis);
ClientMessage response = invoke(request, keyData);
return MapTryPutCodec.decodeResponse(response);
}
@Override
public V put(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
return putInternal(ttl, timeunit, null, null, key, value);
}
protected V putInternal(long ttl, TimeUnit ttlUnit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, ttlUnit);
ClientMessage request;
if (maxIdle != null) {
request = MapPutWithMaxIdleCodec.encodeRequest(name, keyData, valueData,
getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
} else {
request = MapPutCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
}
ClientMessage response = invoke(request, keyData);
return toObject(MapPutCodec.decodeResponse(response));
}
@Override
public void putTransient(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
putTransientInternal(ttl, timeunit, null, null, key, value);
}
@Override
public void putTransient(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
checkNotNull(maxIdleUnit, NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED);
putTransientInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
protected void putTransientInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit,
Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
ClientMessage request;
if (maxIdle != null) {
request = MapPutTransientWithMaxIdleCodec.encodeRequest(name, keyData, valueData,
getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
} else {
request = MapPutTransientCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
}
invoke(request, keyData);
}
@Override
public V putIfAbsent(@Nonnull K key, @Nonnull V value) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
return putIfAbsentInternal(UNSET, MILLISECONDS, null, null, key, value);
}
@Override
public V putIfAbsent(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit timeunit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(timeunit, NULL_TIMEUNIT_IS_NOT_ALLOWED);
return putIfAbsentInternal(ttl, timeunit, null, null, key, value);
}
@Override
public V putIfAbsent(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
checkNotNull(maxIdleUnit, NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED);
return putIfAbsentInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
protected V putIfAbsentInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
ClientMessage request;
if (maxIdle != null) {
request = MapPutIfAbsentWithMaxIdleCodec.encodeRequest(name, keyData, valueData,
getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
} else {
request = MapPutIfAbsentCodec.encodeRequest(name, keyData, valueData,
getThreadId(), ttlMillis);
}
ClientMessage result = invoke(request, keyData);
return toObject(MapPutIfAbsentCodec.decodeResponse(result));
}
@Override
public boolean replace(@Nonnull K key, @Nonnull V oldValue, @Nonnull V newValue) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(oldValue, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(newValue, NULL_VALUE_IS_NOT_ALLOWED);
return replaceIfSameInternal(key, oldValue, newValue);
}
protected boolean replaceIfSameInternal(Object key, Object oldValue, Object newValue) {
Data keyData = toData(key);
Data oldValueData = toData(oldValue);
Data newValueData = toData(newValue);
ClientMessage request = MapReplaceIfSameCodec.encodeRequest(name, keyData, oldValueData, newValueData, getThreadId());
ClientMessage response = invoke(request, keyData);
return MapReplaceIfSameCodec.decodeResponse(response);
}
@Override
public V replace(@Nonnull K key, @Nonnull V value) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
return replaceInternal(key, value);
}
protected V replaceInternal(Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
ClientMessage request = MapReplaceCodec.encodeRequest(name, keyData, valueData, getThreadId());
ClientMessage response = invoke(request, keyData);
return toObject(MapReplaceCodec.decodeResponse(response));
}
@Override
public void set(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit ttlUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
setInternal(ttl, ttlUnit, null, null, key, value);
}
@Override
public void set(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);
checkNotNull(ttlUnit, NULL_TTL_UNIT_IS_NOT_ALLOWED);
checkNotNull(maxIdleUnit, NULL_MAX_IDLE_UNIT_IS_NOT_ALLOWED);
setInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value);
}
protected void setInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
Data keyData = toData(key);
Data valueData = toData(value);
long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
ClientMessage request;
if (maxIdle != null) {
request = MapSetWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(),
ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
} else {
request = MapSetCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
}
invoke(request, keyData);
}
@Override
public void lock(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
lockInternal(key, timeInMsOrTimeIfNullUnit(UNSET, MILLISECONDS));
}
@Override
public void lock(@Nonnull K key, long leaseTime, @Nullable TimeUnit timeUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
checkPositive("leaseTime", leaseTime);
lockInternal(key, timeInMsOrTimeIfNullUnit(leaseTime, timeUnit));
}
private void lockInternal(@Nonnull K key, long leaseTimeMs) {
Data keyData = toData(key);
ClientMessage request = MapLockCodec.encodeRequest(name, keyData, getThreadId(),
leaseTimeMs, lockReferenceIdGenerator.getNextReferenceId());
invoke(request, keyData, Long.MAX_VALUE);
}
private T invoke(ClientMessage clientMessage, Object key, long invocationTimeoutSeconds) {
final int partitionId = getContext().getPartitionService().getPartitionId(key);
try {
ClientInvocation clientInvocation = new ClientInvocation(getClient(), clientMessage, getName(), partitionId);
clientInvocation.setInvocationTimeoutMillis(invocationTimeoutSeconds);
final Future future = clientInvocation.invoke();
return (T) future.get();
} catch (Exception e) {
throw rethrow(e);
}
}
@Override
public boolean isLocked(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
Data keyData = toData(key);
ClientMessage request = MapIsLockedCodec.encodeRequest(name, keyData);
ClientMessage response = invoke(request, keyData);
return MapIsLockedCodec.decodeResponse(response);
}
@Override
public boolean tryLock(@Nonnull K key) {
try {
return tryLock(key, 0, null);
} catch (InterruptedException e) {
currentThread().interrupt();
return false;
}
}
@Override
public boolean tryLock(@Nonnull K key, long time, @Nullable TimeUnit timeunit) throws InterruptedException {
return tryLock(key, time, timeunit, UNSET, null);
}
@Override
public boolean tryLock(@Nonnull K key,
long time, @Nullable TimeUnit timeunit,
long leaseTime, @Nullable TimeUnit leaseUnit) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
Data keyData = toData(key);
long leaseTimeMillis = timeInMsOrTimeIfNullUnit(leaseTime, leaseUnit);
long timeoutMillis = timeInMsOrTimeIfNullUnit(time, timeunit);
ClientMessage request = MapTryLockCodec.encodeRequest(name, keyData, getThreadId(), leaseTimeMillis, timeoutMillis,
lockReferenceIdGenerator.getNextReferenceId());
ClientMessage response = invoke(request, keyData, Long.MAX_VALUE);
return MapTryLockCodec.decodeResponse(response);
}
@Override
public void unlock(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
Data keyData = toData(key);
ClientMessage request = MapUnlockCodec.encodeRequest(name, keyData, getThreadId(),
lockReferenceIdGenerator.getNextReferenceId());
invoke(request, keyData);
}
@Override
public void forceUnlock(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
Data keyData = toData(key);
ClientMessage request = MapForceUnlockCodec.encodeRequest(name, keyData, lockReferenceIdGenerator.getNextReferenceId());
invoke(request, keyData);
}
@Override
public String addInterceptor(@Nonnull MapInterceptor interceptor) {
checkNotNull(interceptor, "Interceptor should not be null!");
Data data = toData(interceptor);
ClientMessage request = MapAddInterceptorCodec.encodeRequest(name, data);
ClientMessage response = invoke(request);
return MapAddInterceptorCodec.decodeResponse(response);
}
@Override
public boolean removeInterceptor(@Nonnull String id) {
checkNotNull(id, "Interceptor ID should not be null!");
ClientMessage request = MapRemoveInterceptorCodec.encodeRequest(name, id);
ClientMessage response = invoke(request);
return MapRemoveInterceptorCodec.decodeResponse(response);
}
@Override
public UUID addEntryListener(@Nonnull MapListener listener, boolean includeValue) {
checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
ListenerAdapter listenerAdaptor = createListenerAdapter(listener);
return addEntryListenerInternal(listenerAdaptor, includeValue);
}
private UUID addEntryListenerInternal(ListenerAdapter listenerAdaptor, boolean includeValue) {
int listenerFlags = setAndGetListenerFlags(listenerAdaptor);
EventHandler handler = new ClientMapEventHandler(listenerAdaptor);
return registerListener(createMapEntryListenerCodec(includeValue, listenerFlags), handler);
}
private ListenerMessageCodec createMapEntryListenerCodec(final boolean includeValue, final int listenerFlags) {
return new ListenerMessageCodec() {
@Override
public ClientMessage encodeAddRequest(boolean localOnly) {
return MapAddEntryListenerCodec.encodeRequest(name, includeValue, listenerFlags, localOnly);
}
@Override
public UUID decodeAddResponse(ClientMessage clientMessage) {
return MapAddEntryListenerCodec.decodeResponse(clientMessage);
}
@Override
public ClientMessage encodeRemoveRequest(UUID realRegistrationId) {
return MapRemoveEntryListenerCodec.encodeRequest(name, realRegistrationId);
}
@Override
public boolean decodeRemoveResponse(ClientMessage clientMessage) {
return MapRemoveEntryListenerCodec.decodeResponse(clientMessage);
}
};
}
@Override
public boolean removeEntryListener(@Nonnull UUID registrationId) {
checkNotNull(registrationId, "Listener ID should not be null!");
return deregisterListener(registrationId);
}
@Override
public UUID addPartitionLostListener(@Nonnull MapPartitionLostListener listener) {
checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
// Handle dependency injection
listener = (MapPartitionLostListener) getSerializationService().getManagedContext().initialize(listener);
EventHandler handler = new ClientMapPartitionLostEventHandler(listener);
return registerListener(createMapPartitionListenerCodec(), handler);
}
private ListenerMessageCodec createMapPartitionListenerCodec() {
return new ListenerMessageCodec() {
@Override
public ClientMessage encodeAddRequest(boolean localOnly) {
return MapAddPartitionLostListenerCodec.encodeRequest(name, localOnly);
}
@Override
public UUID decodeAddResponse(ClientMessage clientMessage) {
return MapAddPartitionLostListenerCodec.decodeResponse(clientMessage);
}
@Override
public ClientMessage encodeRemoveRequest(UUID realRegistrationId) {
return MapRemovePartitionLostListenerCodec.encodeRequest(name, realRegistrationId);
}
@Override
public boolean decodeRemoveResponse(ClientMessage clientMessage) {
return MapRemovePartitionLostListenerCodec.decodeResponse(clientMessage);
}
};
}
@Override
public boolean removePartitionLostListener(@Nonnull UUID registrationId) {
checkNotNull(registrationId, "Listener ID should not be null!");
return deregisterListener(registrationId);
}
@Override
public UUID addEntryListener(@Nonnull MapListener listener, @Nonnull K key, boolean includeValue) {
checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
ListenerAdapter listenerAdaptor = createListenerAdapter(listener);
return addEntryListenerInternal(listenerAdaptor, key, includeValue);
}
private UUID addEntryListenerInternal(ListenerAdapter listenerAdaptor, K key, boolean includeValue) {
int listenerFlags = setAndGetListenerFlags(listenerAdaptor);
Data keyData = toData(key);
EventHandler handler = new ClientMapToKeyEventHandler(listenerAdaptor);
return registerListener(createMapEntryListenerToKeyCodec(includeValue, listenerFlags, keyData), handler);
}
private ListenerMessageCodec createMapEntryListenerToKeyCodec(final boolean includeValue, final int listenerFlags,
final Data keyData) {
return new ListenerMessageCodec() {
@Override
public ClientMessage encodeAddRequest(boolean localOnly) {
return MapAddEntryListenerToKeyCodec.encodeRequest(name, keyData, includeValue, listenerFlags, localOnly);
}
@Override
public UUID decodeAddResponse(ClientMessage clientMessage) {
return MapAddEntryListenerToKeyCodec.decodeResponse(clientMessage);
}
@Override
public ClientMessage encodeRemoveRequest(UUID realRegistrationId) {
return MapRemoveEntryListenerCodec.encodeRequest(name, realRegistrationId);
}
@Override
public boolean decodeRemoveResponse(ClientMessage clientMessage) {
return MapRemoveEntryListenerCodec.decodeResponse(clientMessage);
}
};
}
@Override
public UUID addEntryListener(@Nonnull MapListener listener,
@Nonnull Predicate predicate,
@Nullable K key,
boolean includeValue) {
checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
checkDoesNotContainPagingPredicate(predicate, "addEntryListener");
ListenerAdapter listenerAdaptor = createListenerAdapter(listener);
return key == null
? addEntryListenerInternal(listenerAdaptor, predicate, includeValue)
: addEntryListenerInternal(listenerAdaptor, predicate, key, includeValue);
}
private UUID addEntryListenerInternal(@Nonnull ListenerAdapter listenerAdaptor,
@Nonnull Predicate predicate,
@Nullable K key,
boolean includeValue) {
int listenerFlags = setAndGetListenerFlags(listenerAdaptor);
Data keyData = toData(key);
Data predicateData = toData(predicate);
EventHandler handler = new ClientMapToKeyWithPredicateEventHandler(listenerAdaptor);
ListenerMessageCodec codec = createEntryListenerToKeyWithPredicateCodec(
includeValue, listenerFlags, keyData, predicateData);
return registerListener(codec, handler);
}
private ListenerMessageCodec createEntryListenerToKeyWithPredicateCodec(final boolean includeValue, final int listenerFlags,
final Data keyData, final Data predicateData) {
return new ListenerMessageCodec() {
@Override
public ClientMessage encodeAddRequest(boolean localOnly) {
return MapAddEntryListenerToKeyWithPredicateCodec.encodeRequest(name, keyData, predicateData, includeValue,
listenerFlags, localOnly);
}
@Override
public UUID decodeAddResponse(ClientMessage clientMessage) {
return MapAddEntryListenerToKeyWithPredicateCodec.decodeResponse(clientMessage);
}
@Override
public ClientMessage encodeRemoveRequest(UUID realRegistrationId) {
return MapRemoveEntryListenerCodec.encodeRequest(name, realRegistrationId);
}
@Override
public boolean decodeRemoveResponse(ClientMessage clientMessage) {
return MapRemoveEntryListenerCodec.decodeResponse(clientMessage);
}
};
}
@Override
public UUID addEntryListener(@Nonnull MapListener listener,
@Nonnull Predicate predicate,
boolean includeValue) {
checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
checkDoesNotContainPagingPredicate(predicate, "addEntryListener");
ListenerAdapter listenerAdaptor = createListenerAdapter(listener);
return addEntryListenerInternal(listenerAdaptor, predicate, includeValue);
}
private UUID addEntryListenerInternal(ListenerAdapter listenerAdapter,
Predicate predicate,
boolean includeValue) {
int listenerFlags = setAndGetListenerFlags(listenerAdapter);
Data predicateData = toData(predicate);
EventHandler handler = new ClientMapWithPredicateEventHandler(listenerAdapter);
return registerListener(createEntryListenerWithPredicateCodec(includeValue, listenerFlags, predicateData), handler);
}
private ListenerMessageCodec createEntryListenerWithPredicateCodec(final boolean includeValue, final int listenerFlags,
final Data predicateData) {
return new ListenerMessageCodec() {
@Override
public ClientMessage encodeAddRequest(boolean localOnly) {
return MapAddEntryListenerWithPredicateCodec.encodeRequest(name, predicateData, includeValue, listenerFlags,
localOnly);
}
@Override
public UUID decodeAddResponse(ClientMessage clientMessage) {
return MapAddEntryListenerWithPredicateCodec.decodeResponse(clientMessage);
}
@Override
public ClientMessage encodeRemoveRequest(UUID realRegistrationId) {
return MapRemoveEntryListenerCodec.encodeRequest(name, realRegistrationId);
}
@Override
public boolean decodeRemoveResponse(ClientMessage clientMessage) {
return MapRemoveEntryListenerCodec.decodeResponse(clientMessage);
}
};
}
@Override
@SuppressWarnings("unchecked")
public EntryView getEntryView(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
Data keyData = toData(key);
ClientMessage request = MapGetEntryViewCodec.encodeRequest(name, keyData, getThreadId());
ClientMessage response = invoke(request, keyData);
MapGetEntryViewCodec.ResponseParameters parameters = MapGetEntryViewCodec.decodeResponse(response);
SimpleEntryView dataEntryView = parameters.response;
if (dataEntryView == null) {
return null;
}
// TODO: putCache
return new SimpleEntryView()
.withKey(toObject(dataEntryView.getKey()))
.withValue(toObject(dataEntryView.getValue()))
.withCost(dataEntryView.getCost())
.withCreationTime(dataEntryView.getCreationTime())
.withExpirationTime(dataEntryView.getExpirationTime())
.withHits(dataEntryView.getHits())
.withLastAccessTime(dataEntryView.getLastAccessTime())
.withLastStoredTime(dataEntryView.getLastStoredTime())
.withLastUpdateTime(dataEntryView.getLastUpdateTime())
.withVersion(dataEntryView.getVersion())
.withHits(dataEntryView.getHits())
.withTtl(dataEntryView.getTtl())
.withMaxIdle(parameters.maxIdle);
}
@Override
public boolean evict(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
return evictInternal(key);
}
protected boolean evictInternal(Object key) {
Data keyData = toData(key);
ClientMessage request = MapEvictCodec.encodeRequest(name, keyData, getThreadId());
ClientMessage response = invoke(request, keyData);
return MapEvictCodec.decodeResponse(response);
}
@Override
public void evictAll() {
ClientMessage request = MapEvictAllCodec.encodeRequest(name);
invoke(request);
}
@Override
public void loadAll(boolean replaceExistingValues) {
ClientMessage request = MapLoadAllCodec.encodeRequest(name, replaceExistingValues);
invoke(request);
}
@Override
public void loadAll(@Nonnull Set keys, boolean replaceExistingValues) {
checkNotNull(keys, "Parameter keys should not be null.");
if (keys.isEmpty()) {
return;
}
loadAllInternal(replaceExistingValues, keys);
}
protected void loadAllInternal(boolean replaceExistingValues, Collection> keys) {
Collection dataKeys = objectToDataCollection(keys, getSerializationService());
ClientMessage request = MapLoadGivenKeysCodec.encodeRequest(name, dataKeys, replaceExistingValues);
invoke(request);
}
@Nonnull
@Override
public Set keySet() {
ClientMessage request = MapKeySetCodec.encodeRequest(name);
ClientMessage response = invoke(request);
return (Set) new UnmodifiableLazySet(MapKeySetCodec.decodeResponse(response), getSerializationService());
}
@Override
public Map getAll(@Nullable Set keys) {
if (CollectionUtil.isEmpty(keys)) {
// Wrap emptyMap() into unmodifiableMap to make sure put/putAll methods throw UnsupportedOperationException
return Collections.unmodifiableMap(emptyMap());
}
int keysSize = keys.size();
Map> partitionToKeyData = new HashMap<>();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy