文件处理策略检查数据库是否在处理文件XYZ之前执行了特定的预处理条件/步骤。
文件XYZ来自驼峰扫描的根目录的不同子目录。
如果其中一个文件不合格,则驼峰应移至下一个。不确定我应该使用哪个标志,以便它不会再次检查当前文件而不是移动到下一个文件。
我的文件处理策略:
public class MigrFileProcessStrategy<T> extends GenericFileProcessStrategySupport<T> {
private static final Logger log = LoggerFactory.getLogger(MigrFileProcessStrategy.class);
@Autowired
DefaultMigrationProcessor defaultMigrationProcessor;
@Override
public boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
//check if HIST table has entry for this filename, if yes all preprocessing done, file is ready.
boolean readyForProcessing = false;
String fileAbsPath = file.getAbsoluteFilePath();
File inMigrFile = new File(fileAbsPath);
readyForProcessing = defaultMigrationProcessor.isFileReadyForProcessing(inMigrFile);
if (!readyForProcessing) {
String msg = String.format("\n####Process?:%b File:%s", readyForProcessing, fileAbsPath);
log.info(msg);
}
return readyForProcessing;
}
}
我的配置:
<bean id="migrFilesToCopy" class="org.apache.camel.component.file.MigrFileFilter">
<!-- Filter for migr files that need to be copied-->
<property name="caseSensitive" value="true" />
<property name="excludes" value="**/**/*.migratedLnk, **/_inProgress/**, **/_done/**, **/_failed/**" />
</bean>
<endpoint id="endpoint_migrFilesToCopy"
uri="file://#{migrationProcessor.migrRootDir.toFile()}?processStrategy=#migrFileProcessStrategy&directoryMustExist=true&idempotent=true&recursive=true&delete=true&initialDelay=1000&delay=5000&readLock=changed&readLockTimeout=100000&readLockCheckInterval=1000&moveFailed=_failed&maxMessagesPerPoll=10&filter=#migrFilesToCopy" />
<route id="chMigrate" autoStartup="true">
<from uri="ref:endpoint_migrFilesToCopy" />
<pipeline>
<log message="Procesing file: ${header.CamelFileName}" />
<!--threads executorServiceRef="migrThreadPool" -->
<bean ref="migrationProcessor" method="createMetadata" /><!-- MetaDataVo -->
<bean ref="migrationProcessor" method="createCopyObj" /><!-- CacheCopyObj -->
<bean ref="migrationProcessor" method="migrate" />
<!--/threads -->
</pipeline>
</route>
通过扩展ant过滤器解决:
公共类MigrFileFilter扩展AntPathMatcherGenericFileFilter实现GenericFileFilter { private static final Logger log = LoggerFactory.getLogger(MigrFileFilter.class); @Autowired DefaultMigrationProcessor defaultMigrationProcessor; public MigrFileFilter(){ 超(); }
@Override
public boolean accept(GenericFile<T> file) {
String fileAbsPath = file.getAbsoluteFilePath();
File inMigrFile = new File(fileAbsPath);
boolean readyForProcessing = false;
if (Files.isDirectory(inMigrFile.toPath())) {
readyForProcessing = true; //To recursivly process directories.
} else {
boolean validFilePatten = super.accept(file);
boolean preprocessDataExist = false;
if (validFilePatten) {
preprocessDataExist = defaultMigrationProcessor.isFileReadyForProcessing(inMigrFile);
}
readyForProcessing = (validFilePatten && preprocessDataExist);
}
return readyForProcessing;
}
答案 0 :(得分:1)
使用过滤器过滤掉不需要的文件
您可以实现自定义实现,如果要包含该文件,则只返回true | false。
请参阅过滤使用org.apache.camel.component.file.GenericFileFilter