org.iids.aos.messagecenter
Class Envelope

java.lang.Object
  extended by org.iids.aos.messagecenter.Envelope
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ViaEnvelope, ViaReplyEnvelope

public class Envelope
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

An envelope wrapping AgentScape agent messages.

Each envelope contains data as well as address information (source and targets AgentHandle).

Author:
hidde@cs.vu.nl
See Also:
Serialized Form

Field Summary
protected  java.io.Serializable data
           
protected  byte[] dataBytes
           
protected  AgentHandle fromHandle
           
protected  java.util.List<AgentHandle> toList
           
 
Constructor Summary
Envelope()
           
Envelope(AgentHandle to, AgentHandle from, java.io.Serializable data)
          Create a new envelope with contact information and data.
Envelope(java.util.Collection<AgentHandle> to, AgentHandle from, java.io.Serializable data)
           
Envelope(Envelope e)
           
 
Method Summary
 void addTarget(AgentHandle... handles)
           
 void addTarget(java.util.Collection<AgentHandle> to)
           
protected  Envelope clone()
           
 Envelope copy()
           
 java.io.Serializable getData()
          Obtain data wrapped in envelope.
 java.io.Serializable getData(java.lang.ClassLoader cl)
          Read data using an explicit ClassLoader.
 byte[] getDataAsSerializedBytes()
          Get data in serialized form.
 AgentHandle getFromHandle()
          Get source handle of this message.
 java.util.Collection<AgentHandle> getMulticastTargets()
           
 int getTargetCount()
           
 AgentHandle getToHandle()
          Deprecated. 
 java.util.List<AgentHandle> getToHandles()
           
 void removeTarget(AgentHandle targetHandle)
           
 void setData(java.io.Serializable data)
           
 void setFromHandle(AgentHandle fromHandle)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dataBytes

protected byte[] dataBytes

data

protected transient java.io.Serializable data

toList

protected java.util.List<AgentHandle> toList

fromHandle

protected AgentHandle fromHandle
Constructor Detail

Envelope

public Envelope()

Envelope

public Envelope(Envelope e)

Envelope

public Envelope(AgentHandle to,
                AgentHandle from,
                java.io.Serializable data)
Create a new envelope with contact information and data.

Parameters:
to - The AgentHandle of the target for this message.
from - The AgentHandle of the source of this message.
data - The (raw) data to be carried in this message. TODO change parameter type to Object.

Envelope

public Envelope(java.util.Collection<AgentHandle> to,
                AgentHandle from,
                java.io.Serializable data)
Method Detail

clone

protected final Envelope clone()
Overrides:
clone in class java.lang.Object

copy

public final Envelope copy()

getMulticastTargets

public java.util.Collection<AgentHandle> getMulticastTargets()

removeTarget

public void removeTarget(AgentHandle targetHandle)

getTargetCount

public int getTargetCount()

addTarget

public void addTarget(AgentHandle... handles)

addTarget

public void addTarget(java.util.Collection<AgentHandle> to)

getData

public java.io.Serializable getData()
Obtain data wrapped in envelope. This data will be read using the context ClassLoader of the calling thread. If this is incorrect then user to getData(ClassLoader) instead.

Returns:
The data object inside the envelope

getData

public java.io.Serializable getData(java.lang.ClassLoader cl)
Read data using an explicit ClassLoader.

Parameters:
cl - The ClassLoader to use for the data. If this is null, it defaults to the envelope class loader.
Returns:
The data object inside the envelope.

getDataAsSerializedBytes

public byte[] getDataAsSerializedBytes()
Get data in serialized form. Note: you probably want to use getData() to retrieve your data from the envelope.

Returns:
serialized data in byte form.

setData

public void setData(java.io.Serializable data)

getFromHandle

public AgentHandle getFromHandle()
Get source handle of this message.

Returns:
The source handle with which this message was sent.

setFromHandle

public void setFromHandle(AgentHandle fromHandle)

getToHandle

@Deprecated
public AgentHandle getToHandle()
Deprecated. 

Get target handle of this message. Only for backwards compatibility, works only if the envelope has only one target.

Note: deprecated, use getToHandles() instead

Returns:
the target AgentHandle of this envelope

getToHandles

public java.util.List<AgentHandle> getToHandles()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003, 2004 IIDS Group. All Rights Reserved.