Sending and receiving serialized objects

View: New views
2 Messages — Rating Filter:   Alert me  

Sending and receiving serialized objects

by Kai Timmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I use these functions to send a serialized object to all nodes on a channel

to send:
pivate void stateUpdate(cNodeInfo newNodeInfo) throws Exception{
  byte[] buf = Util.objectToByteBuffer(newNodeInfo);
  control_channel.send(null, null, buf);
}

and on the receiver side:

public void receive(Message msg){
  Object message_content;
  try {
    message_content = Util.objectFromByteBuffer(msg.getBuffer());
    if (message_content instanceof cNodeInfo){
       //Stuff to do with the NodeInfo
    }
}

The problem is that message_content instanceof cNodeInfo never
evaluates to true. I have no idea why. This is maybe more a java
related question and has nothing to do with jgourps, but I'm not sure.

Greets,
--
Kai Timmer | http://kaitimmer.de
Email : email@...
Jabber (Google Talk): kai@...
ICQ: 67765488

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
javagroups-users mailing list
javagroups-users@...
https://lists.sourceforge.net/lists/listinfo/javagroups-users

Re: Sending and receiving serialized objects

by Bela Ban :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Do this:

private void stateUpdate(cNodeInfo newNodeInfo) throws Exception{
   control_channel.send(null, null, newNodeInfo);
}

and on the receiver side:

public void receive(Message msg) {
    try {
       Object message_content = msg.getObject();
       if (message_content instanceof cNodeInfo){
       //Stuff to do with the NodeInfo
       }
    }
}


Kai Timmer wrote:

> Hello,
> I use these functions to send a serialized object to all nodes on a
> channel
>
> to send:
> pivate void stateUpdate(cNodeInfo newNodeInfo) throws Exception{
> byte[] buf = Util.objectToByteBuffer(newNodeInfo);
> control_channel.send(null, null, buf);
> }
>
> and on the receiver side:
>
> public void receive(Message msg){
> Object message_content;
> try {
> message_content = Util.objectFromByteBuffer(msg.getBuffer());
> if (message_content instanceof cNodeInfo){
> //Stuff to do with the NodeInfo
> }
> }
>
> The problem is that message_content instanceof cNodeInfo never
> evaluates to true. I have no idea why. This is maybe more a java
> related question and has nothing to do with jgourps, but I'm not sure.
>
> Greets,

--
Bela Ban
Lead JGroups / Clustering Team
JBoss


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
javagroups-users mailing list
javagroups-users@...
https://lists.sourceforge.net/lists/listinfo/javagroups-users