ObjectMessage (Java EE 5)

Java EE API


javax.jms Interface ObjectMessage

All Superinterfaces:
Message

public interface ObjectMessage
extends Message

Implements: Message

ObjectMessage 对象用于发送包含 Java 编程语言中可序列化对象(“Java 对象”)的消息。它继承自 Message 接口并添加了包含一个对某对象引用的正文。只能使用 Serializable Java 对象。

如果必须发送 Java 对象的集合,则可以使用自 JDK 1.2 起提供的 Collection 类之一。

当客户端接收 ObjectMessage 时,它是只读模式。如果客户端尝试在此时写入消息,则抛出 MessageNotWriteableException。如果调用了 clearBody,现在便可以读取和写入消息。

英文文档:

An ObjectMessage object is used to send a message that contains a serializable object in the Java programming language ("Java object"). It inherits from the Message interface and adds a body containing a single reference to an object. Only Serializable Java objects can be used.

If a collection of Java objects must be sent, one of the Collection classes provided since JDK 1.2 can be used.

When a client receives an ObjectMessage, it is in read-only mode. If a client attempts to write to the message at this point, a MessageNotWriteableException is thrown. If clearBody is called, the message can now be both read from and written to.

Version:
1.0 - 6 August 1998
Author:
Mark Hapner, Rich Burridge
See Also:
Session.createObjectMessage(), Session.createObjectMessage(Serializable), BytesMessage, MapMessage, Message, StreamMessage, TextMessage

Field Summary
 
Fields inherited from interface javax.jms.Message
 
Method Summary
 Serializable
 void
 
Methods inherited from interface javax.jms.Message
 

Method Detail

public void setObject(java.io.Serializable object) throws JMSException
设置包含此消息数据的可序列化对象。要特别注意的是,调用 setObject() 时,ObjectMessage 包含的是对象的快照;后续对对象的修改不会影响 ObjectMessage 正文。
object 消息的数据
ThrowsJMSException: 如果 JMS 提供者由于某个内部错误无法设置对象。
ThrowsMessageFormatException: 如果对象序列化失败。
ThrowsMessageNotWriteableException: 如果消息是只读模式。
英文文档:

setObject

void setObject(Serializable object)
               throws JMSException
Sets the serializable object containing this message's data. It is important to note that an ObjectMessage contains a snapshot of the object at the time setObject() is called; subsequent modifications of the object will have no effect on the ObjectMessage body.

Parameters:
object - the message's data
Throws:
JMSException - if the JMS provider fails to set the object due to some internal error.
MessageFormatException - if object serialization fails.
MessageNotWriteableException - if the message is in read-only mode.

public java.io.Serializable getObject() throws JMSException
获取包含此消息数据的可序列化对象。默认值为 null。
return 包含此消息数据的可序列化对象。
ThrowsJMSException: 如果 JMS 提供者由于某个内部错误无法获取对象。
ThrowsMessageFormatException: 如果对象反序列化失败。
英文文档:

getObject

Serializable getObject()
                       throws JMSException
Gets the serializable object containing this message's data. The default value is null.

Returns:
the serializable object containing this message's data
Throws:
JMSException - if the JMS provider fails to get the object due to some internal error.
MessageFormatException - if object deserialization fails.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!