4 Replies Latest reply on Apr 27, 2009 6:55 AM by Joshua Tharp

    Is it possible to reuse the file poller?

    Joshua Tharp Newbie

      JBoss AS 5 is obviously using some kind of file/directory poller to notice and hot deploy applications. I have an application where I too need to notice the arrival of new files in a directory. Is it possible to reuse the file poller? If so, can I get a pointer to where I might find out how to do that?

      Thanks,

      Josh

        • 1. Re: Is it possible to reuse the file poller?
          Ales Justin Master

          The (pseudo) mechanism goes like this:
          * HDScanner (hdscanner-jboss-beans.xml) asks ProfileService
          * ProfileService (from profile.xml) asks Profile which asks StructureModificationChecker if anything has been modified
          * current impl of SMC is MetaDataStructureModificationChecker (also in profile.xml)
          * in 5.1.x the SMC impl is SynchWrapperModificationChecker

          It now depends where you wanna plugin.

          You can step through these classes and check how they work.
          If you need any additional hook let me know and I'll see what we can do.

          • 2. Re: Is it possible to reuse the file poller?
            Joshua Tharp Newbie

            I'm going to claim ignorance here and restate my problem a little. Perhaps you can then better recommend where I should look to plug in...

            (By the way, I'm using JBoss 5.0.1.GA)

            I have an external system that is delivering files to my system. They call a trigger script on my box when the file has been completely downloaded. I planned on having my trigger script create a file that describes some aspects of the delivery, and I need to identify when that descriptor file has been put in a specific directory. In other words, when the file arrives, I can perform my actions on it immediately as the trigger script will ensure the delivered file has been completely downloaded.

            Boiling this down to some basic requirements, I need to be able to identify when a descriptor has been dropped in my delivery directory and then perform some custom (and preferably transactional) actions. If in order to get the transaction part, I need to kick off something with JMS or an EJB call that's OK.

            Thanks again for your help,

            Josh

            • 3. Re: Is it possible to reuse the file poller?
              Ales Justin Master

              Hmm ... I guess the easiest for you would be to write your own HDScanner from hdscanner-jboss-beans.xml.

              Where most of the logic would still be the same as what HDscanner bean does now,
              but you would intercept the list of ModificationInfos,
              and check if any of those is your descriptor file.

              HDScanner bean:

               public synchronized void scan() throws Exception
               {
               boolean trace = log.isTraceEnabled();
              
               // Query the ProfileService for deployments
               if( trace )
               log.trace("Begin deployment scan");
              
              
               // Get the modified deployments
               Profile activeProfile = profileService.getActiveProfile();
               if( activeProfile == null )
               {
               if( trace )
               log.trace("End deployment scan, no activeProfile");
               return;
               }
              
               Collection<ModificationInfo> modified = activeProfile.getModifiedDeployments();
               for(ModificationInfo info : modified)
               {
               VFSDeployment ctx = info.getDeployment();
              
               // TODO <--- your code here
              
               switch( info.getStatus() )
               {
               case ADDED:
               mainDeployer.addDeployment(ctx);
               break;
               case MODIFIED:
               mainDeployer.addDeployment(ctx);
               break;
               case REMOVED:
               mainDeployer.removeDeployment(ctx.getName());
               break;
               }
               }
              


              • 4. Re: Is it possible to reuse the file poller?
                Joshua Tharp Newbie

                Thanks for the pointers. I'm looking into the code and getting some ideas of how I would plug into this stack.