You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "martin.vich" <me...@seznam.cz> on 2015/05/20 17:20:07 UTC

repeated reading from read-only directory (noop=true + idempotent=false)

Hi,

I am using polling consumer pattern to read all files in defined directory : 

public List<GenericFile> scanFolder(String folder) {
List<GenericFile> result = new ArrayList<GenericFile>();
String endpointUrl  = "file:////" + folder +
"?sendEmptyMessageWhenIdle=true&noop=true"
PollingConsumer pConsumer =
camelContext.getEndpoint(endpointUrl).createPollingConsumer();

pConsumer.start();

GenericFile<File> gFile;

 do {
     Exchange ex = pConsumer.receive(SCAN_TIMEOUT);
     gFile = (GenericFile<File>) ex.getIn().getBody();
     if(gFile != null) {
         result.add(gFile);
     }
  } while(gFile != null); //empty message is sent when endpoint is idle

 pConsumer.stop();

}

This works fine but as I am calling this method repeatedly Camel caches all
files in fileRepository (noop=true enforces idempotent=true) and result is
empty. I am using noop=true because this needs to work with read-only
filesystem. Is there a better way how to create 'folder scanner' using
polling consumer pattern which will read full folder content eachtime ?




--
View this message in context: http://camel.465427.n5.nabble.com/repeated-reading-from-read-only-directory-noop-true-idempotent-false-tp5767338.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: repeated reading from read-only directory (noop=true + idempotent=false)

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Probably better to just use the java file api to get a list of files

Something in the order of
String[] names = new File(dir).listNames();



On Wed, May 20, 2015 at 5:20 PM, martin.vich <me...@seznam.cz> wrote:
> Hi,
>
> I am using polling consumer pattern to read all files in defined directory :
>
> public List<GenericFile> scanFolder(String folder) {
> List<GenericFile> result = new ArrayList<GenericFile>();
> String endpointUrl  = "file:////" + folder +
> "?sendEmptyMessageWhenIdle=true&noop=true"
> PollingConsumer pConsumer =
> camelContext.getEndpoint(endpointUrl).createPollingConsumer();
>
> pConsumer.start();
>
> GenericFile<File> gFile;
>
>  do {
>      Exchange ex = pConsumer.receive(SCAN_TIMEOUT);
>      gFile = (GenericFile<File>) ex.getIn().getBody();
>      if(gFile != null) {
>          result.add(gFile);
>      }
>   } while(gFile != null); //empty message is sent when endpoint is idle
>
>  pConsumer.stop();
>
> }
>
> This works fine but as I am calling this method repeatedly Camel caches all
> files in fileRepository (noop=true enforces idempotent=true) and result is
> empty. I am using noop=true because this needs to work with read-only
> filesystem. Is there a better way how to create 'folder scanner' using
> polling consumer pattern which will read full folder content eachtime ?
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/repeated-reading-from-read-only-directory-noop-true-idempotent-false-tp5767338.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/