/**
* Generate new requests as needed and tally the response.
* The final invoke is the termination request/response.
*/
void doInvoker() {
InvocationImpl request = new InvocationImpl();
while (numTerminations > 0) {
int rand = nextRandom(10);
if (numInvokes < maxInvokes &&
(numResponses == numInvokes || (rand < 5))) {
// produce a new INIT request for a random app, class
int targetid = nextRandom(nappIDs);
int targetcn = nextRandom(nclassnames);
request.suiteId = getAppID(targetid);
request.classname = getClassname(targetcn);
request.invokingSuiteId = appID;
request.invokingClassname = classname;
request.responseRequired = true;
request.ID = Integer.toString(numInvokes);
request.status = Invocation.INIT;
int wait = nextRandom(500);
sleep(wait);
InvocationStore.put(request);
++numInvokes;
println("invoke: +" + wait + " ", request);
}
// Consume a response; block until some
InvocationImpl response = new InvocationImpl();
response = InvocationStore.getResponse(response,
appID, classname, true);
if (response != null) {
if (response.status == Invocation.OK) {
testcase.assertEquals(appID +
" verify target appID",
appID, response.suiteId);
testcase.assertEquals(appID +
" verify target classname",
classname, response.classname);
println("response", response);
if ("terminate".equals(response.action)) {
numTerminations--;
} else {
// Keep track of responses
scorecard[Integer.parseInt(response.ID)] += 1;
++numResponses;
/*
* If just finished receiving the max responses;
* send the terminations
*/
if (numResponses == maxInvokes) {
sendAll(Invocation.INIT, "terminate");
}
}
} else {
testcase.assertNull(appID + " illegal response:",
response);
}
}
}
sleep(2000L);
do {
request = InvocationStore.getResponse(new InvocationImpl(),
appID, classname, false);
} while (request != null);
// Terminate responder thread
stop();