-
1. Re: storeAsBinary behaviour
galder.zamarreno Jul 26, 2011 3:55 AM (in response to markaddy)Mark, not sure I understand what you're asking exactly. Is it that you want Infinispan to *only* store the serialized (byte[]) form in memory and no reference to the original instance?
To understand the current design of storeAsBinary, you need to understand where it's coming from. The aim originally was to provide lazy deserialization which effectively allows data in the receiver side to be deserialized lazily, when data is requested, with the assumption that the right classloader would be in place to be able to deserialize data. Often, when data is replicated to another node, the thread receiving the data might not have access to the right classloader, and so a normal embedded configuration would break with ClassNotFoundException or similar.
Taking this into account, what now is called 'storeAsBinary' is not a true reflection of what happens underneath. In a lazy deserialization case, you normally work with the instances and the binary form is just to allow deserialization to happen when data is request lazily. So, the data is either in one form or the other, hence why you see the MarshalledValue with two fields. Btw, those log messages look a bit outdated. I'd suggest moving to the latest Infinispan version which provides more info (currently 5.0.0.CR8).
Even though we don't provide a pure byte[] form of storing data in embedded more, it shouldn't be difficult for you to work that out. All you need to do is mimic what the Java HotRod client does with the data it receives which is converted into a byte[] using the GenericJBossMarshaller. Once you have got hold of the Marshaller (interface), all you have to do is call objectToByteBuffer() to convert into a byte[] and objectFromByteBuffer() to do the opposite work. See RemoteCacheImpl.bytes2obj() and RemoteCacheImpl.obj2bytes() to see this in action.
-
2. Re: storeAsBinary behaviour
markaddy Jul 26, 2011 4:16 AM (in response to galder.zamarreno)Hi Galder,
Yes, only store byte[] - We have already done as you suggest, grabbed the Marshaller and serialized entries before placing in the cache, reversed the process when retrieving entries from cache. It works well allowing us to reduce memory usage in embedded mode without any significant overhead. I thought this may be a potentially useful configuration option.
Thanks
Mark