2
<bean id="inFileHandler"
    class="com.yahoo.FileProcessHandler" />

<bean id="executorService" class="java.util.concurrent.Executors" factory-method="newSingleThreadExecutor" destroy-method="shutdownNow" />

<int:channel id="inChannel" />

<int:channel id="outChannel">
    <int:queue capacity="5" />
</int:channel>

<bean id="sftpFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="${SFTP_HOST}"></property>
    <property name="port" value="${SFTPPORT}"></property>
    <property name="user" value="${SFTPUSERNAME}"></property>
    <property name="password" value="${SFTPPASSWORD}"></property>
</bean>

<sftp:inbound-channel-adapter id="ftpInBound" channel="inChannel"
    session-factory="sftpFactory" 
    delete-remote-files="true" remote-directory="/Files"
    local-directory="file:C:/Bhaji">
    <int:poller id="poller" fixed-rate="10000"/>
</sftp:inbound-channel-adapter>

<int:service-activator input-channel="inChannel"
    output-channel="nullChannel" ref="inFileHandler" method="handler" />

and the FileProcess handler is

 @Autowired
    private ExecutorService executorService;

    private static Logger log = LoggerFactory.getLogger(FileProcessHandler.class);

    public File handler(File input) {
        **//Doing some time taking process**
        return input;
}

here while doing the time taking process i don't want to poll the SFTP inbound-channel-adapter. after completion of time taken process the poller should start automatically.

Is there any way to do this ? is there any way to achieve it?

Baji Shaik
  • 1,022
  • 2
  • 10
  • 14

2 Answers2

0

What are using the executor service for - let the flow run on the poller thread and the next poll won't happen until the current poll completes.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Actual requirement is from sftp i have to copy mutiple files at a time and i have to process the files using spring-batch one by one.Can you please elaborate how can i run it in poller thread? – Baji Shaik May 20 '15 at 10:20
  • Hey will you explain how can we access the poller thread? would you guide me to run this. – Baji Shaik Jun 04 '15 at 15:23
  • What do you mean by "access" ? You can stop/start the adapter at will. You can restart it when your last task is complete - the framework can't do that for you. – Gary Russell Jun 04 '15 at 15:35
  • OK.can you please explain how can i stop the adapter when ever a file is received and how can i restart the adapter when the process on file was done? – Baji Shaik Jun 04 '15 at 15:58
  • Use a [control bus](http://docs.spring.io/spring-integration/reference/html/system-management-chapter.html#control-bus) and send `@ftpInBound.stop()` and `...start()`. – Gary Russell Jun 04 '15 at 17:27
0

Looks like it would be enough for you to use fixed-delay instead of fixed-rate on the <poller> and do the task in a TaskScheduler Thread. In this case you will have only one process at a time. And the next one will start only after the finish of previous.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118