You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jean Francois LE BESCONT <jf...@gmail.com> on 2013/05/30 10:24:05 UTC

Camel File Discard empty file

Hi,

I undig an old point (
http://camel.465427.n5.nabble.com/Camel-File-Discard-empty-file-td472234.html
)

My camel application wait file send from a tierce application ( which is
generate from a file:stream by an other application) and has to process it
and delete it after.

The file can be empty or big (more than 1Go). The big size of the file
required that the from wait for the end of the write before to process it
and I have to manage in the same time empty file.

I have started with a :

from("file://C:/Temp/camel2/in/?filter=#lockFilter&delay=2000&delete=true")
.log("start process file => ${file:name}")
.to("file://C:/Temp/camel2/out/?fileName=out.csv")
.log("end process file => ${file:name}")
.end();

With a lockFilter :

public class LockFilter<T> implements GenericFileFilter<T> {

@Override
public boolean accept(GenericFile<T> genericFile) {

File currentFile = (File) genericFile.getFile();

// try to rename the current file
if (currentFile.renameTo(currentFile)) {
return true;
} else {
return false;
}
}
}

I am a little suprised that camel doesn't manage it " natively " , is there
a other solution ?

Thanks !

Jeff

Re: Camel File Discard empty file

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

Read the docs please.
http://camel.apache.org/file2

See the readLockMinLength option

On Thu, May 30, 2013 at 10:10 AM, Jean Francois LE BESCONT
<jf...@gmail.com> wrote:
> I have play with readLock but :
>
> *changed : (with "**?readLock=changed&readLockTimeout=20000&delete=true") :
> doesn't detect empty file.*
> *
> *
> *fileLock : (with "?readLock=fileLock&delete=true" ) generate an exception
> on the producer of the file ( in my case an other application)
> *
> *
> *
> *
> 2013-05-30 12:06:33 - [0 - file://C:/Temp/camel/rep1/] route1
>           INFO  start process file => file.csv
> Exception in thread "main" java.io.IOException: The process cannot access
> the file because another process has locked a portion of the file
> at java.io.FileOutputStream.writeBytes(Native Method)
> at java.io.FileOutputStream.write(FileOutputStream.java:305)
> at com.mycompany.camel.spring.bacasable.Start.main(Start.java:19)
> *
> [...]
>
> rename : (with "?readLock=rename&delete=true" ) generate an exception on
> the client :
>
> org.apache.camel.component.file.GenericFileOperationFailedException: Error
> renaming file from C:\Temp\camel\rep1\file.csv to
> C:\Temp\camel\rep1\file.csv.camelExclusiveReadLock
> at
> org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:72)[camel-core-2.11.0.jar:2.11.0]
> [...]
>
> That is with I have developed my own filter as you suggest.
>
>
> 2013/5/30 Claus Ibsen <cl...@gmail.com>
>
>> Hi
>>
>> It does, see the readLock option
>> http://camel.apache.org/file2
>>
>> On Thu, May 30, 2013 at 10:24 AM, Jean Francois LE BESCONT
>> <jf...@gmail.com> wrote:
>> > Hi,
>> >
>> > I undig an old point (
>> >
>> http://camel.465427.n5.nabble.com/Camel-File-Discard-empty-file-td472234.html
>> > )
>> >
>> > My camel application wait file send from a tierce application ( which is
>> > generate from a file:stream by an other application) and has to process
>> it
>> > and delete it after.
>> >
>> > The file can be empty or big (more than 1Go). The big size of the file
>> > required that the from wait for the end of the write before to process it
>> > and I have to manage in the same time empty file.
>> >
>> > I have started with a :
>> >
>> >
>> from("file://C:/Temp/camel2/in/?filter=#lockFilter&delay=2000&delete=true")
>> > .log("start process file => ${file:name}")
>> > .to("file://C:/Temp/camel2/out/?fileName=out.csv")
>> > .log("end process file => ${file:name}")
>> > .end();
>> >
>> > With a lockFilter :
>> >
>> > public class LockFilter<T> implements GenericFileFilter<T> {
>> >
>> > @Override
>> > public boolean accept(GenericFile<T> genericFile) {
>> >
>> > File currentFile = (File) genericFile.getFile();
>> >
>> > // try to rename the current file
>> > if (currentFile.renameTo(currentFile)) {
>> > return true;
>> > } else {
>> > return false;
>> > }
>> > }
>> > }
>> >
>> > I am a little suprised that camel doesn't manage it " natively " , is
>> there
>> > a other solution ?
>> >
>> > Thanks !
>> >
>> > Jeff
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> www.camelone.org: The open source integration conference.
>>
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: cibsen@redhat.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Camel File Discard empty file

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
Hi,

