Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Serializing & Deserializing objects through ObjectMessage

886634Sep 13 2011 — edited Sep 14 2011
Hi,

I'm having trouble sending objects/instances of a class (Data) through the message queue. I also made Data to be serializable.
public class Data implements Serializable {
...
}
The following are snippets of code from the Message producer side:
objectMessage = mySess.createObjectMessage();
MessageProducer myMsgProducer = mySess.createProducer(myQueue);
Data e = new Data();
objectMessage.setObject(e);
myMsgProducer.send(objectMessage);
And the following are snippets of code from the message consumer:
public void onMessage(Message message) {
...
             if(message instanceof ObjectMessage ){
	    try{
	    	ObjectMessage objMsg = (ObjectMessage) message;
	    	Data myData = (Data)objMsg.getObject();
	    }
	    catch(JMSException e){
	    	System.out.println("Exception occured: " + e.toString());
	    }
}
The result of attempting to cast the objMsg to a Data is an exception thrown.

i did noticed however, that when I was debugging the message consumer, that the byteArrayInputStream values for both message and objMsg are null meaning that the data is not being sent or received. Any help would be greatly appreciated, thanks!

Edited by: 883631 on Sep 13, 2011 4:09 PM

Edited by: EJP on 14/09/2011 09:22: added {noformat}
{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

Comments

SubOptimal

The link to Oracle Javamagazine is broken. It point to `oracle.com/java` instead of `oracle.com/javamagazine`.

user619767

No link to source on GitHub or Kenai?

Pradeep Y

Hi Annie,

I have developed source code based on this document using usb4java and it is working fine as a standalone class.

I integrated this code into another application as a signed applet jar along with other supporting files. Here weight from weighing scale is also reading as expected.

My problem is if weight on weighing scale is changed, to update this change it is taking 20-30 sec. So, a user has to wait for some time to get updated weight.

I verified code and found below code is reading same weight in this period.

     received = pipe.syncSubmit(data);

Here data size is 8 bytes and receiving 6 bytes.

When I looped this statement alone for 400 time it is retrieving update weight in 10 sec and also there are performance issues like browser is hanged for almost 10-15 sec and applet is also hanging.

Please suggest me on resolving this issue.

Thanks,

Y Pradeep

Fantazma

Thank You Annie.

User_I95HU

DSCN0010.jpg

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 12 2011
Added on Sep 13 2011
4 comments
1,722 views