use of org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy in project camel by apache.
the class GenericFileProcessStrategyFactory method createGenericFileProcessStrategy.
@SuppressWarnings("unchecked")
public static <T> GenericFileProcessStrategy<T> createGenericFileProcessStrategy(CamelContext context, Map<String, Object> params) {
// We assume a value is present only if its value not null for String and 'true' for boolean
Expression moveExpression = (Expression) params.get("move");
Expression moveFailedExpression = (Expression) params.get("moveFailed");
Expression preMoveExpression = (Expression) params.get("preMove");
boolean isNoop = params.get("noop") != null;
boolean isDelete = params.get("delete") != null;
boolean isMove = moveExpression != null || preMoveExpression != null || moveFailedExpression != null;
if (isDelete) {
GenericFileDeleteProcessStrategy<T> strategy = new GenericFileDeleteProcessStrategy<T>();
strategy.setExclusiveReadLockStrategy((GenericFileExclusiveReadLockStrategy<T>) getExclusiveReadLockStrategy(params));
if (preMoveExpression != null) {
GenericFileExpressionRenamer<T> renamer = new GenericFileExpressionRenamer<T>();
renamer.setExpression(preMoveExpression);
strategy.setBeginRenamer(renamer);
}
if (moveFailedExpression != null) {
GenericFileExpressionRenamer<T> renamer = new GenericFileExpressionRenamer<T>();
renamer.setExpression(moveFailedExpression);
strategy.setFailureRenamer(renamer);
}
return strategy;
} else if (isMove || isNoop) {
GenericFileRenameProcessStrategy<T> strategy = new GenericFileRenameProcessStrategy<T>();
strategy.setExclusiveReadLockStrategy((GenericFileExclusiveReadLockStrategy<T>) getExclusiveReadLockStrategy(params));
if (!isNoop && moveExpression != null) {
// move on commit is only possible if not noop
GenericFileExpressionRenamer<T> renamer = new GenericFileExpressionRenamer<T>();
renamer.setExpression(moveExpression);
strategy.setCommitRenamer(renamer);
}
// both move and noop supports pre move
if (moveFailedExpression != null) {
GenericFileExpressionRenamer<T> renamer = new GenericFileExpressionRenamer<T>();
renamer.setExpression(moveFailedExpression);
strategy.setFailureRenamer(renamer);
}
// both move and noop supports pre move
if (preMoveExpression != null) {
GenericFileExpressionRenamer<T> renamer = new GenericFileExpressionRenamer<T>();
renamer.setExpression(preMoveExpression);
strategy.setBeginRenamer(renamer);
}
return strategy;
} else {
// default strategy will do nothing
GenericFileNoOpProcessStrategy<T> strategy = new GenericFileNoOpProcessStrategy<T>();
strategy.setExclusiveReadLockStrategy((GenericFileExclusiveReadLockStrategy<T>) getExclusiveReadLockStrategy(params));
return strategy;
}
}
use of org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy in project camel by apache.
the class FileProcessStrategyFactory method getExclusiveReadLockStrategy.
@SuppressWarnings("unchecked")
private static GenericFileExclusiveReadLockStrategy<File> getExclusiveReadLockStrategy(Map<String, Object> params) {
GenericFileExclusiveReadLockStrategy<File> strategy = (GenericFileExclusiveReadLockStrategy<File>) params.get("exclusiveReadLockStrategy");
if (strategy != null) {
return strategy;
}
// no explicit strategy set then fallback to readLock option
String readLock = (String) params.get("readLock");
if (ObjectHelper.isNotEmpty(readLock)) {
if ("none".equals(readLock) || "false".equals(readLock)) {
return null;
} else if ("markerFile".equals(readLock)) {
strategy = new MarkerFileExclusiveReadLockStrategy();
} else if ("fileLock".equals(readLock)) {
strategy = new FileLockExclusiveReadLockStrategy();
} else if ("rename".equals(readLock)) {
strategy = new FileRenameExclusiveReadLockStrategy();
} else if ("changed".equals(readLock)) {
FileChangedExclusiveReadLockStrategy readLockStrategy = new FileChangedExclusiveReadLockStrategy();
Long minLength = (Long) params.get("readLockMinLength");
if (minLength != null) {
readLockStrategy.setMinLength(minLength);
}
Long minAge = (Long) params.get("readLockMinAge");
if (null != minAge) {
readLockStrategy.setMinAge(minAge);
}
strategy = readLockStrategy;
} else if ("idempotent".equals(readLock)) {
FileIdempotentRepositoryReadLockStrategy readLockStrategy = new FileIdempotentRepositoryReadLockStrategy();
Boolean readLockRemoveOnRollback = (Boolean) params.get("readLockRemoveOnRollback");
if (readLockRemoveOnRollback != null) {
readLockStrategy.setRemoveOnRollback(readLockRemoveOnRollback);
}
Boolean readLockRemoveOnCommit = (Boolean) params.get("readLockRemoveOnCommit");
if (readLockRemoveOnCommit != null) {
readLockStrategy.setRemoveOnCommit(readLockRemoveOnCommit);
}
IdempotentRepository repo = (IdempotentRepository) params.get("readLockIdempotentRepository");
if (repo != null) {
readLockStrategy.setIdempotentRepository(repo);
}
strategy = readLockStrategy;
} else if ("idempotent-changed".equals(readLock)) {
FileIdempotentChangedRepositoryReadLockStrategy readLockStrategy = new FileIdempotentChangedRepositoryReadLockStrategy();
Boolean readLockRemoveOnRollback = (Boolean) params.get("readLockRemoveOnRollback");
if (readLockRemoveOnRollback != null) {
readLockStrategy.setRemoveOnRollback(readLockRemoveOnRollback);
}
Boolean readLockRemoveOnCommit = (Boolean) params.get("readLockRemoveOnCommit");
if (readLockRemoveOnCommit != null) {
readLockStrategy.setRemoveOnCommit(readLockRemoveOnCommit);
}
IdempotentRepository repo = (IdempotentRepository) params.get("readLockIdempotentRepository");
if (repo != null) {
readLockStrategy.setIdempotentRepository(repo);
}
Long minLength = (Long) params.get("readLockMinLength");
if (minLength != null) {
readLockStrategy.setMinLength(minLength);
}
Long minAge = (Long) params.get("readLockMinAge");
if (null != minAge) {
readLockStrategy.setMinAge(minAge);
}
strategy = readLockStrategy;
} else if ("idempotent-rename".equals(readLock)) {
FileIdempotentRenameRepositoryReadLockStrategy readLockStrategy = new FileIdempotentRenameRepositoryReadLockStrategy();
Boolean readLockRemoveOnRollback = (Boolean) params.get("readLockRemoveOnRollback");
if (readLockRemoveOnRollback != null) {
readLockStrategy.setRemoveOnRollback(readLockRemoveOnRollback);
}
Boolean readLockRemoveOnCommit = (Boolean) params.get("readLockRemoveOnCommit");
if (readLockRemoveOnCommit != null) {
readLockStrategy.setRemoveOnCommit(readLockRemoveOnCommit);
}
IdempotentRepository repo = (IdempotentRepository) params.get("readLockIdempotentRepository");
if (repo != null) {
readLockStrategy.setIdempotentRepository(repo);
}
strategy = readLockStrategy;
}
if (strategy != null) {
Long timeout = (Long) params.get("readLockTimeout");
if (timeout != null) {
strategy.setTimeout(timeout);
}
Long checkInterval = (Long) params.get("readLockCheckInterval");
if (checkInterval != null) {
strategy.setCheckInterval(checkInterval);
}
LoggingLevel readLockLoggingLevel = (LoggingLevel) params.get("readLockLoggingLevel");
if (readLockLoggingLevel != null) {
strategy.setReadLockLoggingLevel(readLockLoggingLevel);
}
Boolean readLockMarkerFile = (Boolean) params.get("readLockMarkerFile");
if (readLockMarkerFile != null) {
strategy.setMarkerFiler(readLockMarkerFile);
}
Boolean readLockDeleteOrphanLockFiles = (Boolean) params.get("readLockDeleteOrphanLockFiles");
if (readLockDeleteOrphanLockFiles != null) {
strategy.setDeleteOrphanLockFiles(readLockDeleteOrphanLockFiles);
}
}
}
return strategy;
}
Aggregations