Added support to NoContext in root scope

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@142589 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-02-16 10:23:28 +00:00
parent cf8e664241
commit 9d79ef0cf0
1 changed files with 37 additions and 18 deletions

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.admin.accountingmanager.server;
import java.util.ArrayList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
@ -31,10 +32,13 @@ public class AccountingClientDaemon implements Runnable {
private ServletContextEvent sce;
private volatile boolean running = true;
private volatile AccountingCache accountingCache;
private ArrayList<Future<TaskStatus>> workers;
public AccountingClientDaemon(ServletContextEvent sce, AccountingCache accountingCache) {
public AccountingClientDaemon(ServletContextEvent sce,
AccountingCache accountingCache) {
this.sce = sce;
this.accountingCache=accountingCache;
this.accountingCache = accountingCache;
workers = new ArrayList<>();
}
public void terminate() {
@ -55,26 +59,41 @@ public class AccountingClientDaemon implements Runnable {
final TaskRequest taskRequest = jobQueue.poll();
AccountingClientCallable accountingClientCallable = new AccountingClientCallable(
taskRequest,accountingCache);
taskRequest, accountingCache);
Future<TaskStatus> futureResult = executorService
.submit(accountingClientCallable);
TaskStatus result = null;
try {
result = futureResult.get(Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MINUTES,
TimeUnit.MINUTES);
logger.info("AccountingClientTask: " + result);
} catch (InterruptedException | ExecutionException e) {
logger.error(
"AccountingClientTask: " + e.getLocalizedMessage(),
e);
} catch (TimeoutException e) {
logger.error("AccountingClientTask No response after "
+ Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MINUTES + " minutes!");
futureResult.cancel(true);
}
workers.add(futureResult);
}
if (!workers.isEmpty()) {
ArrayList<Future<TaskStatus>> dones=new ArrayList<>();
for (Future<TaskStatus> futureResult : workers) {
if (futureResult.isDone()) {
TaskStatus result = null;
try {
result = futureResult
.get(Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MINUTES,
TimeUnit.MINUTES);
logger.info("AccountingClientTask: " + result);
} catch (InterruptedException | ExecutionException e) {
logger.error(
"AccountingClientTask: "
+ e.getLocalizedMessage(), e);
} catch (TimeoutException e) {
logger.error("AccountingClientTask No response after "
+ Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MINUTES
+ " minutes!");
futureResult.cancel(true);
}
dones.add(futureResult);
}
}
workers.removeAll(dones);
}
}
}
}