| Method from org.apache.bsf.debug.util.ResultCell Detail: |
public void booleanResult(boolean val) {
bool = val;
waitingForCode = DebugConstants.WAIT_FOR_BOOLEAN;
}
|
public void completionNotify() {
if (thread!=null) {
thread.completionNotify(this);
}
}
|
public void doubleResult(double val) {
dval = val;
waitingForCode = DebugConstants.WAIT_FOR_DOUBLE;
}
|
public void floatResult(float val) {
fval =val;
waitingForCode = DebugConstants.WAIT_FOR_FLOAT;
}
|
public Exception getException() {
return exception;
}
|
void incomingInvocation(int cmdId,
byte[] bytes) throws IOException {
this.done = false;
this.cmdId = cmdId;
// set the incoming packet...
this.fInPacket = new ByteArrayInputStream(bytes);
this.fDataInputStream = new DataInputStream(fInPacket);
// pre-allocate the outgoing packet.
this.fOutPacket = new ByteArrayOutputStream();
this.fDataOutputStream = new DataOutputStream(fOutPacket);
this.classId = readId();
this.methodId = readId();
this.selfSkel = (Skeleton)readObject();
DebugLog.stdoutPrintln(" " +
DebugConstants.getConstantName(classId) +
"::" +
DebugConstants.getConstantName(methodId),
DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" on " + this.selfSkel,
DebugLog.BSF_LOG_L3);
}
|
public void intResult(int val) {
val32 = val;
waitingForCode = DebugConstants.WAIT_FOR_INT;
}
|
public void longResult(long val) {
val64 = val;
waitingForCode = DebugConstants.WAIT_FOR_LONG;
}
|
public void objectResult(Object obj) {
oval = obj;
waitingForCode = DebugConstants.WAIT_FOR_OBJECT;
}
|
void outgoingInvocation(int cmdId,
int classId,
int methodId,
Stub self) throws IOException {
this.done = false;
this.cmdId = cmdId;
this.classId = classId;
this.methodId = methodId;
this.selfStub = self;
// allocate the outgoing packet...
this.fOutPacket = new ByteArrayOutputStream();
this.fDataOutputStream = new DataOutputStream(fOutPacket);
// no in packet, it will be provided upon
// completion...
this.fInPacket = null;
this.fDataInputStream = null;
// format the header of the packet.
// Pre-packet header is composed of the size,
// the thid, and the cmdId.
// They are written when the packet is emitted.
writeId(classId);
writeId(methodId);
writeObject(self);
}
|
public void parseResult() {
try {
_parseResult();
} catch (Exception ex) {
m_con.wireExceptionNotify(ex);
}
}
|
public void print() {
DebugLog.stdoutPrintln("ResultCell...", DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" tid=" +
DebugConstants.getConstantName(tid),
DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" classId [" + classId +
"] =" +
DebugConstants.getConstantName(classId),
DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" methodId [" + methodId +
"] =" + DebugConstants.getConstantName(methodId), DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" bool="+bool, DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" val32="+val32, DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" val64="+val64, DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" fval="+fval, DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" dval="+dval, DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" oval="+oval, DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" exception=" + exception,
DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" message=" +
exception.getMessage(), DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(" stack trace:",
DebugLog.BSF_LOG_L3);
DebugLog.stdoutPrintln(new String(stackTraceBytes),
DebugLog.BSF_LOG_L3);
}
|
public boolean readBoolean() throws IOException {
boolean bool = fDataInputStream.readBoolean();
DebugLog.stdoutPrintln("Connection marshalling boolean " +
bool, DebugLog.BSF_LOG_L3);
return bool;
}
Default reading methods for unmarshalling in parameters
from remote method calls. |
public double readDouble() throws IOException {
double dval = fDataInputStream.readDouble();
DebugLog.stdoutPrintln(" Unmarshalling double " + dval,
DebugLog.BSF_LOG_L3);
return dval;
}
|
public void readException() throws IOException {
exception = (Exception)readObject();
stackTraceBytes = (byte[])readObject();
}
|
public float readFloat() throws IOException {
float fval = fDataInputStream.readFloat();
DebugLog.stdoutPrintln(" Unmarshalling float " + fval,
DebugLog.BSF_LOG_L3);
return fval;
}
|
public int readId() throws IOException {
int val32 = fDataInputStream.readInt();
DebugLog.stdoutPrintln(" Unmarshalling id=[" +
DebugConstants.getConstantName(val32) +
" (" + val32 + ")", DebugLog.BSF_LOG_L3);
return val32;
}
|
public int readInt() throws IOException {
int val32 = fDataInputStream.readInt();
DebugLog.stdoutPrintln(" Unmarshalling int " + val32,
DebugLog.BSF_LOG_L3);
return val32;
}
|
public long readLong() throws IOException {
long val64 = fDataInputStream.readLong();
DebugLog.stdoutPrintln(" Unmarshalling long " + val64,
DebugLog.BSF_LOG_L3);
return val64;
}
|
public Object readObject() throws IOException {
ObjectInputStream ois;
Object object = null;
int tag;
int tid, uid, enguid;
DebugLog.stdoutPrintln(" Unmarshalling an object...",
DebugLog.BSF_LOG_L3);
tag = fDataInputStream.readInt();
switch (tag) {
case DebugConstants.NULL_OBJECT :
object = null;
DebugLog.stdoutPrintln(" null object",
DebugLog.BSF_LOG_L3);
break;
case DebugConstants.VALUE_OBJECT :
try {
ois = new ObjectInputStream(fInPacket);
object = ois.readObject();
DebugLog.stdoutPrintln(" value object= " +
object, DebugLog.BSF_LOG_L3);
} catch (ClassNotFoundException ex) {
object = null;
}
break;
case DebugConstants.STUB_OBJECT :
// it was a stub on the sender side,
// so it maps to a local skeleton
// that was remoted...
uid = fDataInputStream.readInt();
object = m_con.getSkeleton(uid);
DebugLog.stdoutPrintln(" Local skel object= " +
object + "(uid=" + uid + ")",
DebugLog.BSF_LOG_L3);
break;
case DebugConstants.SKEL_OBJECT :
// it was a skeleton on the sender's side
// so it has to swizzled into a stub on this
// side...
tid = fDataInputStream.readInt();
uid = fDataInputStream.readInt();
object = m_con.getStub(tid,uid);
DebugLog.stdoutPrintln(" Local stub object= " +
object + "(tid=" + tid + "; uid=" +
uid + ")", DebugLog.BSF_LOG_L3);
break;
default:
throw new Error("Wire Protocol Error: unknown object format.");
}
return object;
}
|
public void sendInvocation() throws Exception {
byte bytes[];
bytes = fOutPacket.toByteArray();
m_con.sendPacket(thread.getThId(),cmdId,false,bytes,false);
}
|
public void sendResult() {
try {
_sendResult();
} catch (Exception ex) {
m_con.wireExceptionNotify(ex);
}
}
|
public void setException(Exception ex) {
exception = ex;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(bytes);
stream.println(ex.getMessage());
ex.printStackTrace(stream);
stackTraceBytes = bytes.toByteArray();
}
|
public void setPacketBytes(byte[] bytes) {
fInPacket = new ByteArrayInputStream(bytes);
this.fDataInputStream = new DataInputStream(fInPacket);
fOutPacket = new ByteArrayOutputStream();
this.fDataOutputStream = new DataOutputStream(fOutPacket);
}
Once a packet has been read from the socket,
it is passed to the ResultCell and further processed
to parse the remaining data item. |
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("ResultCell...\n");
buf.append(" tid="+DebugConstants.getConstantName(tid)+"\n");
buf.append(" classId ["+classId+"] ="+DebugConstants.getConstantName(classId)+"\n");
buf.append(" methodId ["+methodId+"] ="+DebugConstants.getConstantName(methodId)+"\n");
buf.append(" bool="+bool+"\n");
buf.append(" val32="+val32+"\n");
buf.append(" val64="+val64+"\n");
buf.append(" fval="+fval+"\n");
buf.append(" dval="+dval+"\n");
buf.append(" oval="+oval+"\n");
buf.append(" exception="+exception+"\n");
buf.append(" message="+exception.getMessage()+"\n");
return buf.toString();
}
|
public void voidResult() {
waitingForCode = DebugConstants.WAIT_FOR_VOID;
}
|
public boolean waitForBooleanValue() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_BOOLEAN;
thread.waitOnCompletion(this);
return bool;
}
|
public void waitForCompletion() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_VOID;
thread.waitOnCompletion(this);
}
|
public double waitForDoubleValue() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_DOUBLE;
thread.waitOnCompletion(this);
return dval;
}
|
public float waitForFloatValue() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_FLOAT;
thread.waitOnCompletion(this);
return fval;
}
|
public int waitForIntValue() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_INT;
thread.waitOnCompletion(this);
return val32;
}
|
public long waitForLongValue() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_LONG;
thread.waitOnCompletion(this);
return val64;
}
|
public Object waitForObject() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_OBJECT;
thread.waitOnCompletion(this);
return oval;
}
|
public Object waitForValueObject() throws Exception {
waitingForCode = DebugConstants.WAIT_FOR_OBJECT;
thread.waitOnCompletion(this);
return oval;
}
The following methods are for waiting for the result of an
outgoing method invocation. |
public void writeBoolean(boolean bool) throws IOException {
DebugLog.stdoutPrintln(" marshalling bool" + bool, DebugLog.BSF_LOG_L3);
fDataOutputStream.writeBoolean(bool);
}
Default writing methods for marshalling out parameters
in remote method calls. |
public void writeDouble(double dval) throws IOException {
DebugLog.stdoutPrintln(" marshalling double " + dval,
DebugLog.BSF_LOG_L3);
fDataOutputStream.writeDouble(dval);
}
|
public void writeException() throws IOException {
writeObject(exception);
writeObject(stackTraceBytes);
}
|
public void writeFloat(float fval) throws IOException {
DebugLog.stdoutPrintln(" marshalling float " + fval,
DebugLog.BSF_LOG_L3);
fDataOutputStream.writeFloat(fval);
}
|
public void writeId(int id) throws IOException {
DebugLog.stdoutPrintln(" marshalling id=" +
DebugConstants.getConstantName(id),
DebugLog.BSF_LOG_L3);
fDataOutputStream.writeInt(id);
}
|
public void writeInt(int val32) throws IOException {
DebugLog.stdoutPrintln(" marshalling int " + val32, DebugLog.BSF_LOG_L3);
fDataOutputStream.writeInt(val32);
}
|
public void writeLong(long val64) throws IOException {
DebugLog.stdoutPrintln(" marshalling long " + val64,
DebugLog.BSF_LOG_L3);
fDataOutputStream.writeLong(val64);
}
|
public void writeObject(Object object) throws IOException {
if (object == null) {
DebugLog.stdoutPrintln(" marshalling null object ",
DebugLog.BSF_LOG_L3);
fDataOutputStream.writeInt(DebugConstants.NULL_OBJECT);
}
else {
if (object instanceof Skeleton) {
Skeleton skel = (Skeleton)object;
m_con.exportSkeleton(skel);
DebugLog.stdoutPrintln(" marshalling (iid=" +
skel.getTid() + ";uid=" +
skel.getUid() + " skeleton= " +
skel, DebugLog.BSF_LOG_L3);
fDataOutputStream.writeInt(DebugConstants.SKEL_OBJECT);
fDataOutputStream.writeInt(skel.getTid());
fDataOutputStream.writeInt(skel.getUid());
}
else if (object instanceof Stub) {
Stub stub = (Stub)object;
DebugLog.stdoutPrintln(" marshalling (tid=" +
tid + ";uid=" + stub.getUid() +
" stub= " + stub, DebugLog.BSF_LOG_L3);
fDataOutputStream.writeInt(DebugConstants.STUB_OBJECT);
// no need to send the tid, the uid identifies
// the skeleton on the other side that already exists.
fDataOutputStream.writeInt(stub.getUid());
}
else {
ObjectOutputStream oos;
DebugLog.stdoutPrintln("Connection marshalling " +
"value object " + object,
DebugLog.BSF_LOG_L3);
fDataOutputStream.writeInt(DebugConstants.VALUE_OBJECT);
oos = new ObjectOutputStream(fOutPacket);
oos.writeObject(object);
}
}
}
|