| Method from org.apache.bsf.debug.util.SocketConnection Detail: |
void completionNotify(ResultCell rcell) {
try {
rcell.sendResult();
} catch (Exception ex) {
DebugLog.stdoutPrintln("Exception Raised while sending result.",
DebugLog.BSF_LOG_L0);
ex.printStackTrace();
}
}
Called from the completion of an incoming remote
method from the ThreadCell class.
The ResultCell encodes the result to send the same
way a stub encodes it expected result. |
abstract protected void dispatchInvocation(ResultCell rcell) throws Exception
|
public void exportSkeleton(Skeleton skel) {
skel.allocOid(this);
m_skeletons.put(skel.getUid(), skel);
}
|
public Skeleton getSkeleton(int uid) {
return (Skeleton) m_skeletons.get(uid);
}
|
public Stub getStub(int tid,
int uid) {
return (Stub) fStubs.swizzle(tid, uid);
}
|
public void listen() {
ResultCell cell = null;
int cmdId, thId, count;
int classId;
int methodId;
byte bytes[];
boolean errorOccured, isResult;
setListening(true);
while (keep_listening) {
try {
count = fDataInputStream.readInt();
// total count
thId = fDataInputStream.readInt();
// distributed thread id
errorOccured = fDataInputStream.readBoolean();
// cmdId.
cmdId = fDataInputStream.readInt();
// cmdId.
isResult = fDataInputStream.readBoolean();
// if result.
if (count != 0) {
bytes = new byte[count];
if (count != fInputStream.read(bytes))
throw new Error("Wire Protocol Error");
}
else bytes = new byte[0];
if (errorOccured) {
receivedException(thId,cmdId,bytes);
}
else {
if (isResult) {
// a result...
receivedResult(thId,cmdId,bytes);
}
else {
// an invocation...
receivedInvocation(thId,cmdId,bytes);
}
}
}
catch (InterruptedIOException iioe) {
// Continue on; this timeout is expected.
continue;
}
catch (Exception ex) {
wireExceptionNotify(ex);
}
}
}
|
void lockOutStream() {
synchronized (m_outStreamLock) {
while (m_outStreamLocked) {
try {
m_outStreamLock.wait();
} catch (InterruptedException ex) {
}
}
m_outStreamLocked = true;
}
}
|
public synchronized ResultCell prepareOutgoingInvoke(Stub self,
int classId,
int methodId) throws IOException {
ThreadCell tcell;
ResultCell rcell;
Thread thread;
thread = Thread.currentThread();
tcell = (ThreadCell) m_tcells.get(thread);
if (tcell == null) {
tcell = new ThreadCell(this, thread);
m_tcells.put(thread, tcell);
m_tcellsById.put(tcell.getThId(), tcell);
}
rcell = new ResultCell(this);
int cmdId;
if (ThreadCell.isServer)
cmdId = ++fCmdIdGenerator;
else
cmdId = --fCmdIdGenerator;
rcell.outgoingInvocation(cmdId, classId, methodId, self);
m_rcells.addElement(rcell);
tcell.pushInvocation(rcell);
return rcell;
}
First call made by a stub.
It will allocate the ResultCell and the output buffer for
the outgoing packet.
It will also check if this out-going remote invocation
is part of a global execution already or not.
If not, a global execution (distributed thread) is set,
other the current one is reused. |
void releaseOutStream() {
synchronized (m_outStreamLock) {
m_outStreamLocked = false;
m_outStreamLock.notifyAll();
}
}
|
public synchronized ResultCell searchCell(int cmdId) {
ResultCell cell = null;
Enumeration e;
e = m_rcells.elements();
while (e.hasMoreElements()) {
cell = (ResultCell) e.nextElement();
if (cell.cmdId == cmdId)
break;
cell = null;
}
if (cell == null)
throw new Error("Error in Wire Protocol, can't find CmdId=" +
cmdId);
return cell;
}
|
void sendPacket(int thId,
int cmdId,
boolean isResult,
byte[] bytes,
boolean errorOccured) {
try {
synchronized (fDataOutputStream) {
fDataOutputStream.writeInt(bytes.length);
fDataOutputStream.writeInt(thId);
fDataOutputStream.writeBoolean(errorOccured);
fDataOutputStream.writeInt(cmdId);
fDataOutputStream.writeBoolean(isResult);
if (bytes.length != 0) {
fOutputStream.write(bytes);
}
}
} catch (Exception ex) {
DebugLog.stdoutPrintln("Exception during sending result...",
DebugLog.BSF_LOG_L0);
ex.printStackTrace();
this.wireExceptionNotify(ex);
}
}
|
public void stopListening() {
Enumeration e;
ResultCell cell;
e = m_rcells.elements();
while (e.hasMoreElements()) {
cell = (ResultCell) e.nextElement();
try {
cell.disconnected = true;
cell.completionNotify();
} catch (Throwable t) {
t.printStackTrace();
}
}
fStubs.disconnectNotify();
setListening(false);
}
|
public Stub swizzle(int tid,
int uid) {
return fStubs.swizzle(tid, uid);
}
|
protected void wireExceptionNotify(Exception ex) {
DebugLog.stdoutPrintln("A WIRE exception occurred.",
DebugLog.BSF_LOG_L2);
DebugLog.stdoutPrintln(ex.toString(),
DebugLog.BSF_LOG_L2);
disconnectNotify(ex);
fStubs.disconnectNotify();
setListening(false);
}
A Wire-related exception occurred.
We will consider that we have lost the connection.
All stubs will be revoked... allowing higher-level
listener to pick up that some remote objects have
been revoked through the StubListener mechanism.
Log at lower priority than a standard exception,
since this is the client quit mechanism too. |