Search in sources :

Example 1 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry in project hazelcast by hazelcast.

the class CoalescedWriteBehindQueue method removeFirstOccurrence.

/**
     * Removes the first occurrence of the specified element in this queue
     * when searching it by starting from the head of this queue.
     *
     * @param incoming element to be removed.
     * @return <code>true</code> if removed successfully, <code>false</code> otherwise
     */
@Override
public boolean removeFirstOccurrence(DelayedEntry incoming) {
    Data incomingKey = (Data) incoming.getKey();
    Object incomingValue = incoming.getValue();
    DelayedEntry current = map.get(incomingKey);
    if (current == null) {
        return false;
    }
    Object currentValue = current.getValue();
    if (incomingValue == null && currentValue == null || incomingValue != null && currentValue != null && incomingValue.equals(currentValue)) {
        map.remove(incomingKey);
        return true;
    }
    return false;
}
Also used : Data(com.hazelcast.nio.serialization.Data) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 2 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry in project hazelcast by hazelcast.

the class CoalescedWriteBehindQueue method drainTo.

@Override
public int drainTo(Collection<DelayedEntry> collection) {
    checkNotNull(collection, "collection can not be null");
    Collection<DelayedEntry> delayedEntries = map.values();
    for (DelayedEntry delayedEntry : delayedEntries) {
        collection.add(delayedEntry);
    }
    map.clear();
    return collection.size();
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 3 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry in project hazelcast by hazelcast.

the class CyclicWriteBehindQueue method drainTo.

/**
     * Removes all available elements from this queue and adds them
     * to the given collection.
     *
     * @param collection all elements to be added to this collection.
     * @return number of removed items from this queue.
     */
@Override
public int drainTo(Collection<DelayedEntry> collection) {
    checkNotNull(collection, "collection can not be null");
    Iterator<DelayedEntry> iterator = deque.iterator();
    while (iterator.hasNext()) {
        DelayedEntry e = iterator.next();
        collection.add(e);
        iterator.remove();
    }
    resetCountIndex();
    return collection.size();
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 4 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry in project hazelcast by hazelcast.

the class DefaultWriteBehindProcessor method addToFails.

private void addToFails(List<DelayedEntry> fails, Map<Integer, List<DelayedEntry>> failsPerPartition) {
    if (fails == null || fails.isEmpty()) {
        return;
    }
    for (DelayedEntry entry : fails) {
        final int partitionId = entry.getPartitionId();
        List<DelayedEntry> delayedEntriesPerPartition = failsPerPartition.get(partitionId);
        if (delayedEntriesPerPartition == null) {
            delayedEntriesPerPartition = new ArrayList<DelayedEntry>();
            failsPerPartition.put(partitionId, delayedEntriesPerPartition);
        }
        delayedEntriesPerPartition.add(entry);
    }
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 5 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry in project hazelcast by hazelcast.

the class DefaultWriteBehindProcessor method convertToObject.

private Map convertToObject(Map<Object, DelayedEntry> batchMap) {
    final Map map = new HashMap();
    for (DelayedEntry entry : batchMap.values()) {
        final Object key = toObject(entry.getKey());
        final Object value = toObject(entry.getValue());
        map.put(key, value);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)28 ArrayList (java.util.ArrayList)9 Data (com.hazelcast.nio.serialization.Data)7 HashMap (java.util.HashMap)6 List (java.util.List)6 WriteBehindStore (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)5 Map (java.util.Map)5 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)4 WriteBehindQueue (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Queue (java.util.Queue)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.Test)3 MapConfig (com.hazelcast.config.MapConfig)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 MapDataStore (com.hazelcast.map.impl.mapstore.MapDataStore)1