SGF-660 - Spring Cache Abstraction annotations do not trigger CQ.

This commit is contained in:
John Blum
2017-10-17 13:08:27 -07:00
parent 6512d5da40
commit 86581894e9
9 changed files with 512 additions and 31 deletions

View File

@@ -111,11 +111,11 @@ public class ContinuousQueryConfiguration extends AbstractAnnotationConfigSuppor
private List<ContinuousQueryDefinition> continuousQueryDefinitions = new ArrayList<>();
@Nullable @Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof ContinuousQueryListenerContainer) {
this.container = (ContinuousQueryListenerContainer) bean;
this.continuousQueryDefinitions.forEach(definition -> this.container.addListener(definition));
this.continuousQueryDefinitions.forEach(this.container::addListener);
this.continuousQueryDefinitions.clear();
}
else if (isApplicationBean(bean)) {
@@ -182,6 +182,7 @@ public class ContinuousQueryConfiguration extends AbstractAnnotationConfigSuppor
true, true);
return nullSafeMap(beansOfType).values().stream().collect(Collectors.toList());
})
.orElseGet(Collections::emptyList)
);

View File

@@ -27,7 +27,6 @@ import java.util.concurrent.Executor;
import org.apache.geode.cache.client.Pool;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer;
import org.springframework.util.ErrorHandler;
@@ -75,9 +74,9 @@ public @interface EnableContinuousQueries {
/**
* Refers to the name of the {@link Pool} over which CQs are registered and CQ events are received.
*
* Defaults to {@literal gemfirePool}.
* Defaults to unset.
*/
String poolName() default GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME;
String poolName() default "";
/**
* Refers to the name of the {@link Executor} bean used to process CQ events asynchronously.

View File

@@ -117,7 +117,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
private List<ContinuousQueryListenerContainerConfigurer> cqListenerContainerConfigurers = Collections.emptyList();
private ContinuousQueryListenerContainerConfigurer compositeCqListenerContainerConfigurer =
(beanName, container) -> nullSafeList(cqListenerContainerConfigurers).forEach(configurer ->
(beanName, container) -> nullSafeList(this.cqListenerContainerConfigurers).forEach(configurer ->
configurer.configure(beanName, container));
protected final Log logger = LogFactory.getLog(getClass());
@@ -147,14 +147,6 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
applyContinuousQueryListenerContainerConfigurers(getCompositeContinuousQueryListenerContainerConfigurer());
}
/* (non-Javadoc) */
private QueryService validateQueryService(QueryService queryService) {
Assert.state(queryService != null, "QueryService was not properly initialized");
return queryService;
}
/**
* Applies the array of {@link ContinuousQueryListenerContainerConfigurer} objects to customize the configuration
* of this {@link ContinuousQueryListenerContainer}.
@@ -260,6 +252,14 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
return getQueryService();
}
/* (non-Javadoc) */
private QueryService validateQueryService(QueryService queryService) {
Assert.state(queryService != null, "QueryService is required");
return queryService;
}
/**
* Initialize the {@link Executor} used to process CQ events asynchronously.
*
@@ -301,7 +301,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
* Initializes all the {@link CqQuery Continuous Queries} defined by the {@link ContinuousQueryDefinition defintions}.
*/
private void initContinuousQueries() {
initContinuousQueries(this.continuousQueryDefinitions);
initContinuousQueries(getContinuousQueryDefinitions());
}
/* (non-Javadoc) */
@@ -418,13 +418,24 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
* Returns a reference to all the configured/registered {@link CqQuery Continuous Queries}.
*
* @return a reference to all the configured/registered {@link CqQuery Continuous Queries}.
* @see java.util.Queue
* @see org.apache.geode.cache.query.CqQuery
* @see java.util.Queue
*/
protected Queue<CqQuery> getContinuousQueries() {
return this.continuousQueries;
}
/**
* Returns a reference to all the configured {@link ContinuousQueryDefinition ContinuousQueryDefinitions}.
*
* @return a reference to all the configured {@link ContinuousQueryDefinition ContinuousQueryDefinitions}.
* @see org.springframework.data.gemfire.listener.ContinuousQueryDefinition
* @see java.util.Set
*/
protected Set<ContinuousQueryDefinition> getContinuousQueryDefinitions() {
return this.continuousQueryDefinitions;
}
/**
* Null-safe operation setting an array of {@link ContinuousQueryListenerContainerConfigurer} objects used to
* customize the configuration of this {@link ContinuousQueryListenerContainer}.
@@ -504,6 +515,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
* @return the phase value of this CQ listener container.
* @see org.springframework.context.Phased#getPhase()
*/
@Override
public int getPhase() {
return this.phase;
}
@@ -532,8 +544,8 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
* @param queries set of queries
*/
public void setQueryListeners(Set<ContinuousQueryDefinition> queries) {
this.continuousQueryDefinitions.clear();
this.continuousQueryDefinitions.addAll(nullSafeSet(queries));
getContinuousQueryDefinitions().clear();
getContinuousQueryDefinitions().addAll(nullSafeSet(queries));
}
/**
@@ -596,6 +608,10 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
}
}
public boolean addContinuousQueryDefinition(ContinuousQueryDefinition definition) {
return Optional.ofNullable(definition).map(it -> getContinuousQueryDefinitions().add(it)).orElse(false);
}
/* (non-Javadoc) */
CqQuery addContinuousQuery(ContinuousQueryDefinition definition) {
@@ -641,6 +657,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
public synchronized void start() {
if (!isRunning()) {
doStart();
this.running = true;
@@ -657,6 +674,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
/* (non-Javadoc) */
private void execute(CqQuery query) {
try {
query.execute();
}
@@ -686,6 +704,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
* @see #handleListenerError(Throwable)
*/
private void notify(ContinuousQueryListener listener, CqEvent event) {
try {
listener.onEvent(event);
}
@@ -708,8 +727,7 @@ public class ContinuousQueryListenerContainer implements BeanFactoryAware, BeanN
*/
private void handleListenerError(Throwable cause) {
getErrorHandler()
.filter(errorHandler -> {
getErrorHandler().filter(errorHandler -> {
boolean active = this.isActive();