Do you think that we could enhance camel to manage it correctly ?

Jeff


2013/5/30 Jean Francois LE BESCONT <jf...@gmail.com>

> I have play with readLock but :
>
> *changed : (with "**?readLock=changed&readLockTimeout=20000&delete=true")
> : doesn't detect empty file.*
> *
> *
> *fileLock : (with "?readLock=fileLock&delete=true" ) generate an
> exception on the producer of the file ( in my case an other application)
> *
> *
> *
> *
> 2013-05-30 12:06:33 - [0 - file://C:/Temp/camel/rep1/] route1
>             INFO  start process file => file.csv
> Exception in thread "main" java.io.IOException: The process cannot access
> the file because another process has locked a portion of the file
> at java.io.FileOutputStream.writeBytes(Native Method)
>  at java.io.FileOutputStream.write(FileOutputStream.java:305)
> at com.mycompany.camel.spring.bacasable.Start.main(Start.java:19)
> *
> [...]
>
> rename : (with "?readLock=rename&delete=true" ) generate an exception on
> the client :
>
> org.apache.camel.component.file.GenericFileOperationFailedException: Error
> renaming file from C:\Temp\camel\rep1\file.csv to
> C:\Temp\camel\rep1\file.csv.camelExclusiveReadLock
>  at
> org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:72)[camel-core-2.11.0.jar:2.11.0]
> [...]
>
> That is with I have developed my own filter as you suggest.
>
>
> 2013/5/30 Claus Ibsen <cl...@gmail.com>
>
>> Hi
>>
>> It does, see the readLock option
>> http://camel.apache.org/file2
>>
>> On Thu, May 30, 2013 at 10:24 AM, Jean Francois LE BESCONT
>> <jf...@gmail.com> wrote:
>> > Hi,
>> >
>> > I undig an old point (
>> >
>> http://camel.465427.n5.nabble.com/Camel-File-Discard-empty-file-td472234.html
>> > )
>> >
>> > My camel application wait file send from a tierce application ( which is
>> > generate from a file:stream by an other application) and has to process
>> it
>> > and delete it after.
>> >
>> > The file can be empty or big (more than 1Go). The big size of the file
>> > required that the from wait for the end of the write before to process
>> it
>> > and I have to manage in the same time empty file.
>> >
>> > I have started with a :
>> >
>> >
>> from("file://C:/Temp/camel2/in/?filter=#lockFilter&delay=2000&delete=true")
>> > .log("start process file => ${file:name}")
>> > .to("file://C:/Temp/camel2/out/?fileName=out.csv")
>> > .log("end process file => ${file:name}")
>> > .end();
>> >
>> > With a lockFilter :
>> >
>> > public class LockFilter<T> implements GenericFileFilter<T> {
>> >
>> > @Override
>> > public boolean accept(GenericFile<T> genericFile) {
>> >
>> > File currentFile = (File) genericFile.getFile();
>> >
>> > // try to rename the current file
>> > if (currentFile.renameTo(currentFile)) {
>> > return true;
>> > } else {
>> > return false;
>> > }
>> > }
>> > }
>> >
>> > I am a little suprised that camel doesn't manage it " natively " , is
>> there
>> > a other solution ?
>> >
>> > Thanks !
>> >
>> > Jeff
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> www.camelone.org: The open source integration conference.
>>
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: cibsen@redhat.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>
>

Re: Camel File Discard empty file

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
I have play with readLock but :

