Caused By: java.io.NotSerializableException: com.hazelcast.instance.HazelcastInstanceProxy

1,391 views
Skip to first unread message

keith...@live.com

unread,
Feb 6, 2014, 9:47:09 AM2/6/14
to haze...@googlegroups.com
Hi there,

Trying to get a simple example of hazelcast distributed maps working but getting this exception on the put or putIfAbsent action.  I'm in the process of moving a web app to a weblogic 10.3.5 cluster and came across hazelcast while looking for an open source answer to oracle coherence.  Looks like a great solution, if I can get it to work.  I have the hazelcast-3.1.4.jar and hazelcast-client-3.1.4.jar in my build path.  Using jdk1.6.0_45.

My code is simple like the example:

        Config config = new Config();
        HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
        ConcurrentMap<String, String> map = h.getMap("my-distributed-map");
        map.put("key", "value");
        map.get("key");
        //Concurrent Map methods
        map.putIfAbsent("somekey", "somevalue");

Running the debugger in eclipse, an exception is thrown on the putIfAbsent line:

Caused by: java.io.NotSerializableException: com.hazelcast.instance.HazelcastInstanceProxy
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
	at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.write(DefaultSerializers.java:204)
	at com.hazelcast.nio.serialization.StreamSerializerAdapter.write(StreamSerializerAdapter.java:48)
	at com.hazelcast.nio.serialization.SerializationServiceImpl.toData(SerializationServiceImpl.java:176)
	... 94 more

Hoping somebody has seen this before.  Thanks in advance.

Ali Gürbüz

unread,
Feb 6, 2014, 10:31:44 AM2/6/14
to haze...@googlegroups.com
code works fine for me, are you sure you are running just this piece of code?


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/a2b08965-438d-4ea5-a0a8-f93915d598d5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Christoph Engelbert

unread,
Feb 6, 2014, 10:42:49 AM2/6/14
to haze...@googlegroups.com
Hi Keith,

What's your runtime environment? Anything with classloaders like Servlet Container, OSGi or JEE? I know that problem if Hazelcast classloader wasn't able to find / register the base seriliazers.

Chris

keith...@live.com

unread,
Feb 6, 2014, 1:26:13 PM2/6/14
to haze...@googlegroups.com
I got past this exception, and have a distributed map persisting across my weblogic cluster now.  The code snippet in my original post wasn't accurate.  I was doing this:

map.putIfAbsent("somekey", myClass);

myClass looks like:

   class MyClass implements Serializable {
       
        private static final long serialVersionUID = 1L;
        String user;
        Long timestamp;
       
        public MyClass(String currentUser, long l) {
            this.user = currentUser;
            this.timestamp = l;
        }
    }

I changed it to
map.putIfAbsent("somekey", "somevalue"); using a String for the map value instead of myClass and the problem went away.  I'm puzzled because I've seen hazelcast examples using custom objects in the map, so not sure why it's a problem for me.  It would be handy if I were able to use an object, but could work around it.  I'm just happy I got it working, pretty impressed with hazelcast thus far.  Thanks for the replies.

M. Sancar Koyunlu

unread,
Feb 6, 2014, 5:54:00 PM2/6/14
to haze...@googlegroups.com
Just to be clear, ,n hazelcast you can use custom objects in your map, just like in your example. There is something else going on in your case, which leads to exception. It is mostly a class loader issue, as Chris suspected.

Another case which I can think of which can lead to this issue is that  one of the cluster members having different codebase and does not aware of the class. 



--
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.

kscott_ns

unread,
Feb 7, 2014, 9:01:34 AM2/7/14
to haze...@googlegroups.com
The issue was myClass was originally declared as an inner class.  Once I moved it outside into it's own class, problem went away.  Thanks again for the replies.  I've so far been able to make use of locks, maps and session clustering, Hazelcast works really great.
Reply all
Reply to author
Forward
0 new messages