2 Replies Latest reply on Apr 8, 2015 6:47 AM by Mehdi Rakhshani

    Is calling iterator.remove() on a replicated cache supported by Infinispan?

    Mehdi Rakhshani Newbie

      I want a system where multiple app1's are adding entries to a named cache and
      an app2 is periodically processing the cache entries in the order they were added to the
      cache and removing them.

       

      Using Infinispan 6.0.0 running in Tomcat, attempting to call iterator.remove()
      on a replicated cache gets a java.lang.UnsupportedOperationException. Turning DEBUG log on
      does not provide any additional information.

       

      What is the appropriate way of iterating over the entries and removing them?

        • 1. Re: Is calling iterator.remove() on a replicated cache supported by Infinispan?
          Will Burns Expert

          The iterator remove method is not supported on keySet, values, or entrySet collections until version 7.0.  The reason for this is because in versions prior to 7.0 the collection these methods returned were just shallow copies and thus we didn't allow modifications to them. In 7.0 the collections returned are fully backed by the cache so updates are reflected in the other and vice versa.  See [1]

           

          If you want to remove an entry while iterating on it in 6.0, you can just call Cache.remove(Object key) method to remove the entry while iterating on the cache.  This won't throw a ConcurrentModificationException since the cache is a concurrent collection implementation.

           

          I wonder though you say

           

          Mehdi Rakhshani wrote:

           

          app2 is periodically processing the cache entries in the order they were added to the
          cache and removing them.

          The iterator does not return the entries in any specific order and could even change between invocations.  I am guessing you must be doing this ordering in your application somehow ?

           

          [1] Infinispan: Why doesn't Map.size return the size of the entire cluster?

          • 2. Re: Is calling iterator.remove() on a replicated cache supported by Infinispan?
            Mehdi Rakhshani Newbie

            Thanks for the reply. I ended up changing the design to not use the iterator.remove() and instead use cache.remove( key ) and to not rely on the order. I have put off upgrading to 7.x until hopefully more documentation on how to convert the configuration file is provided.