HazelcastSerializationException: Problem when serializing type 1

8,958 views
Skip to first unread message

Chris Roffler

unread,
May 14, 2012, 8:24:43 AM5/14/12
to Hazelcast
I have a simple class called Person with a bunch of String attributes.
(Serializable)

I can write this class with no problems to the cache, but the query
below throws an exception

EntryObject e = new PredicateBuilder().getEntryObject();
Predicate<Object, T> predicate = e.get("firstName").equal("chris");

return (Collection<T>) map.values(predicate);

This query throws HazelcastSerializationException: Problem when
serializing type 1 exception

Any help would be greatly appreciated

Thanks
Chris

Mehmet Dogan

unread,
May 14, 2012, 9:03:52 AM5/14/12
to haze...@googlegroups.com
There should be also a causing exception in HazelcastSerializationException's stack trace.

@mmdogan




Chris

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.


Chris Roffler

unread,
May 14, 2012, 10:03:26 AM5/14/12
to Hazelcast
Here is the stack trace

May 14, 2012 4:02:06 PM com.hazelcast.impl.LifecycleServiceImpl
INFO: [192.168.5.186]:5702 [dev] Address[192.168.5.186]:5702 is
STARTED
Exception in thread "main"
com.hazelcast.impl.concurrentmap.QueryException: Problem when
serializing type 1
at
com.hazelcast.impl.ConcurrentMapManager.queryMap(ConcurrentMapManager.java:
3940)
at
com.hazelcast.impl.concurrentmap.MapQueryCallable.call(MapQueryCallable.java:
58)
at
com.hazelcast.impl.concurrentmap.MapQueryCallable.call(MapQueryCallable.java:
34)
at com.hazelcast.impl.ExecutorManager
$RequestExecutor.run(ExecutorManager.java:224)
at com.hazelcast.impl.executor.ParallelExecutorService
$ParallelExecutorImpl
$ExecutionSegment.run(ParallelExecutorService.java:212)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.hazelcast.nio.HazelcastSerializationException: Problem
when serializing type 1
at
com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:
121)
at
com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:
148)
at com.hazelcast.nio.Serializer.readObject(Serializer.java:71)
at com.hazelcast.impl.ThreadContext.toObject(ThreadContext.java:114)
at com.hazelcast.nio.IOUtil.toObject(IOUtil.java:157)
at com.hazelcast.impl.DefaultRecord.getValue(DefaultRecord.java:63)
at com.hazelcast.query.Predicates
$GetExpressionImpl.doGetValue(Predicates.java:892)
at com.hazelcast.query.Predicates
$GetExpressionImpl.getValue(Predicates.java:886)
at com.hazelcast.query.Predicates
$EqualPredicate.apply(Predicates.java:449)
at com.hazelcast.query.PredicateBuilder.apply(PredicateBuilder.java:
31)
at
com.hazelcast.impl.ConcurrentMapManager.createResultPairs(ConcurrentMapManager.java:
3954)
at
com.hazelcast.impl.ConcurrentMapManager.queryMap(ConcurrentMapManager.java:
3938)
... 7 more
Caused by: java.lang.ClassNotFoundException: mozgif.space.test.Person
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
com.hazelcast.nio.AbstractSerializer.loadClass(AbstractSerializer.java:
85)
at
com.hazelcast.nio.AbstractSerializer.loadClass(AbstractSerializer.java:
60)
at com.hazelcast.nio.AbstractSerializer
$1.resolveClass(AbstractSerializer.java:95)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readUnshared(Unknown Source)
at com.hazelcast.nio.DefaultSerializer
$ObjectSerializer.readNormal(DefaultSerializer.java:410)
at com.hazelcast.nio.DefaultSerializer
$ObjectSerializer.read(DefaultSerializer.java:380)
at com.hazelcast.nio.DefaultSerializer.read(DefaultSerializer.java:
138)
at
com.hazelcast.nio.CustomSerializerAdapter.read(CustomSerializerAdapter.java:
32)
at
com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:
119)
... 18 more

Talip Ozturk

unread,
May 14, 2012, 11:35:09 AM5/14/12
to haze...@googlegroups.com
> Caused by: java.lang.ClassNotFoundException: mozgif.space.test.Person

Make sure you have mozgif.space.test.Person class in the classpath of
each Hazelcast node.

-talip

