INT-1471, more polishing, added auto-startup attribute to the schema for Recieving adapters

This commit is contained in:
Oleg Zhurakousky
2010-10-28 11:14:26 -04:00
committed by Chris Beams
parent 7733a27ea6
commit 5522af7a04
7 changed files with 115 additions and 30 deletions

View File

@@ -77,6 +77,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>

View File

@@ -41,19 +41,20 @@ public class TwitterReceivingMessageSourceParser extends AbstractPollingInboundC
String elementName = element.getLocalName().trim();
String className = null;
if ("inbound-update-channel-adapter".equals(elementName)) {
className = BASE_PACKAGE + ".inbound.TimelineUpdateMessageSource";
className = BASE_PACKAGE + ".inbound.TimelineUpdateReceivingMessageSource";
}
else if ("inbound-dm-channel-adapter".equals(elementName)) {
className = BASE_PACKAGE + ".inbound.DirectMessageMessageSource";
className = BASE_PACKAGE + ".inbound.DirectMessageReceivingMessageSource";
}
else if ("inbound-mention-channel-adapter".equals(elementName)) {
className = BASE_PACKAGE + ".inbound.MentionMessageSource";
className = BASE_PACKAGE + ".inbound.MentionReceivingMessageSource";
}
else {
parserContext.getReaderContext().error("element '" + elementName + "' is not supported by this parser.", element);
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
String name = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
return new RuntimeBeanReference(name);
}

View File

@@ -99,8 +99,6 @@ public abstract class AbstractTwitterMessageSource<T> extends AbstractEndpoint
protected void onInit() throws Exception{
super.onInit();
Assert.notNull(this.configuration, "'configuration' can't be null");
this.twitter = this.configuration.getTwitter();
Assert.notNull(this.twitter, "'twitter' instance can't be null");
if (this.metadataStore == null) {
// first try to look for a 'messageStore' in the context
BeanFactory beanFactory = this.getBeanFactory();
@@ -148,6 +146,8 @@ public abstract class AbstractTwitterMessageSource<T> extends AbstractEndpoint
@Override
protected void doStart(){
this.twitter = this.configuration.getTwitter();
Assert.notNull(this.twitter, "'twitter' instance can't be null");
historyWritingPostProcessor.setTrackableComponent(this);
RateLimitStatusTrigger trigger = new RateLimitStatusTrigger(this.twitter);
Runnable apiCallback = this.getApiCallback();

View File

@@ -1,20 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2010 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.
-->
<xsd:schema xmlns="http://www.springframework.org/schema/integration/twitter"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:beans="http://www.springframework.org/schema/beans"
@@ -29,7 +13,6 @@
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"/>
<xsd:element name="twitter-connection">
<xsd:annotation>
<xsd:documentation>
@@ -60,6 +43,7 @@
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
@@ -78,8 +62,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<!-- <xsd:attribute name="username" type="xsd:string" use="required"/>
<xsd:attribute name="password" type="xsd:string" use="required"/>-->
</xsd:complexType>
</xsd:element>
@@ -103,6 +85,7 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
@@ -112,8 +95,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<!--<xsd:attribute name="username" type="xsd:string" use="required"/>
<xsd:attribute name="password" type="xsd:string" use="required"/>-->
</xsd:complexType>
</xsd:element>
@@ -138,6 +119,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:twitter="http://www.springframework.org/schema/integration/twitter"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
<beans:bean id="tc" class="org.mockito.Mockito" factory-method="mock">
<beans:constructor-arg value="org.springframework.integration.twitter.oauth.OAuthConfiguration"/>
</beans:bean>
<channel id="inbound_mentions"/>
<twitter:inbound-mention-channel-adapter id="mentionAdapter"
twitter-connection="tc"
channel="inbound_mentions"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-mention-channel-adapter>
<twitter:inbound-dm-channel-adapter id="dmAdapter"
twitter-connection="tc"
channel="inbound_mentions"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-dm-channel-adapter>
<twitter:inbound-update-channel-adapter id="updateAdapter"
twitter-connection="tc"
channel="inbound_mentions"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-update-channel-adapter>
</beans:beans>

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2002-2010 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.twitter.config;
import static junit.framework.Assert.assertFalse;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.twitter.inbound.AbstractTwitterMessageSource;
/**
* @author Oleg Zhurakousky
*
*/
public class TestReceivingMessageSourceParserTests {
@Test
public void testRecievingAdapterConfigurationAutoStartup(){
ApplicationContext ac = new ClassPathXmlApplicationContext("TestReceivingMessageSourceParser-context.xml", this.getClass());
SourcePollingChannelAdapter spca = ac.getBean("mentionAdapter", SourcePollingChannelAdapter.class);
AbstractTwitterMessageSource<?> ms = (AbstractTwitterMessageSource<?>) TestUtils.getPropertyValue(spca, "source");
assertFalse(ms.isAutoStartup());
spca = ac.getBean("dmAdapter", SourcePollingChannelAdapter.class);
ms = (AbstractTwitterMessageSource<?>) TestUtils.getPropertyValue(spca, "source");
assertFalse(ms.isAutoStartup());
spca = ac.getBean("updateAdapter", SourcePollingChannelAdapter.class);
ms = (AbstractTwitterMessageSource<?>) TestUtils.getPropertyValue(spca, "source");
assertFalse(ms.isAutoStartup());
}
}

View File

@@ -38,10 +38,10 @@
</twitter:inbound-mention-channel-adapter>
<service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>
<!-- <twitter:inbound-dm-channel-adapter twitter-connection="tc" channel="inbound_dm">-->
<!-- <poller fixed-rate="5000" max-messages-per-poll="3"/>-->
<!-- </twitter:inbound-dm-channel-adapter>-->
<!-- <service-activator input-channel="inbound_dm" ref="twitterAnnouncer" method="dm"/>-->
<twitter:inbound-dm-channel-adapter twitter-connection="tc" channel="inbound_dm">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-dm-channel-adapter>
<service-activator input-channel="inbound_dm" ref="twitterAnnouncer" method="dm"/>
<twitter:inbound-update-channel-adapter id="twitterInbound" twitter-connection="tc" channel="inbound_updates">
<poller fixed-rate="5000" max-messages-per-poll="3"/>