Search in sources :

Example 1 with Object2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap in project geode by apache.

the class RangeIndex method saveMapping.

void saveMapping(Object key, Object indxResultSet, RegionEntry entry) {
    if (key == null) {
        List nullSet = nullEntries.get();
        if (nullSet == null) {
            nullSet = new ArrayList(1);
            nullEntries.set(nullSet);
        }
        nullSet.add(indxResultSet);
    } else if (key == QueryService.UNDEFINED) {
        List undefinedSet = undefinedEntries.get();
        if (undefinedSet == null) {
            undefinedSet = new ArrayList(1);
            undefinedEntries.set(undefinedSet);
        }
        if (indxResultSet != null) {
            if (indxResultSet.getClass().getName().startsWith("org.apache.geode.internal.cache.Token$") || indxResultSet == QueryService.UNDEFINED) {
            // do nothing, Entries are either removed or invalidated or destroyed
            // by other thread.
            } else {
                undefinedSet.add(indxResultSet);
            }
        }
    } else {
        Map keysToSetMap = keysToHashSetMap.get();
        if (keysToSetMap == null) {
            keysToSetMap = new Object2ObjectOpenHashMap(1);
            keysToHashSetMap.set(keysToSetMap);
        }
        Object value = keysToSetMap.get(key);
        if (value == null) {
            keysToSetMap.put(key, indxResultSet);
        } else if (value instanceof Collection) {
            ((Collection) value).add(indxResultSet);
        } else {
            List values = new ArrayList(2);
            values.add(indxResultSet);
            values.add(value);
            keysToSetMap.put(key, values);
        }
    }
    this.internalIndexStats.incNumUpdates();
}
Also used : Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SortedMap(java.util.SortedMap)

Example 2 with Object2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap in project geode by apache.

the class HashIndex method removeMapping.

/**
   * @param opCode one of OTHER_OP, BEFORE_UPDATE_OP, AFTER_UPDATE_OP.
   */
void removeMapping(RegionEntry entry, int opCode) throws IMQException {
    // + entry );
    if (opCode == BEFORE_UPDATE_OP) {
        // Either take key from reverse map OR evaluate it using IMQEvaluator.
        if (!IndexManager.isObjectModificationInplace()) {
            // It will always contain 1 element only, for this thread.
            entryToOldKeysMap.set(new Object2ObjectOpenHashMap(1));
            this.evaluator.evaluate(entry, false);
        }
    } else {
        // happen in same thread.
        if (entryToOldKeysMap != null) {
            entryToOldKeysMap.remove();
        }
        this.evaluator.evaluate(entry, false);
        this.internalIndexStats.incNumUpdates();
    }
}
Also used : Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)

Example 3 with Object2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap in project geode by apache.

the class PdxStringJUnitTest method testHashCodeEquals.

@Test
public void testHashCodeEquals() throws Exception {
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeString("secId", "abc");
    PdxInstanceImpl pi = (PdxInstanceImpl) pf.create();
    PdxString pdx1 = (PdxString) pi.getRawField("secId");
    Map<PdxString, String> map = new HashMap<PdxString, String>();
    map.put(pdx1, "abc");
    PdxString pdx2 = new PdxString("abc");
    assertEquals(map.get(pdx2), "abc");
    map = new Object2ObjectOpenHashMap();
    map.put(pdx1, "abc");
    assertEquals(map.get(pdx2), "abc");
}
Also used : Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) HashMap(java.util.HashMap) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) PdxString(org.apache.geode.pdx.internal.PdxString) PdxString(org.apache.geode.pdx.internal.PdxString) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with Object2ObjectOpenHashMap

use of it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap in project geode by apache.

the class MsgStreamer method create.

/**
   * Create message streamers splitting into versioned streamers, if required, for given list of
   * connections to remote nodes. This method can either return a single MsgStreamer object or a
   * List of MsgStreamer objects.
   */
public static BaseMsgStreamer create(List<?> cons, final DistributionMessage msg, final boolean directReply, final DMStats stats) {
    final Connection firstCon = (Connection) cons.get(0);
    // split into different versions if required
    Version version;
    final int numCons = cons.size();
    if (numCons > 1) {
        Connection con;
        Object2ObjectOpenHashMap versionToConnMap = null;
        int numVersioned = 0;
        for (Object c : cons) {
            con = (Connection) c;
            if ((version = con.getRemoteVersion()) != null) {
                if (versionToConnMap == null) {
                    versionToConnMap = new Object2ObjectOpenHashMap();
                }
                @SuppressWarnings("unchecked") ArrayList<Object> vcons = (ArrayList<Object>) versionToConnMap.get(version);
                if (vcons == null) {
                    vcons = new ArrayList<Object>(numCons);
                    versionToConnMap.put(version, vcons);
                }
                vcons.add(con);
                numVersioned++;
            }
        }
        if (versionToConnMap == null) {
            return new MsgStreamer(cons, msg, directReply, stats, firstCon.getSendBufferSize());
        } else {
            // if there is a versioned stream created, then split remaining
            // connections to unversioned stream
            final ArrayList<MsgStreamer> streamers = new ArrayList<MsgStreamer>(versionToConnMap.size() + 1);
            final int sendBufferSize = firstCon.getSendBufferSize();
            if (numCons > numVersioned) {
                // allocating list of numCons size so that as the result of
                // getSentConnections it may not need to be reallocted later
                final ArrayList<Object> unversionedCons = new ArrayList<Object>(numCons);
                for (Object c : cons) {
                    con = (Connection) c;
                    if ((version = con.getRemoteVersion()) == null) {
                        unversionedCons.add(con);
                    }
                }
                streamers.add(new MsgStreamer(unversionedCons, msg, directReply, stats, sendBufferSize));
            }
            for (ObjectIterator<Object2ObjectMap.Entry> itr = versionToConnMap.object2ObjectEntrySet().fastIterator(); itr.hasNext(); ) {
                Object2ObjectMap.Entry entry = itr.next();
                Object ver = entry.getKey();
                Object l = entry.getValue();
                streamers.add(new VersionedMsgStreamer((List<?>) l, msg, directReply, stats, sendBufferSize, (Version) ver));
            }
            return new MsgStreamerList(streamers);
        }
    } else if ((version = firstCon.getRemoteVersion()) == null) {
        return new MsgStreamer(cons, msg, directReply, stats, firstCon.getSendBufferSize());
    } else {
        // create a single VersionedMsgStreamer
        return new VersionedMsgStreamer(cons, msg, directReply, stats, firstCon.getSendBufferSize(), version);
    }
}
Also used : ArrayList(java.util.ArrayList) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Object2ObjectMap(it.unimi.dsi.fastutil.objects.Object2ObjectMap) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Object2ObjectMap (it.unimi.dsi.fastutil.objects.Object2ObjectMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 SortedMap (java.util.SortedMap)1 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)1 PdxString (org.apache.geode.pdx.internal.PdxString)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)1 Test (org.junit.Test)1