sselvia

unread,
Mar 19, 2013, 8:12:42 AM3/19/13
to haze...@googlegroups.com, skad...@gmail.com
I had another thread with the same issue, we double checked our classpath and our entity class is in the classpath of every node.  We can access the entities from any node, we just cannot issue predicates to filter the map's.
 
When issuing the following predicate on an Hazelcast map initialized with <Long, ClientProducts> I'm getting the serializing type 1 error.  The entity bean is below the stack trace, I can traverse the map manually but I cannot predicate search the map.  The entity bean has an empty constructor, so I don't know what else could be the problem.
 
EntitryObject eo = new PredicateBuilder().getEntryObject();
Predicate predicate = eo.get("uniqueId").equal(new Long(2));
Set<ClientProducts> products = (Set<ClientProducts>)hcClientProductsMap.values(predicate);
Caused by: java.lang.RuntimeException: Problem when serializing type 1
 at com.hazelcast.impl.ClientServiceException.readData(ClientServiceException.java:63)
 at com.hazelcast.nio.Serializer$DataSerializer.read(Serializer.java:104)
 at com.hazelcast.nio.Serializer$DataSerializer.read(Serializer.java:79)
 at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:121)
 at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:156)
 at com.hazelcast.client.ClientThreadContext.toObject(ClientThreadContext.java:72)
 at com.hazelcast.client.IOUtil.toObject(IOUtil.java:34)
 at com.hazelcast.client.ProxyHelper.getValue(ProxyHelper.java:186)
 at com.hazelcast.client.ProxyHelper.doOp(ProxyHelper.java:146)
 at com.hazelcast.client.ProxyHelper.doOp(ProxyHelper.java:140)
 at com.hazelcast.client.ProxyHelper.entries(ProxyHelper.java:211)
 at com.hazelcast.client.MapClientProxy.entrySet(MapClientProxy.java:120)
 at com.hazelcast.client.MapClientProxy.values(MapClientProxy.java:202)
 at com.datamentors.dqs.ejb.DQSApplicationStartupEJB.initClientInformationHazelcastMap(DQSApplicationStartupEJB.java:668)
 
Entity Bean:
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.datamentors.dqs.ejb.entities;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
 *
 * @author bmagliano
 */
@Entity
@Table(name = "CLIENT_PRODUCTS")
@XmlRootElement
@NamedQueries({
 @NamedQuery(name = "ClientProducts.findAll", query = "SELECT c FROM ClientProducts c"),
 @NamedQuery(name = "ClientProducts.findByUniqueId", query = "SELECT c FROM ClientProducts c WHERE c.uniqueId = :uniqueId"),
 @NamedQuery(name = "ClientProducts.findByClientUniqueId", query = "SELECT c FROM ClientProducts c WHERE c.clientUniqueId = :clientUniqueId"),
 @NamedQuery(name = "ClientProducts.findByProductUniqueId", query = "SELECT c FROM ClientProducts c WHERE c.productUniqueId = :productUniqueId"),
 @NamedQuery(name = "ClientProducts.findBySessionId", query = "SELECT c FROM ClientProducts c WHERE c.sessionId = :sessionId"),
 @NamedQuery(name = "ClientProducts.findByHostName", query = "SELECT c FROM ClientProducts c WHERE c.hostName = :hostName"),
 @NamedQuery(name = "ClientProducts.findByProgram", query = "SELECT c FROM ClientProducts c WHERE c.program = :program"),
 @NamedQuery(name = "ClientProducts.findByLastUpdateUid", query = "SELECT c FROM ClientProducts c WHERE c.lastUpdateUid = :lastUpdateUid"),
 @NamedQuery(name = "ClientProducts.findByLastUpdateTs", query = "SELECT c FROM ClientProducts c WHERE c.lastUpdateTs = :lastUpdateTs")})
