for (RequestID requestID : ids) {
RequestWorkItem holder = requests.get(requestID);
if(holder != null && !holder.isCanceled()) {
RequestMetadata req = new RequestMetadata();
req.setExecutionId(holder.requestID.getExecutionID());
req.setSessionId(holder.requestID.getConnectionID());
req.setCommand(holder.requestMsg.getCommandString());
req.setStartTime(holder.getProcessingTimestamp());
req.setState(holder.isCanceled()?ProcessingState.CANCELED:holder.isDoneProcessing()?ProcessingState.DONE:ProcessingState.PROCESSING);
switch (holder.getThreadState()) {
case DONE:
case IDLE:
req.setThreadState(ThreadState.IDLE);
break;
default:
if (holder.isProcessing()) {
req.setThreadState(ThreadState.RUNNING);
} else {
req.setThreadState(ThreadState.QUEUED);
}
}
if (holder.getTransactionContext() != null && holder.getTransactionContext().getTransactionType() != Scope.NONE) {
req.setTransactionId(holder.getTransactionContext().getTransactionId());
}
for (DataTierTupleSource conInfo : holder.getConnectorRequests()) {
String connectorName = conInfo.getConnectorName();
if (connectorName == null) {
continue;
}
// If the request has not yet completed processing, then
// add all the subrequest messages
AtomicRequestMessage arm = conInfo.getAtomicRequestMessage();
RequestMetadata info = new RequestMetadata();
if (conInfo.isQueued()) {
info.setThreadState(ThreadState.QUEUED);
} else if (conInfo.isRunning()) {
info.setThreadState(ThreadState.RUNNING);
} else {
info.setThreadState(ThreadState.IDLE);
}
info.setExecutionId(arm.getRequestID().getExecutionID());
info.setSessionId(holder.requestID.getConnectionID());
info.setCommand(arm.getCommand().toString());
info.setStartTime(arm.getProcessingTimestamp());
info.setSourceRequest(true);
info.setNodeId(arm.getAtomicRequestID().getNodeID());
info.setState(conInfo.isCanceled()?ProcessingState.CANCELED:conInfo.isDone()?ProcessingState.DONE:ProcessingState.PROCESSING);
results.add(info);
}
// check if only need long running queries.
long elapsedTime = System.currentTimeMillis() - req.getStartTime();