in library/src/main/java/com/alibaba/dcm/agent/DcmAgent.java [51:98]
public static void agentmain(@Nonnull String agentArgument) throws Exception {
logger.info(format("%s: attached with agent argument: %s.%n", DcmAgent.class.getName(), agentArgument));
agentArgument = agentArgument.trim();
if (agentArgument.isEmpty()) {
logger.info(DcmAgent.class.getName() + ": agent argument is blank, do nothing!");
return;
}
initAction2Method();
PrintWriter filePrinter = null;
try {
final Map<String, List<String>> action2Arguments = parseAgentArgument(agentArgument);
// Extract file argument, set file printer if needed
filePrinter = getFilePrintWriter(action2Arguments.remove(FILE_KEY));
if (action2Arguments.isEmpty()) {
logger.info(DcmAgent.class.getName() + ": No action in agent argument, do nothing!");
if (filePrinter != null) {
filePrinter.printf("No action in agent argument, do nothing! agent argument: %s.%n", agentArgument);
}
return;
}
boolean allSuccess = true;
for (Map.Entry<String, List<String>> entry : action2Arguments.entrySet()) {
final String action = entry.getKey();
final List<String> arguments = entry.getValue();
boolean success = doAction(action, arguments, filePrinter);
if (!success) allSuccess = false;
}
if (allSuccess && filePrinter != null) {
filePrinter.println(DCM_AGENT_SUCCESS_MARK_LINE);
}
} finally {
if (filePrinter != null) {
try {
filePrinter.close();
} catch (Exception e) {
// do nothing!
}
}
}
}