Refs #12184: Create different pools for Scheduled Thread in accounting stack
Task-Url: https://support.d4science.org/issues/12184 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@169818 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c2041599cc
commit
7f3ce5e96f
|
@ -2,12 +2,14 @@ package org.gcube.accounting.aggregator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.validations.validators.RegexReplace;
|
import org.gcube.accounting.datamodel.validations.validators.RegexReplace;
|
||||||
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
||||||
import org.gcube.documentstore.persistence.ExecutorUtils;
|
|
||||||
import org.gcube.documentstore.records.DSMapper;
|
import org.gcube.documentstore.records.DSMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -19,6 +21,24 @@ public class RegexRulesAggregator implements Runnable {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RegexRulesAggregator.class);
|
private static final Logger logger = LoggerFactory.getLogger(RegexRulesAggregator.class);
|
||||||
|
|
||||||
|
private static final ScheduledExecutorService REGEX_REDISCOVERY_POOL;
|
||||||
|
|
||||||
|
static {
|
||||||
|
|
||||||
|
REGEX_REDISCOVERY_POOL = Executors.newScheduledThreadPool(50, new ThreadFactory() {
|
||||||
|
|
||||||
|
private int counter = 0;
|
||||||
|
private static final String prefix = "RegexRediscoveryThread";
|
||||||
|
|
||||||
|
public Thread newThread(Runnable r) {
|
||||||
|
return new Thread(r, prefix + "-" + counter++);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected TimeUnit timeUnit = TimeUnit.MINUTES;
|
protected TimeUnit timeUnit = TimeUnit.MINUTES;
|
||||||
protected long delay = TimeUnit.MINUTES.toMinutes(15);
|
protected long delay = TimeUnit.MINUTES.toMinutes(15);
|
||||||
|
|
||||||
|
@ -46,8 +66,10 @@ public class RegexRulesAggregator implements Runnable {
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RegexReplace> getRegexReplacelist() {
|
public List<RegexReplace> getRegexReplaceList() {
|
||||||
return regexReplaceList;
|
synchronized(regexReplaceList) {
|
||||||
|
return regexReplaceList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegexReplace addRegexReplace(String serviceClass, String serviceName, String regex, String replace) {
|
public RegexReplace addRegexReplace(String serviceClass, String serviceName, String regex, String replace) {
|
||||||
|
@ -99,7 +121,7 @@ public class RegexRulesAggregator implements Runnable {
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
if(reloadAggregatorRules == null) {
|
if(reloadAggregatorRules == null) {
|
||||||
reloadAggregatorRules = ExecutorUtils.scheduler.scheduleAtFixedRate(this, delay, delay, timeUnit);
|
reloadAggregatorRules = REGEX_REDISCOVERY_POOL.scheduleAtFixedRate(this, delay, delay, timeUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,21 +19,6 @@ public class CalledMethodRegexReplaceValidator implements FieldAction {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(CalledMethodRegexReplaceValidator.class);
|
private static Logger logger = LoggerFactory.getLogger(CalledMethodRegexReplaceValidator.class);
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static List<RegexReplace> getRegexReplacelist() {
|
|
||||||
return RegexRulesAggregator.getInstance().getRegexReplacelist();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static RegexReplace addRegexReplace(String serviceClass, String serviceName, String regex, String replace) {
|
|
||||||
return RegexRulesAggregator.getInstance().addRegexReplace(serviceClass, serviceName, regex, replace);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static RegexReplace addRegexReplace(RegexReplace regexReplace) {
|
|
||||||
return RegexRulesAggregator.getInstance().addRegexReplace(regexReplace);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +49,9 @@ public class CalledMethodRegexReplaceValidator implements FieldAction {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(RegexReplace regexReplace : getRegexReplacelist()) {
|
List<RegexReplace> regexReplaceList = RegexRulesAggregator.getInstance().getRegexReplaceList();
|
||||||
|
|
||||||
|
for(RegexReplace regexReplace : regexReplaceList) {
|
||||||
if(serviceClass.compareTo(regexReplace.getServiceClass())==0 && serviceName.compareTo(regexReplace.getServiceName())==0) {
|
if(serviceClass.compareTo(regexReplace.getServiceClass())==0 && serviceName.compareTo(regexReplace.getServiceName())==0) {
|
||||||
Matcher matcher = regexReplace.regexPattern.matcher(stringValue);
|
Matcher matcher = regexReplace.regexPattern.matcher(stringValue);
|
||||||
if(matcher.matches()) {
|
if(matcher.matches()) {
|
||||||
|
|
|
@ -17,12 +17,16 @@ import org.gcube.documentstore.persistence.PersistenceBackendConfiguration;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class AccountingPersistenceConfiguration extends PersistenceBackendConfiguration {
|
public class AccountingPersistenceConfiguration extends PersistenceBackendConfiguration {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AccountingPersistenceConfiguration.class);
|
||||||
|
|
||||||
protected static final String TARGET_SCOPE = "targetScope";
|
protected static final String TARGET_SCOPE = "targetScope";
|
||||||
|
|
||||||
protected static final String SERVICE_ENDPOINT_CATEGORY = "Accounting";
|
protected static final String SERVICE_ENDPOINT_CATEGORY = "Accounting";
|
||||||
|
@ -38,8 +42,13 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
||||||
|
|
||||||
public AccountingPersistenceConfiguration(Class<?> clz) throws Exception {
|
public AccountingPersistenceConfiguration(Class<?> clz) throws Exception {
|
||||||
super();
|
super();
|
||||||
ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz);
|
try {
|
||||||
setValues(serviceEndpoint, clz);
|
ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz);
|
||||||
|
setValues(serviceEndpoint, clz);
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.error("Error while instancing {} in context {}", this.getClass().getSimpleName(),
|
||||||
|
BasicUsageRecord.getContextFromToken(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServiceEndpoint getServiceEndpoint(String serviceEndpointCategory, String serviceEndpointName, Class<?> clz){
|
protected ServiceEndpoint getServiceEndpoint(String serviceEndpointCategory, String serviceEndpointName, Class<?> clz){
|
||||||
|
|
|
@ -63,6 +63,8 @@ public class AccountingPersistenceFactory {
|
||||||
//flush all and shutdown connection and thread
|
//flush all and shutdown connection and thread
|
||||||
PersistenceBackendFactory.flushAll();
|
PersistenceBackendFactory.flushAll();
|
||||||
PersistenceBackendFactory.shutdown();
|
PersistenceBackendFactory.shutdown();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class RegexRulesAggregatorTest extends ScopedTest {
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
RegexRulesAggregator regexRulesAggregator = RegexRulesAggregator.getInstance();
|
RegexRulesAggregator regexRulesAggregator = RegexRulesAggregator.getInstance();
|
||||||
List<RegexReplace> list = regexRulesAggregator.getRegexReplacelist();
|
List<RegexReplace> list = regexRulesAggregator.getRegexReplaceList();
|
||||||
for(RegexReplace regexReplace : list) {
|
for(RegexReplace regexReplace : list) {
|
||||||
logger.debug("{} {} {} {}", regexReplace.getServiceClass(), regexReplace.getServiceName(), regexReplace.getRegex(), regexReplace.getReplace());
|
logger.debug("{} {} {} {}", regexReplace.getServiceClass(), regexReplace.getServiceName(), regexReplace.getRegex(), regexReplace.getReplace());
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ public class ServiceUsageRecordTest extends ScopedTest {
|
||||||
logger.debug("{}", usageRecord);
|
logger.debug("{}", usageRecord);
|
||||||
|
|
||||||
RegexRulesAggregator regexRulesAggregator = RegexRulesAggregator.getInstance();
|
RegexRulesAggregator regexRulesAggregator = RegexRulesAggregator.getInstance();
|
||||||
List<RegexReplace> list = regexRulesAggregator.getRegexReplacelist();
|
List<RegexReplace> list = regexRulesAggregator.getRegexReplaceList();
|
||||||
for(RegexReplace regexReplace : list) {
|
for(RegexReplace regexReplace : list) {
|
||||||
logger.debug("{} {} {} {}", regexReplace.getServiceClass(), regexReplace.getServiceName(), regexReplace.getRegex(), regexReplace.getReplace());
|
logger.debug("{} {} {} {}", regexReplace.getServiceClass(), regexReplace.getServiceName(), regexReplace.getRegex(), regexReplace.getReplace());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue