Example usage for java.util.concurrent ConcurrentMap remove

List of usage examples for java.util.concurrent ConcurrentMap remove

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentMap remove.

Prototype

boolean remove(Object key, Object value);

Source Link

Document

Removes the entry for a key only if currently mapped to a given value.

Usage

From source file:Main.java

public static void main(String[] args) {
    ConcurrentMap<String, String> cMap = new ConcurrentHashMap<>();
    cMap.put("A", "A");

    System.out.println("Concurrent Map: " + cMap);

    System.out.println(cMap.putIfAbsent("A", "1"));
    System.out.println(cMap.putIfAbsent("B", "B"));
    System.out.println(cMap.remove("A", "B"));
    System.out.println(cMap.replace("A", "B"));

    System.out.println("Concurrent Map: " + cMap);
}

From source file:com.yahoo.pulsar.client.impl.ConnectionPool.java

private void cleanupConnection(InetSocketAddress address, int connectionKey,
        CompletableFuture<ClientCnx> connectionFuture) {
    ConcurrentMap<Integer, CompletableFuture<ClientCnx>> map = pool.get(address);
    if (map != null) {
        map.remove(connectionKey, connectionFuture);
    }//from   w w w  .j  a  v  a 2s.  co  m
}

From source file:org.apache.hadoop.hbase.client.MetaCache.java

/**
 * Delete a cached location, no matter what it is. Called when we were told to not use cache.
 * @param tableName tableName//  ww  w.j  a v a 2 s.c o m
 * @param row
 */
public void clearCache(final TableName tableName, final byte[] row) {
    ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);

    RegionLocations regionLocations = getCachedLocation(tableName, row);
    if (regionLocations != null) {
        byte[] startKey = regionLocations.getRegionLocation().getRegionInfo().getStartKey();
        boolean removed = tableLocations.remove(startKey, regionLocations);
        if (removed && LOG.isTraceEnabled()) {
            LOG.trace("Removed " + regionLocations + " from cache");
        }
    }
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap", expectedExceptions = NullPointerException.class)
public void removeConditionally_withNullKey(ConcurrentMap<Integer, Integer> map) {
    map.remove(null, 2);
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap", expectedExceptions = NullPointerException.class)
public void removeConditionally_withNullEntry(ConcurrentMap<Integer, Integer> map) {
    map.remove(null, null);
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "warmedMap")
public void removeConditionally_withNullValue(ConcurrentMap<Integer, Integer> map) {
    assertThat(map.remove(1, null), is(false)); // matches CHM
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap")
public void removeConditionally_whenEmpty(ConcurrentMap<Integer, Integer> map) {
    assertThat(map.remove(1, 2), is(false));
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap")
public void removeConditionally(ConcurrentMap<Integer, Integer> map) {
    map.put(1, 2);//from   ww  w .  j  ava 2s  .  c  o  m
    assertThat(map.remove(1, -2), is(false));
    assertThat(map.remove(1, 2), is(true));
    assertThat(map.get(1), is(nullValue()));
    assertThat(map.containsKey(1), is(false));
    assertThat(map.containsValue(2), is(false));
    assertThat(map, is(emptyMap()));
}

From source file:org.apache.hadoop.hbase.client.MetaCache.java

public void clearCache(final HRegionLocation location) {
    if (location == null) {
        return;//w  ww. j av  a 2  s .  c  om
    }
    TableName tableName = location.getRegionInfo().getTable();
    ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);
    RegionLocations regionLocations = tableLocations.get(location.getRegionInfo().getStartKey());
    if (regionLocations != null) {
        RegionLocations updatedLocations = regionLocations.remove(location);
        boolean removed = false;
        if (updatedLocations != regionLocations) {
            if (updatedLocations.isEmpty()) {
                removed = tableLocations.remove(location.getRegionInfo().getStartKey(), regionLocations);
            } else {
                removed = tableLocations.replace(location.getRegionInfo().getStartKey(), regionLocations,
                        updatedLocations);
            }
            if (removed && LOG.isTraceEnabled()) {
                LOG.trace("Removed " + location + " from cache");
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.client.MetaCache.java

/**
 * Delete a cached location for a table, row and server
 *///from   ww w  .  j ava2 s  .com
public void clearCache(final TableName tableName, final byte[] row, ServerName serverName) {
    ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);

    RegionLocations regionLocations = getCachedLocation(tableName, row);
    if (regionLocations != null) {
        RegionLocations updatedLocations = regionLocations.removeByServer(serverName);
        if (updatedLocations != regionLocations) {
            byte[] startKey = regionLocations.getRegionLocation().getRegionInfo().getStartKey();
            boolean removed = false;
            if (updatedLocations.isEmpty()) {
                removed = tableLocations.remove(startKey, regionLocations);
            } else {
                removed = tableLocations.replace(startKey, regionLocations, updatedLocations);
            }
            if (removed && LOG.isTraceEnabled()) {
                LOG.trace("Removed locations of table: " + tableName + " ,row: " + Bytes.toString(row)
                        + " mapping to server: " + serverName + " from cache");
            }
        }
    }
}