Re: Hazelcast : Issue regarding Serialization

3,550 views
Skip to first unread message

Enes Akar

unread,
Aug 5, 2013, 5:35:23 AM8/5/13
to Sameer Middha, haze...@googlegroups.com
Can you post your code sample? How you configure and your domain class?


On Mon, Aug 5, 2013 at 12:30 PM, Sameer Middha <sameer...@tcs.com> wrote:
Hi Team,

Currently we use community edition of hazel cast  2.5 version.

We are facing serialization issue while running query using sql predicate on hazel cast cache.

So based on the few of the posts and documentation in order to implement custom serilaization i switched to version 3.0

But below are the issues i am facing while implemnting custom serialization on version 3.0:

1) I am trying to implement type serializer but it seems like there is no TypeSerializer interface class in hazel cast version 3.0 and no way to register the class as well.

2) I tried implementing StreamSerializer but unable to register the serializer using SerializationConfig as per the example mentioned in documentation

It always gives an exception that object is not serializable.

Please let me know if you can provide any suggestions related to above.
or let me know if need any additional info


Thanks & Regards
Sameer Middha

=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you




--
Enes Akar
Hazelcast | Open source in-memory data grid
Mobile: +90.507.150.56.71

Enes Akar

unread,
Aug 5, 2013, 6:18:28 AM8/5/13
to Sameer Middha, haze...@googlegroups.com
TypeSerializer has been replaced by StreamSerializer and ByteArraySerializer.


On Mon, Aug 5, 2013 at 1:17 PM, Sameer Middha <sameer...@tcs.com> wrote:
Hi Enes,

Thanks for the reply. Sure will send the code snippet in a while.

Meanwhile can you please confirm if hazelcast 3.0 version jar supports TypeSerializer, because I have been trying to implement that using version 3.0 but
did not find TypeSerializer interface class , the way it is there in version 2.5 ie AbstractSerializer and DefaultSerializer containing TypeSerializer


Thanks & Regards
Sameer Middha
Tata Consultancy Services
15 Changi Business Park
Central 1 #05-01
Invensys Building
Singapore - 486047
Singapore
Ph:- +6565922715
Cell:- +6586131347
Mailto: sameer...@tcs.com
Website:
http://www.tcs.com
____________________________________________
Experience certainty.        IT Services
                       Business Solutions
                       Consulting
____________________________________________



From: Enes Akar <en...@hazelcast.com>
To: Sameer Middha <sameer...@tcs.com>
Cc: haze...@googlegroups.com
Date: 08/05/2013 05:35 PM
Subject: Re: Hazelcast : Issue regarding Serialization


Sameer Middha

unread,
Aug 5, 2013, 6:17:06 AM8/5/13
to Enes Akar, haze...@googlegroups.com
Hi Enes,

Thanks for the reply. Sure will send the code snippet in a while.

Meanwhile can you please confirm if hazelcast 3.0 version jar supports TypeSerializer, because I have been trying to implement that using version 3.0 but
did not find TypeSerializer interface class , the way it is there in version 2.5 ie AbstractSerializer and DefaultSerializer containing TypeSerializer


Thanks & Regards
Sameer Middha
http://www.tcs.com

Sameer Middha

unread,
Aug 5, 2013, 6:58:15 AM8/5/13
to Enes Akar, haze...@googlegroups.com
Hi Enes,

Please find below code snippet  :


Hazel Server code Snippet :

Config cfg = new FileSystemXmlConfig(configFile);
SerializerConfig sc = new SerializerConfig();
sc.setImplementation(new SampleObjectStreamSerializer()).setTypeClass(SampleObject.class);
cfg.getSerializationConfig().addSerializerConfig(sc);
Hazelcast.newHazelcastInstance(cfg);

Hazel Client code Snippet :

ClientConfig clientConfig = new ClientConfig();
 clientConfig.addAddress(ipConfig);
 client = HazelcastClient.newHazelcastClient(clientConfig);

Domain Object code Snippet :

public class SampleObject { //implements Serializable {
     
     private  Long ID;
     private  String LOCATION_ID;
     private  String TYPE;
     private  String COMMENTS;
     private  Long VERSION_NO;
     private  String ACTION;

public SampleObject(){
         
     }
     
     public SampleObject(Record r) {

          this.ID = r.getID();
          this.LOCATION_ID = r.getLOCATION_ID();
          this.TYPE = r.getTYPE();
          this.COMMENTS = r.getCOMMENTS();
          this.VERSION_NO = r.getVERSION_NO();
          this.ACTION = r.getACTION();

     }
     
