protected virtual bool TryPutInternal(IData keyData, TValue value, long timeout, TimeUnit timeunit) { var valueData = ToData(value); var request = MapTryPutCodec.EncodeRequest(Name, keyData, valueData, GetThreadId(), timeunit.ToMillis(timeout)); var result = Invoke(request, keyData); var response = MapTryPutCodec.DecodeResponse(result).Response; return(response); }
/// <summary> /// Tries to set an entry within a timeout. /// </summary> /// <param name="keyData">A key.</param> /// <param name="valueData">A value.</param> /// <param name="serverTimeout">A timeout.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <returns>true if the entry was set; otherwise false.</returns> /// <remarks> /// <para>This method returns false when no lock on the key could be /// acquired within the timeout.</para> /// </remarks> protected virtual async Task <bool> TrySetAsync(IData keyData, IData valueData, TimeSpan serverTimeout, CancellationToken cancellationToken) { var timeoutMs = serverTimeout.RoundedMilliseconds(false); // codec: 0 = server, -1 = infinite var requestMessage = MapTryPutCodec.EncodeRequest(Name, keyData, valueData, ContextId, timeoutMs); var responseMessage = await Cluster.Messaging.SendToKeyPartitionOwnerAsync(requestMessage, keyData, cancellationToken).CfAwait(); var response = MapTryPutCodec.DecodeResponse(responseMessage).Response; return(response); }
public bool TryPut(K key, V value, long timeout, TimeUnit timeunit) { var keyData = ToData(key); var valueData = ToData(value); var request = MapTryPutCodec.EncodeRequest(GetName(), keyData, valueData, ThreadUtil.GetThreadId(), timeunit.ToMillis(timeout)); var result = Invoke(request, keyData); var response = MapTryPutCodec.DecodeResponse(result).response; if (response) { InvalidateNearCacheEntry(keyData); } return(response); }