1 2 3 Previous Next 42 Replies Latest reply on Jul 6, 2017 4:30 AM by galder.zamarreno Go to original post
      • 15. Re: remote cache entrySet stream throws unsupported exception
        william.burns

        This is because your lambda is capturing the Cache object and trying to serialize it. A cache however is not serializable. You should use the https://docs.jboss.org/infinispan/9.1/apidocs/org/infinispan/CacheStream.html#forEach-java.util.function.BiConsumer-

        CacheStream (Infinispan JavaDoc All 9.1.0.Alpha1 API) method instead, this allows for the lambda to be serialized across and then passes the cache into the lambda when it is on the respective node.  This is the same thing that is done at https://stackoverflow.com/questions/43463011/best-way-to-remove-cache-entry-based-on-predicate-in-infinispan

        caching - Best way to remove cache entry based on predicate in infinispan? - Stack Overflow .

        • 16. Re: remote cache entrySet stream throws unsupported exception
          sea_shankar

          Yes I saw this on stack overflow, but if you do that:

           

          Cache<Object, Object> cache = (Cache<Object, Object>) taskContext.getCache().get();

          cache.entrySet().stream().filter(e -> e.getKey().toString().contains("sessionid"))

                          .forEach((cache, e) -> cache.remove(e.getKey()));

           

          You would get a "Lambda expression's parameter cache cannot redeclare another local variable defined in an enclosing scope."

          • 17. Re: remote cache entrySet stream throws unsupported exception
            william.burns

            You can rename the lambda variable to whatever you want, maybe just name it c to not have a duplicate.

             

            Cache<Object, Object> cache = (Cache<Object, Object>) taskContext.getCache().get();

            cache.entrySet().stream().filter(e -> e.getKey().toString().contains("sessionid"))

                            .forEach((c, e) -> c.remove(e.getKey()));

             

            Also to answer your previous question, the TaskContext.getCache returns the default cache. If you want to get a specific cache call getCacheManger().getCache(name);  Check out infinispan/TaskContext.java at master · infinispan/infinispan · GitHub

            • 18. Re: remote cache entrySet stream throws unsupported exception
              sea_shankar

              nadirx

               

              I also noticed something else, perhaps something to do with serialization:

               

              cache.keySet().stream().forEach(e -> log.info("-------------------" + e.toString()));

                      log.info("*****************");

              cache.entrySet().stream().forEach(e -> log.info("-------------------" + e.getKey().toString()));

               

              This is what get's printed in the server logs:

               

              16:34:07,369 INFO  (HotRod-ServerHandler-6-50) -------------------[B@47d3d2e3

              16:34:07,369 INFO  (HotRod-ServerHandler-6-50) -------------------[B@49143469

              16:34:07,370 INFO  (HotRod-ServerHandler-6-50) -------------------[B@4d2bb993

              16:34:07,370 INFO  (HotRod-ServerHandler-6-50) -------------------[B@8293e52

              16:34:07,370 INFO  (HotRod-ServerHandler-6-50) -------------------[B@5134b17e

               

              I am trying to get the toString of the object, which when I run locally I get: SimpleKey [sessionId, 1, test]

               

              On the server, I get: [B@47d3d2e3

               

              The SimpleKey is from the Spring Api and is serializable.  Any clue as to why this is?  I tried packaging in the SimpleKey.class with the JAR, but that threw some error.  

              • 19. Re: remote cache entrySet stream throws unsupported exception
                william.burns

                Keys and values when using the client are stored as byte[] objects so that you don't incur additional performance hit of having to de/serialize the object as it has to be sent to and from clients. You can enable compatibility mode in the server to have them stored as the Java object instead, but this will also incur the serialization overhead when doing regular client operations. You can read about compatibility mode at Infinispan 9.0 User Guide

                • 20. Re: remote cache entrySet stream throws unsupported exception
                  sea_shankar

                  How bad is the overhead?  I guess if I can't filter on the server without having them stored as java objects, it has to be incurred.  Will take a look at the compatibility mode. Sorry for all the questions, things keep getting added on.

                  • 21. Re: remote cache entrySet stream throws unsupported exception
                    sea_shankar

                    So it doesn't seem like for the compatibility mode you have to do much?

                     

                    I just added this to my config:

                    <local-cache name="compatibility">

                            <compatibility enabled="true"/>

                    </local-cache>

                     

                    I am still getting the values in bytes when I do e.toString().

                    • 22. Re: remote cache entrySet stream throws unsupported exception
                      william.burns

                      That is all you should have to do is add <compatibility enabled="true"/> to your existing cache. My guess is that your client is connecting to a different cache or even the default cache. In your case you are only enabling compatibility for a cache named "compatibility".

                      • 23. Re: remote cache entrySet stream throws unsupported exception
                        william.burns

                        Oh and in regards to the extra over head. Basically you have an extra deserialization step on a put and an extra serialization step on a read when accessing data from the client. Embedded caches have this overhead as well, so it should be very minimal.

                        • 24. Re: remote cache entrySet stream throws unsupported exception
                          sea_shankar

                          Ahhh you were right.  I enabled compatibility on a cache named compatibility.  I thought in the documentation you needed to have a local cache with compatibility on smh

                           

                          Do I need to put the SimpleKey class on the server or something?  I get this error:

                           

                          2017-06-07 22:14:22 WARN [XNIO-2 task-1] o.i.c.h.i.p.Codec21 [Codec20.java:361] - ISPN004005: Error received from the server: java.lang.ClassNotFoundException: org.springframework.cache.interceptor.SimpleKey from [Module "org.infinispan.commons:main" from local module loader @2471cca7 (finder: local module finder @5fe5c6f (roots: /Users/snvr/Desktop/Infinispan/infinispan-server-9.0.1.Final/modules,/Users/snvr/Desktop/Infinispan/infinispan-server-9.0.1.Final/modules/system/layers/base))]

                          2017-06-07 22:14:22 ERROR [XNIO-2 task-1] c.p.c.r.e.a.ExceptionMapper [ExceptionMapper.java:61] - java.lang.ClassNotFoundException: org.springframework.cache.interceptor.SimpleKey from [Module "org.infinispan.commons:main" from local module loader @2471cca7 (finder: local module finder @5fe5c6f (roots: /Users/blah/Desktop/Infinispan/infinispan-server-9.0.1.Final/modules,/Users/blah/Desktop/Infinispan/infinispan-server-9.0.1.Final/modules/system/layers/base))]

                          • 25. Re: remote cache entrySet stream throws unsupported exception
                            william.burns

                            You should be able to deploy the .class file in the same jar that has your ServerTask .class file. I believe

                            • 26. Re: remote cache entrySet stream throws unsupported exception
                              sea_shankar

                              Yup thought of that but get this error when deploying:

                               

                              "WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"session-task.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"session-task.jar\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"session-task.jar\"

                                  Caused by: java.lang.IllegalStateException: DGISPN0122: Could not instantiate class org.springframework.cache.interceptor.SimpleKey"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.unit.\"session-task.jar\".POST_MODULE"],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}}}

                              • 27. Re: remote cache entrySet stream throws unsupported exception
                                sea_shankar

                                This is the script I used, similar to the one in the Integration Tests:

                                    

                                JavaArchive jar = ShrinkWrap.create(JavaArchive.class);

                                       

                                        jar.addClass(ClearSessionTask.class);

                                        jar.addClass(SimpleKey.class);

                                        jar.addAsServiceProvider(ServerTask.class, ClearSessionTask.class, SimpleKey.class);

                                        jar.addAsManifestResource("MANIFEST.MF");

                                 

                                        File f = new File("/Users/blah/Desktop", "session-task.jar");

                                        jar.as(ZipExporter.class).exportTo(f, true);

                                • 28. Re: remote cache entrySet stream throws unsupported exception
                                  william.burns

                                  SimpleKey is not a service provider for ServerTask. Removing that should fix it :fingers_crossed:

                                   

                                  jar.addAsServiceProvider(ServerTask.class, ClearSessionTask.class);

                                  • 29. Re: remote cache entrySet stream throws unsupported exception
                                    sea_shankar

                                    That did it! but still getting the same error when trying to do put in compatibility mode (error doesn't occur if I take that mode out):

                                     

                                    ISPN004005: Error received from the server: java.lang.ClassNotFoundException: org.springframework.cache.interceptor.SimpleKey from [Module "org.infinispan.commons:main" from local module loader @2471cca7 (finder: local module finder @5fe5c6f (roots: /Users/snvr/Desktop/Infinispan/infinispan-server-9.0.1.Final/modules,/Users/snvr/Desktop/Infinispan/infinispan-server-9.0.1.Final/modules/system/layers/base))]

                                     

                                    Is there something that has to be done in the modules as the error suggests?