public class ClientProducts implements Serializable {
 private static final long serialVersionUID = 1L;
 @Id
 @Basic(optional = false)
 @NotNull
 @Column(name = "UNIQUE_ID")
 private Long uniqueId;
 @Basic(optional = false)
 @NotNull
 @Column(name = "CLIENT_UNIQUE_ID")
 private long clientUniqueId;
 @Basic(optional = false)
 @NotNull
 @Column(name = "PRODUCT_UNIQUE_ID")
 private long productUniqueId;
 @Basic(optional = false)
 @NotNull
 @Column(name = "SESSION_ID")
 private int sessionId;
 @Basic(optional = false)
 @NotNull
 @Size(min = 1, max = 30)
 @Column(name = "HOST_NAME")
 private String hostName;
 @Basic(optional = false)
 @NotNull
 @Size(min = 1, max = 64)
 @Column(name = "PROGRAM")
 private String program;
 @Basic(optional = false)
 @NotNull
 @Size(min = 1, max = 100)
 @Column(name = "LAST_UPDATE_UID")
 private String lastUpdateUid;
 @Basic(optional = false)
 @NotNull
 @Column(name = "LAST_UPDATE_TS")
 @Temporal(TemporalType.TIMESTAMP)
 private Date lastUpdateTs;
 public ClientProducts() {
 }
 public ClientProducts(Long uniqueId) {
  this.uniqueId = uniqueId;
 }
 public ClientProducts(Long uniqueId, long clientUniqueId, long productUniqueId, int sessionId, String hostName, String program, String lastUpdateUid, Date lastUpdateTs) {
  this.uniqueId = uniqueId;
  this.clientUniqueId = clientUniqueId;
  this.productUniqueId = productUniqueId;
  this.sessionId = sessionId;
  this.hostName = hostName;
  this.program = program;
  this.lastUpdateUid = lastUpdateUid;
  this.lastUpdateTs = lastUpdateTs;
 }
 public Long getUniqueId() {
  return uniqueId;
 }
 public void setUniqueId(Long uniqueId) {
  this.uniqueId = uniqueId;
 }
 public long getClientUniqueId() {
  return clientUniqueId;
 }
 public void setClientUniqueId(long clientUniqueId) {
  this.clientUniqueId = clientUniqueId;
 }
 public long getProductUniqueId() {
  return productUniqueId;
 }
 public void setProductUniqueId(long productUniqueId) {
  this.productUniqueId = productUniqueId;
 }
 public int getSessionId() {
  return sessionId;
 }
 public void setSessionId(int sessionId) {
  this.sessionId = sessionId;
 }
 public String getHostName() {
  return hostName;
 }
 public void setHostName(String hostName) {
  this.hostName = hostName;
 }
 public String getProgram() {
  return program;
 }
 public void setProgram(String program) {
  this.program = program;
 }
 public String getLastUpdateUid() {
  return lastUpdateUid;
 }
 public void setLastUpdateUid(String lastUpdateUid) {
  this.lastUpdateUid = lastUpdateUid;
 }
 public Date getLastUpdateTs() {
  return lastUpdateTs;
 }
 public void setLastUpdateTs(Date lastUpdateTs) {
  this.lastUpdateTs = lastUpdateTs;
 }
 @Override
 public int hashCode() {
  int hash = 0;
  hash += (uniqueId != null ? uniqueId.hashCode() : 0);
  return hash;
 }
 @Override
 public boolean equals(Object object) {
  // TODO: Warning - this method won't work in the case the id fields are not set
  if (!(object instanceof ClientProducts)) {
   return false;
  }
  ClientProducts other = (ClientProducts) object;
  if ((this.uniqueId == null && other.uniqueId != null) || (this.uniqueId != null && !this.uniqueId.equals(other.uniqueId))) {
   return false;
  }
  return true;
 }
 @Override
 public String toString() {
  return "com.datamentors.dqs.ejb.entities.ClientProducts[ uniqueId=" + uniqueId + " ]";
 }
 

On Tuesday, March 19, 2013 6:47:21 AM UTC-4, skad...@gmail.com wrote:
Hello,
I've experienced the same issue, but maybe i've got a different setup:

I use hazelcast both to achieve Jetty session clustering (map: sessionMap) and to store two different maps: users and emailTokens.
I separately launch an hazelcast server, then I launch jetty and I connect to hazelcast as a client both from web.xml (for Session Clustering)

