2 Replies Latest reply on Jan 8, 2009 12:01 PM by Dave Stanley

    Bean-SU implementation not able to handle concurrent messages correctly?

    Corrado Campisano Newbie



      I'm developing a generic SA able to poll TXT files from one folder, extract some data from them and use this data to rename the file, moving it to another folder.


      It optionally polls the renamed file and transfers it using ftp.


      Notice the txt file is handled as an attachment.



      The maven project is attached as a zip file (notice the SA is meant to use an external configuration file, which is red at deployment time - check for the whole stuff - it's a little complex).



      Take a look at the onMessageExchange code for the bean-SU (which does the data extraction, renaming and routing), in class eu.servicemix.tools.sMixCcbFrt.FileBean.java



      Everithing works fine if ONE txt file AT A TIME is dropped into the incoming folder: it is renamed and moved correctly (to the output folder or to another "error" folder if the data to be used for renaming is not found).


      But, if I drop multiple files into the incoming folder, the bean mess with them and the behaviour varies randomly: "good" files are moved to the "wrong" files folder and vice-versa.


      Is that because the bean is a 'singletone' and is not concurrency-safe?


      Looking at the log files, it seems it's the attachment piece of code which goes wrong:

      nm.addAttachment(attachmentNameOut, dh2);

      it attaches the wrong file randomly: sometimes every file is attached correctly, but most of the times one attachment replaces all the others.




      Maybe I just have to move the class variables:

      private String fileContent = "";

      private String fileOrigName = "";

      private String fileNewName = "";

      inside the method?



      Thanks for your attention and regards

      Corrado Campisano


      Edited by: corrado on Jan 7, 2009 8:44 PM