     public Long getID() {
          return ID;
     }
     public String getLOCATION_ID() {
          return LOCATION_ID;
     }
     public String getTYPE() {
          return TYPE;
     }
     public String getCOMMENTS() {
          return COMMENTS;
     }
     public Long getVERSION_NO() {
          return VERSION_NO;
     }
     public String getACTION() {
          return ACTION;
     }
}

Stream Serializer code snippet :

public class SampleObjectStreamSerializer implements StreamSerializer<SampleObject> {
     
     public SampleObjectStreamSerializer(){
     }

     @Override
     public SampleObject read(ObjectDataInput in) throws IOException {
          System.out.println("Reading using custom serializer....");
          final InputStream is = (InputStream) in;
          XMLDecoder decoder = new XMLDecoder(is);
          SampleObject so = (SampleObject) decoder.readObject();
          return so;
     }

     @Override
     public void write(ObjectDataOutput out, SampleObject sample) throws IOException {
          System.out.println("Writing using custom serializer....");
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          XMLEncoder encoder = new XMLEncoder(baos);
          encoder.writeObject(sample);
          encoder.close();
          out.write(baos.toByteArray());
     }

     @Override
     public void destroy() {
          // TODO Auto-generated method stub
         
     }

     @Override
     public int getTypeId() {
          return 10;
     }

Hazel cast config file snippet :

<serialization>
          <serializers>
               <serializer type-class="com.db.mmrepo.libs.dataclass.SampleObject">com.db.mmrepo.libs.serialization.SampleSteamSerializer</serializer>
          </serializers>
     </serialization>

I tried configuring both the ways ie throught hazel cast config file and by using serializationconfig in hazel cast server code but getting below exception

Exception snippet :

com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable serializer for class SampleObject
     at com.hazelcast.nio.serialization.SerializationServiceImpl.toData(SerializationServiceImpl.java:154)
     at com.hazelcast.client.proxy.ClientMapProxy.toData(ClientMapProxy.java:483)
     at com.hazelcast.client.proxy.ClientMapProxy.put(ClientMapProxy.java:166)
     at com.hazelcast.client.proxy.ClientMapProxy.put(ClientMapProxy.java:90)
     at com.datamodel.cache.HazelCastCacheManager.put(HazelCastCacheManager.java:49)

Peter Veentjer

unread,
Aug 5, 2013, 7:32:05 AM8/5/13
to haze...@googlegroups.com, Enes Akar
I think it is caused by the client not knowing about how to serialize the object.

So you need to have something like this:

ClientConfig clientConfig = new ClientConfig(); 
 clientConfig.addAddress(ipConfig); 
SerializerConfig sc = new SerializerConfig(); 
sc.setImplementation(new SampleObjectStreamSerializer()).setTypeClass(SampleObject.class); 
clientConfig.getSerializationConfig().addSerializerConfig(sc); 
 client = HazelcastClient.newHazelcastClient(clientConfig); 


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


middha...@gmail.com

unread,
Aug 5, 2013, 9:42:50 AM8/5/13
to haze...@googlegroups.com, Enes Akar
Thanks Peter and Enes.
I tried above suggestion. It worked fine.

middha...@gmail.com

unread,
Aug 5, 2013, 1:32:05 PM8/5/13
to haze...@googlegroups.com, Enes Akar, middha...@gmail.com
Hi Enes/Peter

I am able to serialize the object but have run into other issue.
When running hazel cast predicate query on that object it always returns 0 records

Can u please suggest something in this regard?

Christoph Engelbert

unread,
Aug 5, 2013, 3:01:48 PM8/5/13
to haze...@googlegroups.com, Enes Akar, middha...@gmail.com
What does you Predicate looks like? What kind of Predicate do you use? Custom, PredicateBuilder, SQLPredicate?

Peter Veentjer

unread,
Aug 5, 2013, 4:05:11 PM8/5/13
to haze...@googlegroups.com, Enes Akar, middha...@gmail.com
Without more information, it is impossible for us to determine what is going on.

Can you create a test that reproduces this problem so we can have a look at it?


Peter Veentjer

unread,
Aug 5, 2013, 8:46:39 AM8/5/13
to Sameer Middha, haze...@googlegroups.com, sup...@hazelcast.com
Hi Sameer,

see the answers on the mailinglist since you have posted the question there as well.

Peter.


Sameer Middha

unread,
Aug 5, 2013, 5:30:21 AM8/5/13
to haze...@googlegroups.com, sup...@hazelcast.com

Peter YAN

unread,
Nov 29, 2017, 4:32:21 AM11/29/17
to Hazelcast
Hi Peter, I also get the same issue, https://groups.google.com/forum/#!topic/hazelcast/Z5_alKu0ICA
Could you please forward the solution to me? thanks.
Reply all
Reply to author
Forward
0 new messages