- Poll: which means that every period of time the program are checking if new content is available. For example FTP Source Adapter is an example because ftp server doesn't throw an interruption when another user upload a file.
- Driven-Event: which means that an asynchronous event is thrown and can be captured. Our IM Adapter is an example.
- AbstractSourceAdapter: A base class providing common behavior for source adapters. It has some methods for sending messages to a channel, set message mappers, ...
- PollingSourceAdapter: A base class for polling if new message is available to be sent. It has some methods like period between polls, initial delay, ...
IMSourceAdapter extends AbstractSourceAdapterimplements InitializingBean
final XMPPConnection connection = new XMPPConnection(this.server); (1)try {connection.connect();connection.login(this.user, this.password);} catch (final XMPPException e) {throw new MessageHandlingException("Error starting", e);}
final PacketFilter packetFilter = new MessageTypeFilter(Message.Type.chat);connection.createPacketCollector(packetFilter); (2)
final PacketListener packetListener = new PacketListener() { (3)
@Overridepublic void processPacket(Packet arg0) {String msn = ((Message) arg0).getBody(); (4)SimpleIMMessage simpleIMMessage = new SimpleIMMessage();simpleIMMessage.setText(msn); (5)IMSourceAdapter.this.sendToChannel(simpleIMMessage); (6)}
};
connection.addPacketListener(packetListener, packetFilter); (7)
<?xml version="1.0" encoding="UTF-8"?><
beans:beans xmlns="http://www.springframework.org/schema/integration"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:beans="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/integrationhttp://www.springframework.org/schema/integration/spring-integration-1.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<message-bus /><annotation-driven />
<channel id="inMessage"></channel><beans:bean id="sourceIM" class="test.spring.integration.im.IMSourceAdapter"><beans:property name="user" value="logger"></beans:property><beans:property name="password" value="logger"></beans:property><beans:property name="server" value="localhost"></beans:property><beans:property name="channel" ref="inMessage"></beans:property><beans:property name="messageMapper"><beans:bean class="test.spring.integration.im.TextIMMessageMapper"></beans:bean></beans:property></beans:bean>
<file-target directory="/temp" channel="inMessage"/></beans:beans>