*changed : (with "**?readLock=changed&readLockTimeout=20000&delete=true") :
doesn't detect empty file.*
*
*
*fileLock : (with "?readLock=fileLock&delete=true" ) generate an exception
on the producer of the file ( in my case an other application)
*
*
*
*
2013-05-30 12:06:33 - [0 - file://C:/Temp/camel/rep1/] route1
          INFO  start process file => file.csv
Exception in thread "main" java.io.IOException: The process cannot access
the file because another process has locked a portion of the file
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:305)
at com.mycompany.camel.spring.bacasable.Start.main(Start.java:19)
*
[...]

rename : (with "?readLock=rename&delete=true" ) generate an exception on
the client :

org.apache.camel.component.file.GenericFileOperationFailedException: Error
renaming file from C:\Temp\camel\rep1\file.csv to
C:\Temp\camel\rep1\file.csv.camelExclusiveReadLock
at
org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:72)[camel-core-2.11.0.jar:2.11.0]
[...]

That is with I have developed my own filter as you suggest.


2013/5/30 Claus Ibsen <cl...@gmail.com>

> Hi
>
> It does, see the readLock option
> http://camel.apache.org/file2
>
> On Thu, May 30, 2013 at 10:24 AM, Jean Francois LE BESCONT
> <jf...@gmail.com> wrote:
> > Hi,
> >
> > I undig an old point (
> >
> http://camel.465427.n5.nabble.com/Camel-File-Discard-empty-file-td472234.html
> > )
> >
> > My camel application wait file send from a tierce application ( which is
> > generate from a file:stream by an other application) and has to process
> it
> > and delete it after.
> >
> > The file can be empty or big (more than 1Go). The big size of the file
> > required that the from wait for the end of the write before to process it
> > and I have to manage in the same time empty file.
> >
> > I have started with a :
> >
> >
> from("file://C:/Temp/camel2/in/?filter=#lockFilter&delay=2000&delete=true")
> > .log("start process file => ${file:name}")
> > .to("file://C:/Temp/camel2/out/?fileName=out.csv")
> > .log("end process file => ${file:name}")
> > .end();
> >
> > With a lockFilter :
> >
> > public class LockFilter<T> implements GenericFileFilter<T> {
> >
> > @Override
> > public boolean accept(GenericFile<T> genericFile) {
> >
> > File currentFile = (File) genericFile.getFile();
> >
> > // try to rename the current file
> > if (currentFile.renameTo(currentFile)) {
> > return true;
> > } else {
> > return false;
> > }
> > }
> > }
> >
> > I am a little suprised that camel doesn't manage it " natively " , is
> there
> > a other solution ?
> >
> > Thanks !
> >
> > Jeff
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Camel File Discard empty file

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

It does, see the readLock option
http://camel.apache.org/file2

On Thu, May 30, 2013 at 10:24 AM, Jean Francois LE BESCONT
<jf...@gmail.com> wrote:
> Hi,
>
> I undig an old point (
> http://camel.465427.n5.nabble.com/Camel-File-Discard-empty-file-td472234.html
> )
>
> My camel application wait file send from a tierce application ( which is
> generate from a file:stream by an other application) and has to process it
> and delete it after.
>
> The file can be empty or big (more than 1Go). The big size of the file
> required that the from wait for the end of the write before to process it
> and I have to manage in the same time empty file.
>
> I have started with a :
>
> from("file://C:/Temp/camel2/in/?filter=#lockFilter&delay=2000&delete=true")
> .log("start process file => ${file:name}")
> .to("file://C:/Temp/camel2/out/?fileName=out.csv")
> .log("end process file => ${file:name}")
> .end();
>
> With a lockFilter :
>
> public class LockFilter<T> implements GenericFileFilter<T> {
>
> @Override
> public boolean accept(GenericFile<T> genericFile) {
>
> File currentFile = (File) genericFile.getFile();
>
> // try to rename the current file
> if (currentFile.renameTo(currentFile)) {
> return true;
> } else {
> return false;
> }
> }
> }
>
> I am a little suprised that camel doesn't manage it " natively " , is there
> a other solution ?
>
> Thanks !
>
> Jeff



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen