All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.util.IConcurrentMap Maven / Gradle / Ivy

There is a newer version: 4.5.4
Show newest version
/*
 * Copyright (c) 2008-2018, 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.util;

import com.hazelcast.core.IBiFunction;
import com.hazelcast.core.IFunction;


/**
 * A {@link java.util.concurrent.ConcurrentMap} with applyIfAbsent function.
 *
 * 

Memory consistency effects: As with other concurrent * collections, actions in a thread prior to placing an object into a * {@code ConcurrentMap} as a key or value * happen-before * actions subsequent to the access or removal of that object from * the {@code ConcurrentMap} in another thread. * * * @param the type of keys maintained by this map * @param the type of mapped values */ public interface IConcurrentMap extends java.util.concurrent.ConcurrentMap { /** * {@inheritDoc} * * @implSpec * The default implementation is equivalent to the following steps for this * {@code map}, then returning the current value or {@code null} if now * absent: * *

 {@code
     * if (map.get(key) == null) {
     *     V newValue = mappingFunction.apply(key);
     *     if (newValue != null)
     *         return map.putIfAbsent(key, newValue);
     * }
     * }
* * The default implementation may retry these steps when multiple * threads attempt updates including potentially calling the mapping * function multiple times. * *

This implementation assumes that the ConcurrentMap cannot contain null * values and {@code get()} returning null unambiguously means the key is * absent. Implementations which support null values must * override this default implementation. * * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ V applyIfAbsent(K key, IFunction mappingFunction); /** * {@inheritDoc} * * @implSpec * The default implementation is equivalent to performing the following * steps for this {@code map}, then returning the current value or * {@code null} if now absent. : * *

 {@code
     * if (map.get(key) != null) {
     *     V oldValue = map.get(key);
     *     V newValue = remappingFunction.apply(key, oldValue);
     *     if (newValue != null)
     *         map.replace(key, oldValue, newValue);
     *     else
     *         map.remove(key, oldValue);
     * }
     * }
* * The default implementation may retry these steps when multiple threads * attempt updates including potentially calling the remapping function * multiple times. * *

This implementation assumes that the ConcurrentMap cannot contain null * values and {@code get()} returning null unambiguously means the key is * absent. Implementations which support null values must * override this default implementation. * * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ V applyIfPresent(K key, IBiFunction mappingFunction); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy