INT-2075 - Added namespace support for cq-inbound-channel-adapter. Also some general cleanup and additional tests

This commit is contained in:
David Turanski
2011-08-26 10:25:25 -04:00
parent 201b4abe57
commit a888d71f62
16 changed files with 411 additions and 107 deletions

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.gemfire.config.xml;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* @author David Turanski
* @since 2.1
*
*/
public class GemfireCqInboundChannelAdapterParser extends AbstractChannelAdapterParser {
private static final String ERROR_CHANNEL_ATTRIBUTE = "error-channel";
private static final String OUTPUT_CHANNEL_PROPERTY = "outputChannel";
private static final String QUERY_LISTENER_CONTAINER_ATTRIBUTE = "query-listener-container";
private static final String DURABLE_ATTRIBUTE = "durable";
private static final String QUERY_NAME_ATTRIBUTE = "query-name";
private static final String QUERY_ATTRIBUTE = "query";
private static final String PAYLOAD_EXPRESSION_PROPERTY = "payloadExpression";
private static final String EXPRESSION_ATTRIBUTE = "expression";
private static final String GEMFIRE_INBOUND_CONTINUOUS_QUERY_MESSAGE_PRODUCER = "org.springframework.integration.gemfire.inbound.ContinuousQueryMessageProducer";
private static final String SUPPORTED_EVENT_TYPES_PROPERTY = "supportedEventTypes";
private static final String QUERY_EVENTS_ATTRIBUTE = "query-events";
/* (non-Javadoc)
* @see org.springframework.integration.config.xml.AbstractChannelAdapterParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, java.lang.String)
*/
@Override
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
BeanDefinitionBuilder continuousQueryMesageProducer = BeanDefinitionBuilder.genericBeanDefinition(GEMFIRE_INBOUND_CONTINUOUS_QUERY_MESSAGE_PRODUCER);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, EXPRESSION_ATTRIBUTE,PAYLOAD_EXPRESSION_PROPERTY);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, QUERY_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY);
if (!StringUtils.hasText(QUERY_LISTENER_CONTAINER_ATTRIBUTE)){
parserContext.getReaderContext().error("'query-listener-container' attribute is required.",element);
}
if (!StringUtils.hasText(QUERY_ATTRIBUTE)){
parserContext.getReaderContext().error("'query' attribute is required.",element);
}
continuousQueryMesageProducer.addConstructorArgReference(element.getAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE));
continuousQueryMesageProducer.addConstructorArgValue(element.getAttribute(QUERY_ATTRIBUTE));
continuousQueryMesageProducer.addPropertyReference(OUTPUT_CHANNEL_PROPERTY, channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(continuousQueryMesageProducer, element, ERROR_CHANNEL_ATTRIBUTE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, QUERY_NAME_ATTRIBUTE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, DURABLE_ATTRIBUTE);
return continuousQueryMesageProducer.getBeanDefinition();
}
}

View File

@@ -16,7 +16,7 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa
/**
* @author David Turanski
*
* @since 2.1
*/
public class GemfireIntegrationNamespaceHandler extends AbstractIntegrationNamespaceHandler{
@@ -25,8 +25,8 @@ public class GemfireIntegrationNamespaceHandler extends AbstractIntegrationNames
*/
public void init() {
registerBeanDefinitionParser("inbound-channel-adapter", new GemfireInboundChannelAdapterParser());
registerBeanDefinitionParser("cq-inbound-channel-adapter", new GemfireCqInboundChannelAdapterParser());
registerBeanDefinitionParser("outbound-channel-adapter", new GemfireOutboundChannelAdapterParser());
}
}

View File

@@ -111,7 +111,7 @@ public class ContinuousQueryMessageProducer extends SpelMessageProducerSupport i
public void onEvent(CqEvent event) {
if (isEventSupported(event)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("processing cq event key [%s] event [%s]", event.getBaseOperation()
logger.debug(String.format("processing cq event key [%s] event [%s]", event.getQueryOperation()
.toString(), event.getKey()));
}
Message<?> cqEventMessage = MessageBuilder.withPayload(evaluationResult(event)).build();
@@ -124,7 +124,9 @@ public class ContinuousQueryMessageProducer extends SpelMessageProducerSupport i
* @return
*/
private boolean isEventSupported(CqEvent event) {
String eventName = event.getBaseOperation().toString()+"D";
String eventName = event.getQueryOperation().toString() +
(event.getQueryOperation().toString().endsWith("Y")? "ED" : "D");
CqEventType eventType = CqEventType.valueOf(eventName);
return supportedEventTypes.contains(eventType);
}

View File

@@ -6,14 +6,14 @@
targetNamespace="http://www.springframework.org/schema/integration/gemfire"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/schema/beans"
schemaLocation="http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/beans"
schemaLocation="http://www.springframework.org/schema/beans/spring-beans-3.1.xsd" />
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-2.1.xsd" />
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines the core configuration elements for Spring Integration Gemfire Support.
Defines the core configuration elements for Spring Integration GemFire Support.
]]></xsd:documentation>
</xsd:annotation>
@@ -21,88 +21,131 @@
<xsd:annotation>
<xsd:documentation>
Configures an inbound Channel Adapter backed by a
Gemfire CacheListener
GemFire CacheListener
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="InboundChannelAdapterType">
<xsd:attribute name="region" type="xsd:string" use="required">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="com.gemstone.gemfire.cache.Region" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-events" type="xsd:string"
use="optional" default="CREATED,UPDATED">
<xsd:annotation>
<xsd:documentation><![CDATA[
Enabled cache entry event types
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="value">
<tool:expected-type
type="org.springframework.integration.gemfire.inbound.EventType" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="cq-inbound-channel-adapter">
<xsd:annotation>
<xsd:documentation>
Configures an inbound Channel Adapter backed by a
Spring Gemfire QueryListener
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="id" type="xsd:string" use="optional" />
<xsd:attribute name="channel" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="error-channel" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="region" type="xsd:string" use="required">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="com.gemstone.gemfire.cache.Region" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="expression" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Expression to be evaluated to produce a value for the payload.
<xsd:complexContent>
<xsd:extension base="InboundChannelAdapterType">
<xsd:attribute name="query-listener-container" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
Reference to a QueryListenerContainer
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="value">
<tool:expected-type
type="org.springframework.data.gemfire.listener.QueryListenerContainer" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="query-events" type="xsd:string"
use="optional" default="CREATED,UPDATED">
<xsd:annotation>
<xsd:documentation><![CDATA[
Enabled continuous query event types
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="value">
<tool:expected-type
type="org.springframework.integration.gemfire.inbound.CqEventType" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="query" use="required" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The query string
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-events" type="xsd:string"
use="optional" default="CREATED,UPDATED">
<xsd:annotation>
<xsd:documentation><![CDATA[
Enabled cache event types
</xsd:attribute>
<xsd:attribute name="query-name" use="optional" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The query name
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="value">
<tool:expected-type
type="org.springframework.integration.gemfire.inbound.EventType" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:attribute>
<xsd:attribute name="durable" use="optional" type="xsd:boolean" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates if the query is a durable subscription
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="outbound-channel-adapter">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Configures an outbound Channel Adapter that writes Message payloads to a
Configures an outbound Channel Adapter that
writes Message payloads to a
File.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="cache-entries" type="beans:mapType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
A map of SpEL expressions used to create cache entries. If not provided, payload must be a Map
<xsd:element name="cache-entries" type="beans:mapType"
minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
A map of SpEL expressions used to create cache entries. If not
provided, payload must be a Map
</xsd:documentation>
</xsd:annotation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="optional" />
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
@@ -114,7 +157,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="region" type="xsd:string" use="required">
<xsd:annotation>
<xsd:appinfo>
@@ -124,7 +167,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -133,8 +176,42 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="InboundChannelAdapterType">
<xsd:attribute name="id" type="xsd:string" use="optional" />
<xsd:attribute name="channel" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="error-channel" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="expression" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Expression to be evaluated to produce a value for the payload.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:schema>