(S)FTP Lambdas

AMQP Lambdas

Event Lambdas

Feed/File Lambdas

Gemfile/Groovy Lambdas

* Ensure that JavaDocs are checked via `	check.dependsOn javadoc`
* Add `@return` tag to the `MessageBuilder.readOnlyHeaders()`
This commit is contained in:
Gary Russell
2016-09-22 12:32:47 -04:00
committed by Artem Bilan
parent 3402a86fb5
commit e5ae7d886d
48 changed files with 569 additions and 1148 deletions

View File

@@ -42,7 +42,6 @@ import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.remote.AbstractFileInfo;
import org.springframework.integration.file.remote.MessageSessionCallback;
import org.springframework.integration.file.remote.RemoteFileTemplate;
import org.springframework.integration.file.remote.SessionCallback;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.file.support.FileExistsMode;
@@ -520,15 +519,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
return doMput(requestMessage);
}
}
return this.remoteFileTemplate.execute(new SessionCallback<F, Object>() {
@Override
public Object doInSession(Session<F> session) throws IOException {
return AbstractRemoteFileOutboundGateway.this.messageSessionCallback.doInSession(session,
requestMessage);
}
});
return this.remoteFileTemplate.execute(session ->
AbstractRemoteFileOutboundGateway.this.messageSessionCallback.doInSession(session, requestMessage));
}
private Object doLs(Message<?> requestMessage) {
@@ -537,13 +529,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
dir += this.remoteFileTemplate.getRemoteFileSeparator();
}
final String fullDir = dir;
List<?> payload = this.remoteFileTemplate.execute(new SessionCallback<F, List<?>>() {
@Override
public List<?> doInSession(Session<F> session) throws IOException {
return AbstractRemoteFileOutboundGateway.this.ls(session, fullDir);
}
});
List<?> payload = this.remoteFileTemplate.execute(session ->
AbstractRemoteFileOutboundGateway.this.ls(session, fullDir));
return this.getMessageBuilderFactory().withPayload(payload)
.setHeader(FileHeaders.REMOTE_DIRECTORY, dir)
.build();
@@ -567,14 +554,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
}
}
else {
payload = this.remoteFileTemplate.execute(new SessionCallback<F, File>() {
@Override
public File doInSession(Session<F> session) throws IOException {
return get(requestMessage, session, remoteDir, remoteFilePath, remoteFilename, true);
}
});
payload = this.remoteFileTemplate.execute(session1 ->
get(requestMessage, session1, remoteDir, remoteFilePath, remoteFilename, true));
}
return getMessageBuilderFactory().withPayload(payload)
.setHeader(FileHeaders.REMOTE_DIRECTORY, remoteDir)
@@ -588,13 +569,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
final String remoteFilePath = this.fileNameProcessor.processMessage(requestMessage);
final String remoteFilename = getRemoteFilename(remoteFilePath);
final String remoteDir = getRemoteDirectory(remoteFilePath, remoteFilename);
List<File> payload = this.remoteFileTemplate.execute(new SessionCallback<F, List<File>>() {
@Override
public List<File> doInSession(Session<F> session) throws IOException {
return mGet(requestMessage, session, remoteDir, remoteFilename);
}
});
List<File> payload = this.remoteFileTemplate.execute(session ->
mGet(requestMessage, session, remoteDir, remoteFilename));
return this.getMessageBuilderFactory().withPayload(payload)
.setHeader(FileHeaders.REMOTE_DIRECTORY, remoteDir)
.setHeader(FileHeaders.REMOTE_FILE, remoteFilename)

View File

