director.tell("ACK", getSelf());
} else if (message instanceof AgentResponse) {
try {
GenericAgentResponse gap = null;
// this guareetee gap is not NULL :-)
if ((message instanceof GenericAgentResponse)) {
gap = (GenericAgentResponse) message;
} else {
gap = new GenericAgentResponse((AgentResponse) message,
DateUtils.getNowDateTimeStrSdsm());
}
// 20130422 to trim the message if needed; careful, when there
// are exception: will make the
// bug fixed: 20130423 check gap.getResponseContent() length
// ==0; then -1 will make it out of bound!
if (gap != null && gap.getResponseContent() != null
&& !gap.getResponseContent().isEmpty()
&& responseExtractIndexStart >= 0
&& responseExtractIndexEnd >= 0
&& responseExtractIndexStart <= responseExtractIndexEnd) {
int trimStartIndex = (int) Math.min(
responseExtractIndexStart, gap.getResponseContent()
.length() - 1);
int trimEndIndex = (int) Math.min(responseExtractIndexEnd,
gap.getResponseContent().length() - 1);
trimStartIndex = (trimStartIndex < 0) ? 0 : trimStartIndex;
trimEndIndex = (trimEndIndex < 0) ? 0 : trimEndIndex;
gap.setResponseContent(gap.getResponseContent().substring(
trimStartIndex, trimEndIndex));
}
this.responseCount += 1;
/**
* 20131009: add feedback of current responseCount to asst
* manager ResponseCountToBatchSenderAsstManager
*/
final ResponseCountToBatchSenderAsstManager responseCountToBatchSenderAsstManager = new ResponseCountToBatchSenderAsstManager(
this.responseCount);
if (batchSenderAsstManager != null) {
batchSenderAsstManager.tell(
responseCountToBatchSenderAsstManager, getSelf());
if (VarUtils.IN_DETAIL_DEBUG) {
models.utils.LogUtils
.printLogError("Send batchSenderAsstManager to responseCountToBatchSenderAsstManager: "
+ this.responseCount);
}
} else {
models.utils.LogUtils
.printLogError("batchSenderAsstManager is empty; when trying to send responseCountToBatchSenderAsstManager In manager resonse handling. "
+ DateUtils.getNowDateTimeStrSdsm());
}
String hostName = gap.getHost();
responseListKey.add(hostName);
responseListValue.add(gap);
String displayResponse = (gap.getResponseContent() == null || gap
.getResponseContent().length() < 1) ? "RESPONSE_CONTENT_EMPTY_OR_NULL"
: gap.getResponseContent()
.substring(
0,
Math.min(
VarUtils.AGNET_RESPONSE_MAX_RESPONSE_DISPLAY_BYTE1,
gap.getResponseContent()
.length()));
if (this.responseCount % 1 == 0) {
long responseReceiveTime = System.currentTimeMillis();
// %.5g%n
double progressPercent = (double) (responseCount)
/ (double) (requestCount) * 100.0;
String responseReceiveTimeStr = DateUtils
.getDateTimeStr(new Date(responseReceiveTime));
String secondElapsedStr = new Double(
(responseReceiveTime - startTime) / 1000.0)
.toString();
// percent is escaped using percent sign
models.utils.LogUtils
.printLogNormal(String
.format("\n[%d]__RESPONSE_RECV_IN_MGR %d (+%d) / %d (%.5g%%) after %s SEC for %s at %s , directorJobId : %s , RESPONSE_BRIEF: %s\n",
responseCount, responseCount,
requestCount - responseCount,
requestCount, progressPercent,
secondElapsedStr, hostName,
responseReceiveTimeStr,
directorJobId, displayResponse));
}
getContext().stop(getSender());
if (this.responseCount == this.requestCount && requestComplete) {
System.out.println("All result back.");
models.utils.LogUtils
.printLogNormal("SUCCESSFUL GOT ON ALL RESPONSES: Received all the expected messages. Count matches: "
+ this.requestCount
+ " at time: "
+ DateUtils.getNowDateTimeStrSdsm());
// Send message to the future with the result
long currTime = System.currentTimeMillis();
models.utils.LogUtils
.printLogNormal("\nTime taken to get all responses back : "
+ (currTime - startTime) / 1000.0 + " secs");
// MUST SHUT DOWN: This is a double check. Acutally agent
// operation worker has already shutdown.
for (ActorRef worker : workerQ) {
if (worker!=null)
getContext().stop(worker);
}
// 20131010: kill asst manager
if (timeoutMessageCancellable != null) {
timeoutMessageCancellable.cancel();
}
}// end when all requests have resonponse
} catch (Throwable t) {
t.printStackTrace();
}
} else if (message instanceof InternalMessageType) {
switch ((InternalMessageType) message) {
case OPERATION_TIMEOUT:
cancelRequestAndCancelWorkers();
break;
}
} else if (message instanceof Map<?, ?>) {
System.out.println("Part request!");
requestComplete = false;
List<NodeData> retryNodeDataList = new ArrayList<NodeData>();
List<String> retryJobIdList = new ArrayList<String>();
requestCount += ((Map<?, ?>) message).size();
for(Entry<String, NodeData> e: ((Map<String, NodeData>) message).entrySet()) {
retryJobIdList.add(e.getKey());
retryNodeDataList.add(e.getValue());
dataStore.get(nodeGroupType).getNodeDataMapValid().put(e.getKey(), e.getValue());
}
getSender().tell("ACK", getSelf());
}else if (message instanceof streamRequestToManager) {
streamRequestToManager sRTM = (streamRequestToManager) message;
System.out.println("StreamRequestToManager : " + sRTM.index);
BatchResponseFromManager partStreamResponse = new BatchResponseFromManager();
if (sRTM.index >= responseListKey.size()) {
getSender().tell(partStreamResponse, getSelf());
} else {
int chunckSize = Math.min(1024, responseListKey.size()-sRTM.index);
try {
for (int i=sRTM.index; i< sRTM.index + chunckSize; i++) {
partStreamResponse.responseMap.put(responseListKey.get(i), responseListValue.get(i));
}
while (sizeof(partStreamResponse) > 15728640 && chunckSize >= 1) {
chunckSize /= 2;
partStreamResponse = new BatchResponseFromManager();
for (int i=sRTM.index; i< sRTM.index + chunckSize; i++) {
partStreamResponse.responseMap.put(responseListKey.get(i), responseListValue.get(i));
}
}
if (chunckSize == 0) {
partStreamResponse.responseMap.put(responseListKey.get(sRTM.index), new GenericAgentResponse("Content Too Large, Discarded.", "", ""));
}
} catch (IOException e) {
e.printStackTrace();
}