   <init-param>
        <param-name>use-client</param-name>
        <param-value>true</param-value>
    </init-param>
     <init-param>
        <param-name>client-config-location</param-name>
        <param-value>/WEB-INF/hazelcast-client.properties</param-value>
    </init-param>

hazelcast.client.addresses= 127.0.0.1
hazelcast.client.connection.attempts.limit = 3
hazelcast.client.connection.timeout    = 30000
hazelcast.client.group.name    = dev
hazelcast.client.group.pass    = dev-pass
hazelcast.client.reconnection.attempts.limit = 5
hazelcast.client.reconnection.timeout = 5000
hazelcast.client.shuffle.addresses = false
hazelcast.client.update.automatic = true

and from java logic (to manage users and emailTokens maps):

public HazelcastInstance getConnection() {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.addAddress("127.0.0.1:5701");
        clientConfig.getGroupConfig().setName("dev").setPassword("dev-pass");
        HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
        return client;
    }

When a user logs in, an HazelcastUser object is put in the Hazelcast map <Integer, HazelcastUser> users (it works); after login, when a user connects to the system its status is set Online.

public HazelcastUser setIsOnline(Integer idUser, boolean online){
        HazelcastInstance hz = dataSource.getConnection();
        Map<Integer, HazelcastUser> users = hz.getMap("users");
        HazelcastUser currentUser = users.get(idUser);
        currentUser.setOnline(online);
        users.put(idUser, currentUser);
        return currentUser;
    }

but when this method is called i get:


com.hazelcast.nio.HazelcastSerializationException: Problem when serializing type 1
    at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:128)
    at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:156)
    at com.hazelcast.client.ClientThreadContext.toObject(ClientThreadContext.java:72)
    at com.hazelcast.client.IOUtil.toObject(IOUtil.java:34)
    at com.hazelcast.client.ProxyHelper.getValue(ProxyHelper.java:186)
    at com.hazelcast.client.ProxyHelper.doOp(ProxyHelper.java:146)
    at com.hazelcast.client.ProxyHelper.doOp(ProxyHelper.java:140)
    at com.hazelcast.client.MapClientProxy.get0(MapClientProxy.java:267)
    at com.hazelcast.client.MapClientProxy.get(MapClientProxy.java:262)
    at persistence.HazelcastController.setIsOnline(HazelcastController.java:37) ------------------>>>>>  WHICH IS:  HazelcastUser currentUser = users.get(idUser);
    at control.chat.HazelcastChatController.connectChat(HazelcastChatController.java:12)
    at action.ConnectChatAction.doAction(ConnectChatAction.java:30)
    at action.controller.ActionController.executeAction(ActionController.java:47)
    at handler.CChatHandler.serviceDoPost(CChatHandler.java:82)
    at handler.CChatHandler.onRequest(CChatHandler.java:40)
    at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:254)
    at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:164)
    at org.atmosphere.container.Jetty9AsyncSupportWithWebSocket.service(Jetty9AsyncSupportWithWebSocket.java:127)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1335)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:259)
    at org.atmosphere.websocket.DefaultWebSocketProcessor$2.run(DefaultWebSocketProcessor.java:209)
    at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:204)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:180)
    at org.atmosphere.container.Jetty9WebSocketHandler.onWebSocketText(Jetty9WebSocketHandler.java:74)
    at org.eclipse.jetty.websocket.core.io.event.ListenerEventDriver.onTextMessage(ListenerEventDriver.java:117)
    at org.eclipse.jetty.websocket.core.io.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
    at org.eclipse.jetty.websocket.core.io.event.ListenerEventDriver.onTextFrame(ListenerEventDriver.java:109)
    at org.eclipse.jetty.websocket.core.io.event.EventDriver.incoming(EventDriver.java:147)
    at org.eclipse.jetty.websocket.core.io.WebSocketSession.incoming(WebSocketSession.java:124)
    at org.eclipse.jetty.websocket.core.protocol.Parser.notifyFrame(Parser.java:189)
    at org.eclipse.jetty.websocket.core.protocol.Parser.parse(Parser.java:224)
    at org.eclipse.jetty.websocket.core.io.AbstractWebSocketConnection.read(AbstractWebSocketConnection.java:377)
    at org.eclipse.jetty.websocket.core.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:287)
    at org.eclipse.jetty.io.AbstractConnection$1.onCompleted(AbstractConnection.java:80)
    at org.eclipse.jetty.io.AbstractConnection$1.onCompleted(AbstractConnection.java:63)
    at org.eclipse.jetty.util.ExecutorCallback$1.run(ExecutorCallback.java:32)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:595)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:526)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: model.HazelcastUser
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at com.hazelcast.nio.AbstractSerializer.loadClass(AbstractSerializer.java:81)
    at com.hazelcast.nio.AbstractSerializer.loadClass(AbstractSerializer.java:56)
    at com.hazelcast.nio.AbstractSerializer$1.resolveClass(AbstractSerializer.java:91)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.readUnshared(ObjectInputStream.java:459)
    at com.hazelcast.nio.DefaultSerializer$ObjectSerializer.readNormal(DefaultSerializer.java:410)
    at com.hazelcast.nio.DefaultSerializer$ObjectSerializer.read(DefaultSerializer.java:380)

    at com.hazelcast.nio.DefaultSerializer.read(DefaultSerializer.java:138)
    at com.hazelcast.nio.CustomSerializerAdapter.read(CustomSerializerAdapter.java:32)
    at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:121)