@@ -40,7 +40,6 @@ import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.filters.ReversibleFileListFilter;
import org.springframework.integration.file.remote.RemoteFileTemplate;
import org.springframework.integration.file.remote.SessionCallback;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.messaging.MessagingException;
@@ -241,52 +240,40 @@ public abstract class AbstractInboundFileSynchronizer<F>
}
final String remoteDirectory = this.remoteDirectoryExpression.getValue(this.evaluationContext, String.class);
try {
int transferred = this.remoteFileTemplate.execute(new SessionCallback<F, Integer>() {
@Override
public Integer doInSession(Session<F> session) throws IOException {
F[] files = session.list(remoteDirectory);
if (!ObjectUtils.isEmpty(files)) {
List<F> filteredFiles = filterFiles(files);
if (maxFetchSize >= 0 && filteredFiles.size() > maxFetchSize) {
rollbackFromFileToListEnd(filteredFiles, filteredFiles.get(maxFetchSize));
List<F> newList = new ArrayList<>(maxFetchSize);
for (int i = 0; i < maxFetchSize; i++) {
newList.add(filteredFiles.get(i));
}
filteredFiles = newList;
int transferred = this.remoteFileTemplate.execute(session -> {
F[] files = session.list(remoteDirectory);
if (!ObjectUtils.isEmpty(files)) {
List<F> filteredFiles = filterFiles(files);
if (maxFetchSize >= 0 && filteredFiles.size() > maxFetchSize) {
rollbackFromFileToListEnd(filteredFiles, filteredFiles.get(maxFetchSize));
List<F> newList = new ArrayList<>(maxFetchSize);
for (int i = 0; i < maxFetchSize; i++) {
newList.add(filteredFiles.get(i));
}
for (F file : filteredFiles) {
try {
if (file != null) {
copyFileToLocalDirectory(
remoteDirectory, file, localDirectory,
session);
}
}
catch (RuntimeException e) {
rollbackFromFileToListEnd(filteredFiles, file);
throw e;
}
catch (IOException e) {
rollbackFromFileToListEnd(filteredFiles, file);
throw e;
filteredFiles = newList;
}
for (F file : filteredFiles) {
try {
if (file != null) {
copyFileToLocalDirectory(
remoteDirectory, file, localDirectory,
session);
}
}
return filteredFiles.size();
}
else {
return 0;
catch (RuntimeException e1) {
rollbackFromFileToListEnd(filteredFiles, file);
throw e1;
}
catch (IOException e2) {
rollbackFromFileToListEnd(filteredFiles, file);
throw e2;
}
}
return filteredFiles.size();
}
public void rollbackFromFileToListEnd(List<F> filteredFiles, F file) {
if (AbstractInboundFileSynchronizer.this.filter instanceof ReversibleFileListFilter) {
((ReversibleFileListFilter<F>) AbstractInboundFileSynchronizer.this.filter)
.rollback(file, filteredFiles);
}
else {
return 0;
}
});
if (this.logger.isDebugEnabled()) {
this.logger.debug(transferred + " files transferred");
@@ -297,6 +284,13 @@ public abstract class AbstractInboundFileSynchronizer<F>
}
}
protected void rollbackFromFileToListEnd(List<F> filteredFiles, F file) {
if (this.filter instanceof ReversibleFileListFilter) {
((ReversibleFileListFilter<F>) this.filter)
.rollback(file, filteredFiles);
}
}
protected void copyFileToLocalDirectory(String remoteDirectoryPath, F remoteFile, File localDirectory,
Session<F> session) throws IOException {
String remoteFileName = this.getFilename(remoteFile);

View File

@@ -84,13 +84,7 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
super.doStart();
destroyProcess();
this.command = "tail " + this.options + " " + this.getFile().getAbsolutePath();
this.getTaskExecutor().execute(new Runnable() {
@Override
public void run() {
runExec();
}
});
this.getTaskExecutor().execute(() -> runExec());
}
@Override
@@ -145,48 +139,39 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
* Runs a thread that waits for the Process result.
*/
private void startProcessMonitor() {
this.getTaskExecutor().execute(new Runnable() {
this.getTaskExecutor().execute(() -> {
Process process = OSDelegatingFileTailingMessageProducer.this.process;
if (process == null) {
if (logger.isDebugEnabled()) {
logger.debug("Process destroyed before starting process monitor");
}
return;
}
@Override
public void run() {
Process process = OSDelegatingFileTailingMessageProducer.this.process;
if (process == null) {
if (logger.isDebugEnabled()) {
logger.debug("Process destroyed before starting process monitor");
}
return;
int result = Integer.MIN_VALUE;
try {
if (logger.isDebugEnabled()) {
logger.debug("Monitoring process " + process);
}
int result = Integer.MIN_VALUE;
try {
if (logger.isDebugEnabled()) {
logger.debug("Monitoring process " + process);
}
result = process.waitFor();
if (logger.isInfoEnabled()) {
logger.info("tail process terminated with value " + result);
}
result = process.waitFor();
if (logger.isInfoEnabled()) {
logger.info("tail process terminated with value " + result);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Interrupted - stopping adapter", e);
stop();
}
finally {
destroyProcess();
}
if (isRunning()) {
if (logger.isInfoEnabled()) {
logger.info("Restarting tail process in " + getMissingFileDelay() + " milliseconds");
}
getRequiredTaskScheduler().schedule(new Runnable() {
@Override
public void run() {
runExec();
}
}, new Date(System.currentTimeMillis() + getMissingFileDelay()));
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Interrupted - stopping adapter", e);
stop();
}
finally {
destroyProcess();
}
if (isRunning()) {
if (logger.isInfoEnabled()) {
logger.info("Restarting tail process in " + getMissingFileDelay() + " milliseconds");
}
getRequiredTaskScheduler().schedule((Runnable) () -> runExec(),
new Date(System.currentTimeMillis() + getMissingFileDelay()));
}
});
}
@@ -204,35 +189,31 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
return;
}
final BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
this.getTaskExecutor().execute(new Runnable() {
@Override
public void run() {
String statusMessage;
this.getTaskExecutor().execute(() -> {
String statusMessage;
if (logger.isDebugEnabled()) {
logger.debug("Reading stderr");
}
try {
while ((statusMessage = errorReader.readLine()) != null) {
publish(statusMessage);
if (logger.isTraceEnabled()) {
logger.trace(statusMessage);
}
}
}
catch (IOException e1) {
if (logger.isDebugEnabled()) {
logger.debug("Reading stderr");
logger.debug("Exception on tail error reader", e1);
}
}
finally {
try {
while ((statusMessage = errorReader.readLine()) != null) {
publish(statusMessage);
if (logger.isTraceEnabled()) {
logger.trace(statusMessage);
}
}
errorReader.close();
}
catch (IOException e) {
catch (IOException e2) {
if (logger.isDebugEnabled()) {
logger.debug("Exception on tail error reader", e);
}
}
finally {
try {
errorReader.close();
}
catch (IOException e) {
if (logger.isDebugEnabled()) {
logger.debug("Exception while closing stderr", e);
}
logger.debug("Exception while closing stderr", e2);
}
}
}