use of org.springframework.integration.metadata.SimpleMetadataStore in project spring-integration by spring-projects.
the class FeedEntryMessageSource method onInit.
@Override
protected void onInit() throws Exception {
if (this.metadataStore == null) {
// first try to look for a 'messageStore' in the context
BeanFactory beanFactory = this.getBeanFactory();
if (beanFactory != null) {
this.metadataStore = IntegrationContextUtils.getMetadataStore(beanFactory);
}
// if no 'messageStore' in context, fall back to in-memory Map-based default
if (this.metadataStore == null) {
this.metadataStore = new SimpleMetadataStore();
}
}
String lastTimeValue = this.metadataStore.get(this.metadataKey);
if (StringUtils.hasText(lastTimeValue)) {
this.lastTime = Long.parseLong(lastTimeValue);
}
this.initialized = true;
}
use of org.springframework.integration.metadata.SimpleMetadataStore in project spring-integration by spring-projects.
the class IdempotentReceiverTests method testIdempotentReceiverInterceptor.
@Test
public void testIdempotentReceiverInterceptor() {
ConcurrentMetadataStore store = new SimpleMetadataStore();
ExpressionEvaluatingMessageProcessor<String> idempotentKeyStrategy = new ExpressionEvaluatingMessageProcessor<>(new SpelExpressionParser().parseExpression("payload"));
BeanFactory beanFactory = Mockito.mock(BeanFactory.class);
idempotentKeyStrategy.setBeanFactory(beanFactory);
IdempotentReceiverInterceptor idempotentReceiverInterceptor = new IdempotentReceiverInterceptor(new MetadataStoreSelector(idempotentKeyStrategy, store));
idempotentReceiverInterceptor.setThrowExceptionOnRejection(true);
AtomicReference<Message<?>> handled = new AtomicReference<>();
MessageHandler idempotentReceiver = handled::set;
ProxyFactory proxyFactory = new ProxyFactory(idempotentReceiver);
proxyFactory.addAdvice(idempotentReceiverInterceptor);
idempotentReceiver = (MessageHandler) proxyFactory.getProxy();
idempotentReceiver.handleMessage(new GenericMessage<>("foo"));
assertEquals(1, TestUtils.getPropertyValue(store, "metadata", Map.class).size());
assertNotNull(store.get("foo"));
try {
idempotentReceiver.handleMessage(new GenericMessage<>("foo"));
fail("MessageRejectedException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessageRejectedException.class));
}
idempotentReceiverInterceptor.setThrowExceptionOnRejection(false);
idempotentReceiver.handleMessage(new GenericMessage<>("foo"));
assertTrue(handled.get().getHeaders().get(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, Boolean.class));
assertEquals(1, TestUtils.getPropertyValue(store, "metadata", Map.class).size());
}
use of org.springframework.integration.metadata.SimpleMetadataStore in project spring-integration by spring-projects.
the class PersistentAcceptOnceFileListFilterTests method testRollback.
@Override
@Test
public void testRollback() {
AbstractPersistentAcceptOnceFileListFilter<String> filter = new AbstractPersistentAcceptOnceFileListFilter<String>(new SimpleMetadataStore(), "rollback:") {
@Override
protected long modified(String file) {
return 0;
}
@Override
protected String fileName(String file) {
return file;
}
};
doTestRollback(filter);
}
use of org.springframework.integration.metadata.SimpleMetadataStore in project spring-integration by spring-projects.
the class AbstractInboundFileSynchronizingMessageSource method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notNull(this.localDirectory, "localDirectory must not be null");
try {
if (!this.localDirectory.exists()) {
if (this.autoCreateLocalDirectory) {
if (logger.isDebugEnabled()) {
logger.debug("The '" + this.localDirectory + "' directory doesn't exist; Will create.");
}
this.localDirectory.mkdirs();
} else {
throw new FileNotFoundException(this.localDirectory.getName());
}
}
this.fileSource.setDirectory(this.localDirectory);
if (this.localFileListFilter == null) {
this.localFileListFilter = new FileSystemPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), getComponentName());
}
FileListFilter<File> filter = buildFilter();
if (this.scannerExplicitlySet) {
Assert.state(!this.fileSource.isUseWatchService(), "'useWatchService' and 'scanner' are mutually exclusive.");
this.fileSource.getScanner().setFilter(filter);
} else if (!this.fileSource.isUseWatchService()) {
DirectoryScanner directoryScanner = new DefaultDirectoryScanner();
directoryScanner.setFilter(filter);
this.fileSource.setScanner(directoryScanner);
} else {
this.fileSource.setFilter(filter);
}
if (this.getBeanFactory() != null) {
this.fileSource.setBeanFactory(this.getBeanFactory());
}
this.fileSource.afterPropertiesSet();
this.synchronizer.afterPropertiesSet();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new BeanInitializationException("Failure during initialization of MessageSource for: " + this.getClass(), e);
}
}
use of org.springframework.integration.metadata.SimpleMetadataStore in project spring-integration by spring-projects.
the class FtpPersistentAcceptOnceFileListFilterTests method testRollback.
@Test
public void testRollback() throws Exception {
FtpPersistentAcceptOnceFileListFilter filter = new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "rollback:");
FTPFile ftpFile1 = new FTPFile();
ftpFile1.setName("foo");
ftpFile1.setTimestamp(Calendar.getInstance());
FTPFile ftpFile2 = new FTPFile();
ftpFile2.setName("bar");
ftpFile2.setTimestamp(Calendar.getInstance());
FTPFile ftpFile3 = new FTPFile();
ftpFile3.setName("baz");
ftpFile3.setTimestamp(Calendar.getInstance());
FTPFile[] files = new FTPFile[] { ftpFile1, ftpFile2, ftpFile3 };
List<FTPFile> passed = filter.filterFiles(files);
assertTrue(Arrays.equals(files, passed.toArray()));
List<FTPFile> now = filter.filterFiles(files);
assertEquals(0, now.size());
filter.rollback(passed.get(1), passed);
now = filter.filterFiles(files);
assertEquals(2, now.size());
assertEquals("bar", now.get(0).getName());
assertEquals("baz", now.get(1).getName());
now = filter.filterFiles(files);
assertEquals(0, now.size());
filter.close();
}
Aggregations