What should I do?

Thank you in advance for your reply!
Andrea

Jason Clawson

unread,
Mar 30, 2013, 5:11:07 PM3/30/13
to skad...@gmail.com, haze...@googlegroups.com, skad...@gmail.com
That Map implementation that gets assigned is likely not serializable.  Put a breakpoint and check the type.

Sent from my iPhone

On Mar 30, 2013, at 2:23 PM, skad...@gmail.com wrote:

Hi, sorry I've been out for work last week.

Anyway I use java default serialization and not DataSerializable.
I found out that I get the error only for the requests handled by the Atmosphere framework: the same code if trigged from a regular servlet doesn't result in any problem.

These are the objects I'm trying to put on the map:

public class HazelcastUser implements Serializable {

    private boolean online;
    private String nickname;
    private Map<Integer, Friend> friends;
    private Map<Integer, Integer> id2w4m;

}

public class Friend implements Serializable {

    private Integer idUser;
    private String status;

}

Thank you,
Andrea

Il giorno martedì 19 marzo 2013 17:49:41 UTC+1, jason....@gmail.com ha scritto:
I don't think I am using the same hazelcast version as you.  My DataSerializer.read operated on DataSerializable's and they class you posted doesn't implement that.  So... I am a little confused.  Anyhow... typically when you get that exception it means you need a default constructor.


Andrea Scaduto

unread,
Apr 1, 2013, 7:13:40 AM4/1/13
to haze...@googlegroups.com, skad...@gmail.com, jason....@gmail.com
If I add the classes of model: HazelcastUser and Friend (needed to serialize/deserialize) in jetty/lib/ext the type of error changes to:

java.lang.ClassCastException: model.HazelcastUser cannot be cast to model.HazelcastUser
    at persistence.HazelcastController.setIsOnline(HazelcastController.java:41) --> WHICH IS     HazelcastUser currentUser = users.get(idUser);

    at control.chat.HazelcastChatController.connectChat(HazelcastChatController.java:12)
    at action.ConnectChatAction.doAction(ConnectChatAction.java:30)
    at action.controller.ActionController.executeAction(ActionController.java:53)
Strange is if I print the keys in the map the user is there:

IMap<Integer, HazelcastUser> users = hz.getMap("users");
for (Integer i : users.keySet())
    System.out.println("### USER : "+i);

Andrea

Jason Clawson

unread,
Apr 1, 2013, 10:07:58 AM4/1/13
to Andrea Scaduto, haze...@googlegroups.com, skad...@gmail.com
This error has nothing to do with hazelcast.  You probably have a duplicate jar include for that class, or otherwise, that class is somehow different in an incompatible way on the machine you are deserializing on.  Hazelcast's DataSerializable would likely be more forgiving in this case.

Also, make sure you set serialVersionUid and update it if you make incompatible changes.  http://docs.oracle.com/javase/6/docs/api/java/io/Serializable.html

I recommend using DataSerializable because it gives you fine grained control of how your objects are serialized / deserialized and there is a lot less java magic in between.

--
Jason




Sent from my iPhone

Andrea Scaduto

unread,
Apr 1, 2013, 11:09:07 AM4/1/13
to haze...@googlegroups.com, skad...@gmail.com, jason....@gmail.com
Hello, I've followed your suggestions:

public class HazelcastUser implements DataSerializable {
    private static final long serialVersionUID = -5782246354613752009L;

    private boolean online;
    private String nickname;
    private Map<Integer, Friend> friends = new HashMap<Integer, Friend>();
    private Map<Integer, Integer> id2w4m = new HashMap<Integer, Integer>();

