On Tue, Dec 29, 2009 at 8:59 AM, Willem Jiang <willem.ji...@gmail.com> wrote: > If you are using file endpoint to pull the directory, it is hard to tell if > the uploading processor is over, > Can you take look at the camel polling consumer API[1] (Timer based polling > consumer example), in this way you can add you logic to check if the file > pulling is finished, and the sendTemplate will return when the uploading > work is over. > > [1]http://camel.apache.org/polling-consumer.html >
You can also use onCompletion or check the inflight registry if there are any current exchanges. http://camel.apache.org/oncompletion.html CamelContext.getInflightRegistry() Which has a counter for the number of exchanges in flight. When it reaches 0 the file should have been transferred. > Willem > > Hebert Hu wrote: >> >> I started the upload like this >> >> CamelContext context = new DefaultCamelContext(); >> RouteBuilder route = createRouteBuilder(); >> context.addRoutes(route); >> context.start(); >> >> I'm able to get the route service status by RouteDefinition definition = >> context.getRouteDefinitions().get(0); >> context.getRouteStatus(definition) >> >> But how can I tell whther the upload is finished? >> As I always get "Started" even the upload is finished. >> >> >> Hebert Hu wrote: >>> >>> Hi, >>> I've encountered a strange problem when using Camel Sftp component for >>> uploading. >>> >>> Here's my code >>> >>> protected RouteBuilder createRouteBuilder() throws Exception { >>> return new RouteBuilder() { >>> public void configure() throws Exception { >>> from("file:c:\\uploadfiles?noop=true").to(getFtpUrl()); >>> from(getFtpUrl()).to("mock:result"); >>> } >>> }; >>> } >>> >>> private String getFtpUrl(){ >>> return >>> >>> "sftp://usern...@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts"; >>> } >>> >>> The problem is: When I start my upload procedure, for the files in the >>> c:\uploadfiles (multiples files), some of them will create a .camellock >>> file while others not. As in the remote server, some of the files that >>> have a .camellock copy will be uploaded while others not. Noted that not >>> all the files that has .camellock copies will be uploaded. And an >>> exception is thrown >>> SEVERE: Cannot retrieve file: ftpload/a.txt >>> org.apache.camel.component.file.GenericFileOperationFailedException: >>> Cannot retrieve file: ftpload/a.txt >>> at >>> >>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326) >>> at >>> >>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312) >>> at >>> >>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183) >>> at >>> >>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120) >>> at >>> >>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93) >>> at >>> >>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99) >>> at >>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432) >>> at >>> >>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295) >>> at >>> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) >>> at >>> >>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80) >>> at >>> >>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157) >>> at >>> >>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181) >>> at >>> >>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665) >>> at >>> >>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690) >>> at java.lang.Thread.run(Thread.java:799) >>> When I run the upload procedure again, more .camellock files appeared, >>> more files been uploaded, and the exception is still thrown. >>> For example. 10 files in c:\uploadfiles, run the upload for the first >>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an >>> exception. Run for the second time, 2 more .camellock appeared, 1 more >>> file uploaded, and an exception again. >>> >>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0 >>> >>> Can any one shed some light on me? >>> >> > > -- Claus Ibsen Apache Camel Committer Author of Camel in Action: http://www.manning.com/ibsen/ Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus