[jboss-svn-commits] JBL Code SVN: r6418 - labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Sep 25 12:39:39 EDT 2006
Author: estebanschifman
Date: 2006-09-25 12:39:37 -0400 (Mon, 25 Sep 2006)
New Revision: 6418
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RemoteDirectoryPoller.java
Log:
RemoteDirectoryPoller class from beta 1 maintenance patch
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RemoteDirectoryPoller.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RemoteDirectoryPoller.java 2006-09-25 16:36:05 UTC (rev 6417)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RemoteDirectoryPoller.java 2006-09-25 16:39:37 UTC (rev 6418)
@@ -0,0 +1,238 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+
+package org.jboss.soa.esb.listeners;
+
+import java.io.*;
+import java.util.*;
+
+import org.jboss.soa.esb.actions.*;
+import org.jboss.soa.esb.helpers.*;
+import org.apache.log4j.*;
+
+public class RemoteDirectoryPoller extends AbstractPoller
+{
+ public static final String FILE_INPUT_DIR = "inputDir";
+ public static final String FILE_INPUT_SFX = "inputSuffix";
+ public static final String FILE_WORK_SFX = "workSuffix";
+ public static final String FILE_ERROR_DIR = "errorDir";
+ public static final String FILE_ERROR_SFX = "errorSuffix";
+ public static final String FILE_POST_DIR = "postDir";
+ public static final String FILE_POST_SFX = "postSuffix";
+ public static final String FILE_POST_DEL = "postDelete";
+
+ private DomElement m_oParms;
+
+ public RemoteDirectoryPoller(GpListener p_oDad, DomElement p_oParms,ActionDefinitionFactory actionDF)
+ throws Exception
+ {
+ super(p_oDad,p_oParms,actionDF);
+ m_oParms = p_oParms;
+ checkMyParms();
+ } //__________________________________
+
+
+ protected File m_oInpDir ,m_oErrorDir ,m_oPostDir;
+ protected String m_sInpSfx ,m_sWrkSfx ,m_sErrSfx ,m_sPostSfx;
+ protected boolean m_bPostDel;
+
+ /**
+ *
+ * @param p_o Object - Must be a File representing the file that has to be processed
+ * @return Object - an array of 3 Files containing:
+ * <p/>[0] renamed file (workSuffix appended to input file name)
+ * <p/>[1] target file name in case actionClass is unable to complete successfuly
+ * <p/>[2] target file name in case actionClass finishes successfuly
+ */
+ @Override
+ public Object preProcess(Object p_o)
+ {
+ if (!(p_o instanceof File))
+ return null;
+ File oF = (File)p_o;
+
+ WorkingFile oCurr = new WorkingFile(oF.getParentFile(), oF.getName() + m_sWrkSfx);
+ oCurr.postDelete = m_bPostDel;
+ oCurr.inputFile = oF;
+ oCurr.errorFile = new File (m_oErrorDir ,oF.getName()+m_sErrSfx);
+ oCurr.outputFile = new File (m_oPostDir ,oF.getName()+m_sPostSfx);
+
+ FtpClientUtil oFtp = null;
+ try
+ {
+ oFtp = new FtpClientUtil(m_oParms,true);
+ oFtp.remoteRename(oF,oCurr);
+ }
+ catch (Exception e)
+ {
+ Logger.getLogger(this.getClass()).error("Can't FTP rename",e);
+ return null;
+ }
+ finally
+ {
+ if (null!=oFtp)
+ oFtp.quit();
+ }
+
+ return oCurr;
+ } //________________________________
+
+ @Override
+ protected List<Object> pollForCandidates()
+ {
+ List<Object> oRet = new ArrayList<Object>();
+ FtpClientUtil oFtp = null;
+ try
+ {
+ oFtp = new FtpClientUtil(m_oParms,true);
+ oFtp.setRemoteDir(FtpClientUtil.fileToFtpString(m_oInpDir));
+ String[] sa = oFtp.getFileListFromRemoteDir(m_sInpSfx);
+ if (null!=sa)
+ for (String sCurr : sa)
+ oRet.add(new File(m_oInpDir,sCurr));
+ }
+ catch (Exception e)
+ {
+ Logger.getLogger(this.getClass()).error("Problems with FTP",e);
+ }
+ finally
+ {
+ if (null!=oFtp)
+ oFtp.quit();
+ }
+ return oRet;
+
+ } //________________________________
+
+ protected void checkMyParms() throws Exception
+ {
+ // INPUT directory and suffix (used for FileFilter)
+ String sInpDir = GpListener.obtainAtt(m_oParms,FILE_INPUT_DIR,null);
+ m_oInpDir = new File(sInpDir);
+
+ m_sInpSfx = GpListener.obtainAtt(m_oParms,FILE_INPUT_SFX,null);
+ m_sInpSfx = m_sInpSfx.trim();
+ if (m_sInpSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_INPUT_SFX+" attribute");
+
+ // WORK suffix (will rename in input directory)
+ m_sWrkSfx = GpListener.obtainAtt(m_oParms,FILE_WORK_SFX,".esbWork").trim();
+ if (m_sWrkSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_WORK_SFX+" attribute");
+ if (m_sInpSfx.equals(m_sWrkSfx))
+ throw new Exception("Work suffix must differ from input suffix <"+m_sWrkSfx+">");
+
+ // ERROR directory and suffix (defaults to input dir and ".esbError" suffix)
+ String sErrDir = GpListener.obtainAtt(m_oParms,FILE_ERROR_DIR,sInpDir);
+ m_oErrorDir = new File(sErrDir);
+
+ m_sErrSfx = GpListener.obtainAtt(m_oParms,FILE_ERROR_SFX,".esbError").trim();
+ if (m_sErrSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_ERROR_SFX+" attribute");
+ if (m_oErrorDir.equals(m_oInpDir) && m_sInpSfx.equals(m_sErrSfx))
+ throw new Exception("Error suffix must differ from input suffix <"+m_sErrSfx+">");
+
+
+ // Do users wish to delete files that were processed OK ?
+ String sPostDel = GpListener.obtainAtt(m_oParms,FILE_POST_DEL,"false").trim();
+ m_bPostDel = Boolean.parseBoolean(sPostDel);
+ if (m_bPostDel)
+ return;
+
+ // POST (done) directory and suffix (defaults to input dir and ".esbDone" suffix)
+ String sPostDir = GpListener.obtainAtt(m_oParms,FILE_POST_DIR,sInpDir);
+ m_oPostDir = new File(sPostDir);
+ m_sPostSfx = GpListener.obtainAtt(m_oParms,FILE_POST_SFX,".esbDone").trim();
+ if (m_oPostDir.equals(m_oInpDir))
+ { if (m_sPostSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_POST_SFX+" attribute");
+ if (m_sPostSfx.equals(m_sInpSfx))
+ throw new Exception("Post process suffix must differ from input suffix <"+m_sPostSfx+">");
+ }
+
+
+ FtpClientUtil oFtp = new FtpClientUtil(m_oParms,false);
+ oFtp.quit();
+
+ } //________________________________
+
+
+ @Override
+ protected void processingError(Object initialMessage, ActionProcessor processor, Throwable error) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void processingComplete(Object initialMessage) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void close() {
+ // TODO Auto-generated method stub
+
+ }
+ /**
+ * Working file.
+ * <p/>
+ * Once the directory poller picks up on an input file, it immediately renames it to a working file
+ * in order to avoid a situation where the file gets processed again.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+ public static class WorkingFile extends File
+ {
+ private static final long serialVersionUID = 1L;
+
+ boolean postDelete;
+
+ File inputFile, errorFile, outputFile;
+
+ public WorkingFile(String filename) {
+ super(filename);
+ }
+
+ public WorkingFile(File parentFile, String filename) {
+ super(parentFile, filename);
+ }
+
+ public boolean renameToError() {
+ return renameTo(errorFile);
+ }
+
+ public boolean renameToOutputFile() {
+ return renameTo(outputFile);
+ }
+
+ /**
+ * Get the File instance representing the original input file.
+ * @return Original input file.
+ */
+ public File getInputFile() {
+ return inputFile;
+ }
+ }
+} //____________________________________________________________________________
More information about the jboss-svn-commits
mailing list