use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class InboundChannelAdapterAnnotationPostProcessor method postProcess.
@Override
public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) {
String channelName = MessagingAnnotationUtils.resolveAttribute(annotations, AnnotationUtils.VALUE, String.class);
Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty.");
MessageSource<?> messageSource = null;
try {
messageSource = createMessageSource(bean, beanName, method);
} catch (NoSuchBeanDefinitionException e) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation.");
}
return null;
}
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setOutputChannelName(channelName);
adapter.setSource(messageSource);
configurePollingEndpoint(adapter, annotations);
return adapter;
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class MBeanExporterIntegrationTests method testSelfDestruction.
@Test
public void testSelfDestruction() throws Exception {
context = new GenericXmlApplicationContext(getClass(), "self-destruction-context.xml");
SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class);
adapter.start();
int n = 0;
while (adapter.isRunning()) {
n += 10;
if (n > 10000) {
fail("Adapter failed to stop");
}
Thread.sleep(10);
}
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQueryAndDelete.
/**
* In this test, a Jpa Polling Channel Adapter will use JpQL query
* to retrieve a list of records from the database. Additionally, the records
* will be deleted after the polling.
*
* @throws Exception
*/
@Test
@DirtiesContext
public void testWithJpaQueryAndDelete() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setJpaQuery("from Student s");
jpaExecutor.setDeleteAfterPoll(true);
jpaExecutor.setDeleteInBatch(true);
jpaExecutor.setFlush(true);
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
final Consumer consumer = new Consumer();
received.add(consumer.poll(10000));
Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull("Message is null.", message);
assertNotNull(message.getPayload());
Collection<?> students = message.getPayload();
assertTrue(students.size() == 3);
Long studentCount = waitForDeletes(students);
assertEquals(Long.valueOf(0), studentCount);
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQuery.
/**
* In this test, a Jpa Polling Channel Adapter will use JpQL query
* to retrieve a list of records from the database.
*
* @throws Exception
*/
@Test
public void testWithJpaQuery() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setJpaQuery("from Student");
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
final Consumer consumer = new Consumer();
received.add(consumer.poll(10000));
Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<?> primeNumbers = message.getPayload();
assertTrue(primeNumbers.size() == 3);
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQueryAndDeletePerRow.
/**
* In this test, a Jpa Polling Channel Adapter will use JpQL query
* to retrieve a list of records from the database. Additionaly, the records
* will be deleted after the polling.
*
* @throws Exception
*/
@Test
@DirtiesContext
public void testWithJpaQueryAndDeletePerRow() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(jpaOperations);
jpaExecutor.setJpaQuery("from Student s");
jpaExecutor.setDeleteAfterPoll(true);
jpaExecutor.setDeleteInBatch(false);
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
Thread.sleep(1000);
final Consumer consumer = new Consumer();
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
received.add(consumer.poll(10000));
final Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull("Message is null.", message);
assertNotNull(message.getPayload());
final Collection<?> students = message.getPayload();
assertTrue(students.size() == 3);
Long studentCount = waitForDeletes(students);
assertEquals(Long.valueOf(0), studentCount);
}
Aggregations