use of com.creditease.agent.spi.Abstract1NTask in project uavstack by uavorg.
the class UpgradeDownloadRequestHandler method handle.
@Override
public void handle(UpgradeHttpMessage message) {
HttpMessage httpMsg = (HttpMessage) message.getObjectParam("message");
// Package downloading is time-consuming task, so use 1+n queue to execute it.
I1NQueueWorker queueWorker = this.get1NQueueWorkerMgr().getQueueWorker(this.feature, UpgradeConstants.UPGRADE_1N_QUEUE_NAME);
if (queueWorker == null) {
if (log.isTraceEnable()) {
log.warn(this, "Download 1N queue does not exit, so ignore this download request");
}
httpMsg.putResponseBodyInString("Internal error: 1N queue worker doese not exist", 500, "UTF-8");
return;
}
String baseDir = this.getConfigManager().getFeatureConfiguration(feature, "download.dir");
String target = httpMsg.getParameter(UpgradeConstants.DOWNLOAD_REQUEST_PARAM_KEY);
String software = httpMsg.getParameter(UpgradeConstants.DOWNLOAD_TARGET_SOFTWARE);
if ("list".equalsIgnoreCase(target)) {
// get the list of upgrade package
handleListFileRequest(baseDir, software, httpMsg);
return;
} else if ("listdir".equalsIgnoreCase(target)) {
handleListDirRequest(baseDir, httpMsg);
return;
}
int downloadThreshold = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "download.threshold"), 10);
synchronized (this) {
if (log.isTraceEnable()) {
log.info(this, "Current download 1+N worker has " + queueWorker.getActiveCount() + " working tasks");
}
if (queueWorker.getActiveCount() >= downloadThreshold) {
httpMsg.putResponseBodyInString("Too Many Requests", UpgradeConstants.HTTP_CODE_TOO_MANY_REQUESTS, "UTF-8");
return;
}
Abstract1NTask task = new UpgradeDownloadTask(cName, feature, httpMsg);
queueWorker.put(task);
}
}
Aggregations