Simplify WebApplicationConfig

This commit is contained in:
alandavis
2022-08-11 15:59:17 +01:00
parent 51d9311392
commit ba711cb2da
4 changed files with 33 additions and 44 deletions

View File

@@ -43,7 +43,6 @@ import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class})
@EnableAsync
//@EnableScheduling
//@EnableRetry

View File

@@ -40,6 +40,7 @@ import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
@@ -47,6 +48,7 @@ import org.springframework.web.client.RestTemplate;
/**
* Simple Rest client that call Alfresco Shared File Store
*/
@Service
public class AlfrescoSharedFileStoreClient
{
@Value("${fileStoreUrl}")

View File

@@ -33,6 +33,7 @@ import org.alfresco.transform.base.registry.TransformRegistry;
import org.alfresco.transform.common.TransformerDebug;
import org.alfresco.transform.messages.TransformRequestValidator;
import org.alfresco.transform.registry.TransformServiceRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -61,40 +62,22 @@ public class WebApplicationConfig implements WebMvcConfigurer
public void addInterceptors(InterceptorRegistry registry)
{
registry
.addInterceptor(transformInterceptor())
.addInterceptor(new TransformInterceptor())
.addPathPatterns(ENDPOINT_TRANSFORM, "/live", "/ready");
}
@Bean
public TransformInterceptor transformInterceptor()
{
return new TransformInterceptor();
}
@Bean
public RestTemplate restTemplate()
{
return new RestTemplate();
}
@Bean
public AlfrescoSharedFileStoreClient alfrescoSharedFileStoreClient()
{
return new AlfrescoSharedFileStoreClient();
}
@Bean
public TransformRequestValidator transformRequestValidator()
{
return new TransformRequestValidator();
}
@Bean
public TransformServiceRegistry transformRegistry()
{
return new TransformRegistry();
}
@Bean
public TransformerDebug transformerDebug()
{

View File

@@ -32,6 +32,7 @@ import org.alfresco.transform.registry.TransformCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.retry.annotation.Backoff;
@@ -39,6 +40,7 @@ import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
@@ -48,8 +50,16 @@ import java.util.function.Supplier;
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers;
@Service
public class TransformRegistry extends AbstractTransformRegistry
{
private static final Logger log = LoggerFactory.getLogger(TransformRegistry.class);
@Autowired
private String coreVersion;
@Autowired
private List<TransformConfigSource> transformConfigSources;
private static class Data extends TransformCache
{
private TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved;
@@ -66,47 +76,32 @@ public class TransformRegistry extends AbstractTransformRegistry
}
}
private static final Logger log = LoggerFactory.getLogger(TransformRegistry.class);
@Autowired
private String coreVersion;
@Autowired
private List<TransformConfigSource> transformConfigSources;
private Data data = new Data();
// Ensures that read operations are blocked while config is being updated
private ReadWriteLock configRefreshLock = new ReentrantReadWriteLock();
private Data data = new Data();
@EventListener
void handleContextRefreshedEvent(final ContextRefreshedEvent event)
{
final ApplicationContext context = event.getApplicationContext();
// the local "initEngineConfigs" method has to be called through the Spring proxy
context.getBean(TransformRegistry.class).initRegistryOnAppStartup(null);
}
/**
* Load the registry on application startup. This allows Components in projects that extend the t-engine base
* to use @PostConstruct to add to {@code transformConfigSources}, before the registry is loaded.
*/
@EventListener
private void initRegistryOnAppStartup(final ContextRefreshedEvent event)
{
asyncRegistryInit();
}
// @Async
// @Retryable(include = {IllegalStateException.class},
// maxAttemptsExpression = "#{${transform.engine.config.retry.attempts}}",
// backoff = @Backoff(delayExpression = "#{${transform.engine.config.retry.timeout} * 1000}"))
public void asyncRegistryInit()
public void initRegistryOnAppStartup(final ContextRefreshedEvent event)
{
initRegistry();
}
/**
* Recovery method in case all the retries fail. If not specified, the @Retryable method will cause the application
* to stop.
*/
// @Recover
private void recover(IllegalStateException e)
{
log.warn(e.getMessage());
}
/**
* Takes the schedule from a spring-boot property
*/
@@ -135,6 +130,16 @@ public class TransformRegistry extends AbstractTransformRegistry
concurrentUpdate(combinedTransformConfig, transformConfigBeforeIncompleteTransformsAreRemoved);
}
/**
* Recovery method in case all the retries fail. If not specified, the @Retryable method will cause the application
* to stop.
*/
// @Recover
private void recover(IllegalStateException e)
{
log.warn(e.getMessage());
}
public TransformConfig getTransformConfig()
{
return getData().getTransformConfigBeforeIncompleteTransformsAreRemoved();