3 Replies Latest reply on Dec 21, 2016 5:11 AM by Radim Vansa

    Marshalling non serializeable objects to a RemoteCache

    Andreas Öh Newbie


      I've problems marshalling objects to a RemoteCache.

      I believe the problem is that the objects I try to serialize does not implement Serializable and I have no way of modify these classes.


      Exception in thread "main" org.infinispan.client.hotrod.exceptions.HotRodClientException:: Unable to marshall object of type [se.codeispoetry.infinispan.SimpleMessage]

          at org.infinispan.client.hotrod.impl.RemoteCacheImpl.obj2bytes(RemoteCacheImpl.java:681)


      Caused by: java.io.NotSerializableException: se.codeispoetry.infinispan.SimpleMessage



      I've tried to implement an AdvancedExternalizer and applying it to the configuration as described in the Infinispan User guide Infinispan 8.2 User Guide but have problems figuring out how to apply it to the ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder). I think the user guide does not mention the case with programmatic configuration using a RemoteCache.


      When using a RemoteCache, is this at all possible or are my options either to "hard wire" the externalizers in my xml configuration or use the ProtoStreamMarshaller instead? Does that have any implications on performance compared to using JBossMarshaller.


      I'm using Infinispan 8.2.5




        • 1. Re: Marshalling non serializeable objects to a RemoteCache
          Radim Vansa Master

          That example is probably for embedded caches. RemoteCache does not use any XML file, it's either a programmatic configuration or properties file.


          Besides alternative marshallers (such as ProtoStreamMarshaller), you could also extend AbstractJBossmarshaller and provide a custom ClassExternalizerFactory. Then you would use your marshaller in programmatic configuration or set property  infinispan.client.hotrod.marshaller to this class.

          • 2. Re: Marshalling non serializeable objects to a RemoteCache
            Andreas Öh Newbie

            Hi Radim,

            Thanks for your suggestions, it worked.


            Do you know the reason why this could not be covered by the AdvancedExternalizer also for the hotrod configuration? It seems similar enough so one should be able to hook up the AdvancedExternalizers in pretty much the same way I now implement the Marshaller and the Externalizer factory and then hook them into the configuration with the .marshaller(...) config.


            Also, I guess this covers a distribution as well? Once the entities are stored in Infinispan it can manage to distribute them according to its own protocol.


            Again, thanks.


            • 3. Re: Marshalling non serializeable objects to a RemoteCache
              Radim Vansa Master

              Probably because nobody asked for more convenient way before But there are few technical difficulties:


              1) You have to make sure all clients register the same marshallers/externalizers. Besides the maintenance difficulties (you need to update all clients when you do a change in marshalled classes), this does not allow you to combine clients in C++, C#, the less accessing the same data via REST server etc.

              2) Server still considers your data opaque, so you can't do querying (you would have to register the externalizer on server, too).


              Generally, these problems are solved with Protobuf format, so we focus on that approach in cases when default does not work. Regrettably I don't have any numbers at hand to show you some comparison of JBoss Marshalling/Protobuf to give a perf guidance.