    public HazelcastUser(){}

// getter and setters

    @Override
    public void readData(DataInput in) throws IOException {
        online = in.readBoolean();
        nickname = in.readUTF();

         for (int i = in.readInt(); i > 0; i--) {
                Integer usrId = in.readInt();
                Integer w4m = in.readInt();
                id2w4m.put(usrId, w4m);
            }
         for (int j = in.readInt(); j > 0; j--) {
                Integer idUser = in.readInt();
                Friend friend = new Friend();
                friend.readData(in);
                friends.put(idUser, (Friend) friend);
            }
    }

    @Override
    public void writeData(DataOutput out) throws IOException {
        out.writeBoolean(online);
        out.writeUTF(nickname);
        out.writeInt(id2w4m.size());
        for (Map.Entry<Integer, Integer> entry : id2w4m.entrySet()) {
            out.writeInt(entry.getKey());
            out.writeInt(entry.getValue());
        }
        out.writeInt(friends.size());
        for (Map.Entry<Integer, Friend> entry : friends.entrySet()) {
            out.writeInt(entry.getKey());
            entry.getValue().writeData(out);
        }
    }
}

public class Friend implements DataSerializable {

    private static final long serialVersionUID = 2535332120082360935L;

    private Integer idUser;
    private String status;

    public Friend(){}

@Override
    public void readData(DataInput in) throws IOException {
        idUser = in.readInt();
        status = in.readUTF();
    }

    @Override
    public void writeData(DataOutput out) throws IOException {
        out.writeInt(idUser);
        out.writeUTF(status);
    }
}

Is this the proper way to do it?

Now I get:

com.hazelcast.nio.HazelcastSerializationException: Problem when serializing type 0

    at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:128)
    at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:156)
    at com.hazelcast.client.ClientThreadContext.toObject(ClientThreadContext.java:72)
    at com.hazelcast.client.IOUtil.toObject(IOUtil.java:34)
    at com.hazelcast.client.ProxyHelper.getValue(ProxyHelper.java:186)
    at com.hazelcast.client.ProxyHelper.doOp(ProxyHelper.java:146)
    at com.hazelcast.client.ProxyHelper.doOp(ProxyHelper.java:140)
    at com.hazelcast.client.MapClientProxy.get0(MapClientProxy.java:267)
    at com.hazelcast.client.MapClientProxy.get(MapClientProxy.java:262)
    at persistence.HazelcastController.setIsOnline(HazelcastController.java:44)
Caused by: java.io.IOException: Problem reading DataSerializable class : model.HazelcastUser, exception: java.lang.ClassNotFoundException: model.HazelcastUser
    at com.hazelcast.nio.Serializer$DataSerializer.read(Serializer.java:107)

    at com.hazelcast.nio.Serializer$DataSerializer.read(Serializer.java:79)
    at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:121)
    ... 39 more

I connect from the webapp as a client, should I have to copy model jars in hazelcast path on the standalone node?

Thank you very much,
Andrea

Jason Clawson

unread,
Apr 1, 2013, 8:54:27 PM4/1/13
to Andrea Scaduto, haze...@googlegroups.com
Perhaps the class really is not found?  Are you certain your jars are in the class path?  What happens if you do a Class.forName("model.HazelcastUser")?

Andrea Scaduto

unread,
Apr 11, 2013, 3:40:47 PM4/11/13
to haze...@googlegroups.com, Andrea Scaduto, jason....@gmail.com
I found out that the problem occurs only with requests handled by Atmosphere that can't access the right thread's context for classloading.

The first time this class is called at System startup it is not by Atmosphere so it works, I solved copying the "working" classloader :

public class HazelcastDataSource {

    private static HazelcastInstance hazelcastInstance;
    private static ClassLoader loader = Thread.currentThread().getContextClassLoader();

    static {       
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.addAddress("localhost");
        clientConfig.setReConnectionTimeOut(10);
        clientConfig.setConnectionTimeout(300);

        clientConfig.getGroupConfig().setName("dev").setPassword("dev-pass");
        hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);   
    }

    public HazelcastInstance getInstance(){
        Thread.currentThread().setContextClassLoader(loader);
        return hazelcastInstance;
    }
}

Thank you for your help!
Andrea
Reply all
Reply to author
Forward
0 new messages