Java Code Examples for java.util.AbstractMap#Entry

The following examples show how to use java.util.AbstractMap#Entry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridDhtPartitionsStateValidator.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Processes given {@code counter} for partition {@code part} reported by {@code node}.
 * Populates {@code invalidPartitions} map if existing counter and current {@code counter} are different.
 *
 * @param invalidPartitions Invalid partitions map.
 * @param countersAndNodes Current map of counters and nodes by partitions.
 * @param part Processing partition.
 * @param node Node id.
 * @param counter Counter value reported by {@code node}.
 */
private void process(
    Map<Integer, Map<UUID, Long>> invalidPartitions,
    Map<Integer, AbstractMap.Entry<UUID, Long>> countersAndNodes,
    int part,
    UUID node,
    long counter
) {
    AbstractMap.Entry<UUID, Long> existingData = countersAndNodes.get(part);

    if (existingData == null)
        countersAndNodes.put(part, new AbstractMap.SimpleEntry<>(node, counter));

    if (existingData != null && counter != existingData.getValue()) {
        if (!invalidPartitions.containsKey(part)) {
            Map<UUID, Long> map = new HashMap<>();
            map.put(existingData.getKey(), existingData.getValue());
            invalidPartitions.put(part, map);
        }

        invalidPartitions.get(part).put(node, counter);
    }
}
 
Example 2
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testFloorEntry()
{
	AbstractMap.Entry<Integer, String> e = map.floorEntry(6);
	assertEquals(e.getKey(), (Integer)4);
			
	e = map.floorEntry(7);
	assertEquals(e.getKey(), (Integer)7);
}
 
Example 3
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testCeilingEntry()
{
	AbstractMap.Entry<Integer, String> e = map.ceilingEntry(6);
	assertEquals(e.getKey(), (Integer)7);
	
	e = map.ceilingEntry(7);
	assertEquals(e.getKey(), (Integer)7);
}
 
Example 4
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testHigherEntry()
{
	AbstractMap.Entry<Integer, String> e = map.higherEntry(4);
	assertEquals(e.getKey(), (Integer)7);
	
	e = map.higherEntry(7);
	assertEquals(e.getKey(), (Integer)8);
}
 
Example 5
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testPollFirstEntry()
{
	int size0 = map.size();
	AbstractMap.Entry<Integer, String> e = map.pollFirstEntry();
	int size1 = map.size();
	assertEquals(size0-1, size1);
	
	assertNull(map.get(1));
	assertEquals(e.getKey(), (Integer)1);
	assertEquals(e.getValue(), "one");
}
 
Example 6
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testPollLastEntry()
{
	int size0 = map.size();
	AbstractMap.Entry<Integer, String> e = map.pollLastEntry();
	int size1 = map.size();
	assertEquals(size0-1, size1);
	
	assertNull(map.get(10));
	assertEquals(e.getKey(), (Integer)10);
	assertEquals(e.getValue(), "ten");
}
 
Example 7
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public void testLowerEntry()
{
	AbstractMap.Entry<Integer,String> e = map.lowerEntry(4);
	assertEquals(e.getKey(), (Integer)3);
}
 
Example 8
Source File: GridDhtPartitionsStateValidator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Validate partitions update counters for given {@code top}.
 *
 * @param top Topology to validate.
 * @param messages Single messages received from all nodes.
 * @param ignoringNodes Nodes for what we ignore validation.
 * @return Invalid partitions map with following structure: (partId, (nodeId, updateCounter)).
 * If map is empty validation is successful.
 */
public Map<Integer, Map<UUID, Long>> validatePartitionsUpdateCounters(
    GridDhtPartitionTopology top,
    Map<UUID, GridDhtPartitionsSingleMessage> messages,
    Set<UUID> ignoringNodes
) {
    Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();

    Map<Integer, AbstractMap.Entry<UUID, Long>> updateCountersAndNodesByPartitions = new HashMap<>();

    // Populate counters statistics from local node partitions.
    for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
        if (part.state() != GridDhtPartitionState.OWNING)
            continue;

        if (part.updateCounter() == 0 && part.fullSize() == 0)
            continue;

        updateCountersAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.updateCounter()));
    }

    int partitions = top.partitions();

    // Then process and validate counters from other nodes.
    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : messages.entrySet()) {
        UUID nodeId = e.getKey();
        if (ignoringNodes.contains(nodeId))
            continue;

        final GridDhtPartitionsSingleMessage message = e.getValue();

        CachePartitionPartialCountersMap countersMap = message.partitionUpdateCounters(top.groupId(), partitions);

        Map<Integer, Long> sizesMap = message.partitionSizes(top.groupId());

        Set<Integer> ignorePartitions = shouldIgnore(top, nodeId, countersMap, sizesMap);

        for (int i = 0; i < countersMap.size(); i++) {
            int p = countersMap.partitionAt(i);

            if (ignorePartitions != null && ignorePartitions.contains(p))
                continue;

            long currentCounter = countersMap.updateCounterAt(i);

            process(invalidPartitions, updateCountersAndNodesByPartitions, p, nodeId, currentCounter);
        }
    }

    return invalidPartitions;
}
 
Example 9
Source File: GridDhtPartitionsStateValidator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Validate partitions cache sizes for given {@code top}.
 *
 * @param top Topology to validate.
 * @param messages Single messages received from all nodes.
 * @param ignoringNodes Nodes for what we ignore validation.
 * @return Invalid partitions map with following structure: (partId, (nodeId, cacheSize)).
 * If map is empty validation is successful.
 */
public Map<Integer, Map<UUID, Long>> validatePartitionsSizes(
    GridDhtPartitionTopology top,
    Map<UUID, GridDhtPartitionsSingleMessage> messages,
    Set<UUID> ignoringNodes
) {
    Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();

    Map<Integer, AbstractMap.Entry<UUID, Long>> sizesAndNodesByPartitions = new HashMap<>();

    // Populate sizes statistics from local node partitions.
    for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
        if (part.state() != GridDhtPartitionState.OWNING)
            continue;

        if (part.updateCounter() == 0 && part.fullSize() == 0)
            continue;

        sizesAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.fullSize()));
    }

    int partitions = top.partitions();

    // Then process and validate sizes from other nodes.
    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : messages.entrySet()) {
        UUID nodeId = e.getKey();
        if (ignoringNodes.contains(nodeId))
            continue;

        final GridDhtPartitionsSingleMessage message = e.getValue();

        CachePartitionPartialCountersMap countersMap = message.partitionUpdateCounters(top.groupId(), partitions);

        Map<Integer, Long> sizesMap = message.partitionSizes(top.groupId());

        Set<Integer> ignorePartitions = shouldIgnore(top, nodeId, countersMap, sizesMap);

        for (int i = 0; i < countersMap.size(); i++) {
            int p = countersMap.partitionAt(i);

            if (ignorePartitions != null && ignorePartitions.contains(p))
                continue;

            long currentSize = sizesMap.getOrDefault(p, 0L);

            process(invalidPartitions, sizesAndNodesByPartitions, p, nodeId, currentSize);
        }
    }

    return invalidPartitions;
}