Search code examples
javaignite

Does ignite queue has some method to check if the queue created or not, just like the cache


Does ignite queue has some method to check if the queue created or not, just like the cache?

For ignite cache, i could use somethin like:

        if( txInfoCache.get(txType) == null ) {
            txInfoCache.put(txType, new TreeMap<Long, InfoRecord>());
        }

But when i try to use this to do with queue, it just create a new one

        CollectionConfiguration colCfg = new CollectionConfiguration();

        IgniteQueue<InfoRecord>  queue =
                ignite.queue("ResultRecordQueue_" + txType, 0, null);

        // never go into this judge
        if (queue == null) {
            queue = ignite.queue("ResultRecordQueue_" + txType, 0, colCfg);
        }

Solution

  • I don't quite understand your code. First of all, the following code snippet determines if the txInfoCache cache contains an entry for the given key txType and if it does not contain an entry associated with the key, it associates the specified key with the given value.

    if(txInfoCache.get(txType) == null) {
        txInfoCache.put(txType, new TreeMap<Long, InfoRecord>());
    }
    

    It can be changed to txInfoCache.putIfAbsent(txType, new TreeMap<Long, InfoRecord>()).

    As for the second part of your question, I just checked Apache Ignite 2.4 and it works well. Ignite.queue(String name, int cap, @Nullable CollectionConfiguration cfg) method returns null if named queue does not exist and CollectionConfiguration is null. Please make sure that this queue was not created earlier.