MarshalledObjectpublic final class MarshalledObject extends Object implements SerializableA MarshalledObject contains a byte stream with the serialized
representation of an object given to its constructor. The get
method returns a new copy of the original object, as deserialized from
the contained byte stream. The contained object is serialized and
deserialized with the same serialization semantics used for marshaling
and unmarshaling parameters and return values of RMI calls: When the
serialized form is created:
- classes are annotated with a codebase URL from where the class
can be loaded (if available), and
- any remote object in the
MarshalledObject is
represented by a serialized instance of its stub.
When copy of the object is retrieved (via the get method),
if the class is not available locally, it will be loaded from the
appropriate location (specified the URL annotated with the class descriptor
when the class was serialized.
MarshalledObject facilitates passing objects in RMI calls
that are not automatically deserialized immediately by the remote peer.
|
Fields Summary |
---|
private byte[] | objBytes | private byte[] | locBytes | private int | hash | private static final long | serialVersionUIDIndicate compatibility with 1.2 version of class. |
Constructors Summary |
---|
public MarshalledObject(T obj)Creates a new MarshalledObject that contains the
serialized representation of the current state of the supplied object.
The object is serialized with the semantics used for marshaling
parameters for RMI calls.
if (obj == null) {
hash = 13;
return;
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ByteArrayOutputStream lout = new ByteArrayOutputStream();
MarshalledObjectOutputStream out =
new MarshalledObjectOutputStream(bout, lout);
out.writeObject(obj);
out.flush();
objBytes = bout.toByteArray();
// locBytes is null if no annotations
locBytes = (out.hadAnnotations() ? lout.toByteArray() : null);
/*
* Calculate hash from the marshalled representation of object
* so the hashcode will be comparable when sent between VMs.
*/
int h = 0;
for (int i = 0; i < objBytes.length; i++) {
h = 31 * h + objBytes[i];
}
hash = h;
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Compares this MarshalledObject to another object.
Returns true if and only if the argument refers to a
MarshalledObject that contains exactly the same
serialized representation of an object as this one does. The
comparison ignores any class codebase annotation, meaning that
two objects are equivalent if they have the same serialized
representation except for the codebase of each class
in the serialized representation.
if (obj == this)
return true;
if (obj != null && obj instanceof MarshalledObject) {
MarshalledObject other = (MarshalledObject) obj;
// if either is a ref to null, both must be
if (objBytes == null || other.objBytes == null)
return objBytes == other.objBytes;
// quick, easy test
if (objBytes.length != other.objBytes.length)
return false;
//!! There is talk about adding an array comparision method
//!! at 1.2 -- if so, this should be rewritten. -arnold
for (int i = 0; i < objBytes.length; ++i) {
if (objBytes[i] != other.objBytes[i])
return false;
}
return true;
} else {
return false;
}
| public T | get()Returns a new copy of the contained marshalledobject. The internal
representation is deserialized with the semantics used for
unmarshaling paramters for RMI calls.
if (objBytes == null) // must have been a null object
return null;
ByteArrayInputStream bin = new ByteArrayInputStream(objBytes);
// locBytes is null if no annotations
ByteArrayInputStream lin =
(locBytes == null ? null : new ByteArrayInputStream(locBytes));
MarshalledObjectInputStream in =
new MarshalledObjectInputStream(bin, lin);
T obj = (T) in.readObject();
in.close();
return obj;
| public int | hashCode()Return a hash code for this MarshalledObject .
return hash;
|
|