You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geode.apache.org by Luke Shannon <ls...@pivotal.io> on 2015/10/19 15:54:20 UTC

Serialization per Region?

It looks like a serializer can only be configured per cache:
http://gemfire.docs.pivotal.io/latest/developing/data_serialization/use_pdx_serializer.html

I want to have certain regions go through a custom serializer and others
not.

Right now it looks the options are:
1. Put logic in the toData and fromData to decide to serialize or not
2. Utilize the Mapping Pdx Serializer and configure it to work on specific
classes:
http://docs.spring.io/spring-data-gemfire/docs/current/api/org/springframework/data/gemfire/mapping/MappingPdxSerializer.html

The challenge is there a tons of object types persisting to the cache. It
would be too much logic in step 1 and the config in step 2 would be pretty
messy.

The ideal solution would be to map a serializer to a Region...is this
possible?

Re: Serialization per Region?

Posted by John Blum <jb...@pivotal.io>.
The best thing to do is to associate objects (to be persisted) to certain
Regions (think value-constraint on the Region) and then use a "Composition
<https://en.wikipedia.org/wiki/Composite_pattern>" [0] of serializers based
on type.  As long as the same underlying serialization format is used, the
individual serializers can decide what to serialize based on the object's
type.  See for example this SDG test class
<https://github.com/spring-projects/spring-data-gemfire/blob/master/src/test/java/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest.java#L312-L430>
[1]
and associated configuration
<https://github.com/spring-projects/spring-data-gemfire/blob/master/src/test/resources/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest-context.xml#L31-L42>
 [2].

Of course, it seems you have a situation of 1-many, Region to objects (i.e.
Regions storing objects of multiple types) for each Region in the
applications which I would not recommend.  In addition, my suggestion to
does not preclude the fact you still need a serializer per object (not per
Region), which is consistent with GemFire... serializers work on objects,
not Regions as Dan pointed out.

Cheers,
John



[0] - https://en.wikipedia.org/wiki/Composite_pattern
[1] -
https://github.com/spring-projects/spring-data-gemfire/blob/master/src/test/java/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest.java#L312-L430
[2] -
https://github.com/spring-projects/spring-data-gemfire/blob/master/src/test/resources/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest-context.xml#L31-L42


On Mon, Oct 19, 2015 at 9:50 AM, Dan Smith <ds...@pivotal.io> wrote:

> Hi Luke,
>
> I don't think having different serializers for different regions is
> possible. The issue is that your objects may be serialized in places where
> there is no associated region, for example passing arguments to a function.
> You could also potentially copy an object from one region to another. So
> the serialization of objects is not really tied to a region at all.
>
> -Dan
>
> On Mon, Oct 19, 2015 at 6:54 AM, Luke Shannon <ls...@pivotal.io> wrote:
>
>> It looks like a serializer can only be configured per cache:
>>
>> http://gemfire.docs.pivotal.io/latest/developing/data_serialization/use_pdx_serializer.html
>>
>> I want to have certain regions go through a custom serializer and others
>> not.
>>
>> Right now it looks the options are:
>> 1. Put logic in the toData and fromData to decide to serialize or not
>> 2. Utilize the Mapping Pdx Serializer and configure it to work on
>> specific classes:
>> http://docs.spring.io/spring-data-gemfire/docs/current/api/org/springframework/data/gemfire/mapping/MappingPdxSerializer.html
>>
>> The challenge is there a tons of object types persisting to the cache. It
>> would be too much logic in step 1 and the config in step 2 would be pretty
>> messy.
>>
>> The ideal solution would be to map a serializer to a Region...is this
>> possible?
>>
>
>


-- 
-John
503-504-8657
john.blum10101 (skype)

Re: Serialization per Region?

Posted by Dan Smith <ds...@pivotal.io>.
Hi Luke,

I don't think having different serializers for different regions is
possible. The issue is that your objects may be serialized in places where
there is no associated region, for example passing arguments to a function.
You could also potentially copy an object from one region to another. So
the serialization of objects is not really tied to a region at all.

-Dan

On Mon, Oct 19, 2015 at 6:54 AM, Luke Shannon <ls...@pivotal.io> wrote:

> It looks like a serializer can only be configured per cache:
>
> http://gemfire.docs.pivotal.io/latest/developing/data_serialization/use_pdx_serializer.html
>
> I want to have certain regions go through a custom serializer and others
> not.
>
> Right now it looks the options are:
> 1. Put logic in the toData and fromData to decide to serialize or not
> 2. Utilize the Mapping Pdx Serializer and configure it to work on specific
> classes:
> http://docs.spring.io/spring-data-gemfire/docs/current/api/org/springframework/data/gemfire/mapping/MappingPdxSerializer.html
>
> The challenge is there a tons of object types persisting to the cache. It
> would be too much logic in step 1 and the config in step 2 would be pretty
> messy.
>
> The ideal solution would be to map a serializer to a Region...is this
> possible?
>