001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.dmi;
006:
007: import com.tc.async.api.EventContext;
008: import com.tc.io.TCByteBufferInput;
009: import com.tc.io.TCByteBufferOutput;
010: import com.tc.io.TCSerializable;
011: import com.tc.object.ObjectID;
012: import com.tc.util.Assert;
013:
014: import java.io.IOException;
015:
016: /**
017: * Representation of a distributed method invocation
018: */
019: public class DmiDescriptor implements TCSerializable, EventContext {
020:
021: public static final DmiDescriptor[] EMPTY_ARRAY = new DmiDescriptor[0];
022:
023: private ObjectID receiverId;
024: private ObjectID dmiCallId;
025: private DmiClassSpec[] classSpecs;
026: private boolean faultReceiver;
027:
028: /**
029: * New empty descriptor
030: */
031: public DmiDescriptor() {
032: receiverId = null;
033: dmiCallId = null;
034: }
035:
036: /**
037: * New descriptor
038: *
039: * @param receiverId Receiver object identifier
040: * @param dmiCallId DMI call identifier
041: * @param classSpecs Classes
042: * @param faultReceiver True if should use local fault receiver
043: */
044: public DmiDescriptor(ObjectID receiverId, ObjectID dmiCallId,
045: DmiClassSpec[] classSpecs, boolean faultReceiver) {
046: Assert.pre(receiverId != null);
047: Assert.pre(dmiCallId != null);
048: Assert.pre(classSpecs != null);
049:
050: this .receiverId = receiverId;
051: this .dmiCallId = dmiCallId;
052: this .classSpecs = classSpecs;
053: this .faultReceiver = faultReceiver;
054: }
055:
056: /**
057: * @return Receiver ID
058: */
059: public ObjectID getReceiverId() {
060: return receiverId;
061: }
062:
063: /**
064: * @return DMI call ID
065: */
066: public ObjectID getDmiCallId() {
067: return dmiCallId;
068: }
069:
070: /**
071: * @return Classes
072: */
073: public DmiClassSpec[] getClassSpecs() {
074: return classSpecs;
075: }
076:
077: /**
078: * @return True if should use fault receiver
079: */
080: public boolean isFaultReceiver() {
081: return faultReceiver;
082: }
083:
084: public String toString() {
085: return "DmiDescriptor{receiverId=" + receiverId
086: + ", dmiCallId=" + dmiCallId + ", ClassSpecs="
087: + DmiClassSpec.toString(classSpecs) + "}";
088: }
089:
090: /**
091: * Deserialize descriptor from input stream into this object
092: *
093: * @param in Input stream
094: * @return this
095: */
096: public Object deserializeFrom(TCByteBufferInput in)
097: throws IOException {
098: receiverId = new ObjectID(in.readLong());
099: dmiCallId = new ObjectID(in.readLong());
100: faultReceiver = in.readBoolean();
101: final int size = in.readInt();
102: classSpecs = new DmiClassSpec[size];
103: for (int i = 0; i < classSpecs.length; i++) {
104: final String classLoaderDesc = in.readString();
105: final String className = in.readString();
106: classSpecs[i] = new DmiClassSpec(classLoaderDesc, className);
107: }
108: return this ;
109: }
110:
111: /**
112: * Serialize this descriptor to out
113: *
114: * @param out Output stream
115: */
116: public void serializeTo(TCByteBufferOutput out) {
117: out.writeLong(receiverId.toLong());
118: out.writeLong(dmiCallId.toLong());
119: out.writeBoolean(faultReceiver);
120: out.writeInt(classSpecs.length);
121: for (int i = 0; i < classSpecs.length; i++) {
122: out.writeString(classSpecs[i].getClassLoaderDesc());
123: out.writeString(classSpecs[i].getClassName());
124: }
125: }
126: }
|