Author: ruwan
Date: Sun Aug  9 00:27:39 2009
New Revision: 802468

URL: http://svn.apache.org/viewvc?rev=802468&view=rev
Log:
code reformatting and minor refactoring of the VFS transport

Modified:
    
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/PollTableEntry.java
    
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
    
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java

Modified: 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/PollTableEntry.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/PollTableEntry.java?rev=802468&r1=802467&r2=802468&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/PollTableEntry.java
 (original)
+++ 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/PollTableEntry.java
 Sun Aug  9 00:27:39 2009
@@ -18,15 +18,15 @@
 */
 package org.apache.synapse.transport.vfs;
 
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.description.ParameterInclude;
 import org.apache.axis2.transport.base.AbstractPollTableEntry;
 import org.apache.axis2.transport.base.ParamUtils;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
 /**
  * Holds information about an entry in the VFS transport poll table used by the
  * VFS Transport Listener
@@ -149,11 +149,11 @@
     }
 
     public int getMaxRetryCount() {
-      return maxRetryCount;
+        return maxRetryCount;
     }
 
     public long getReconnectTimeout() {
-      return reconnectTimeout;
+        return reconnectTimeout;
     }
 
     public DateFormat getMoveTimestampFormat() {
@@ -162,43 +162,51 @@
 
     @Override
     public boolean loadConfiguration(ParameterInclude params) throws AxisFault 
{
+        
         fileURI = ParamUtils.getOptionalParam(params, 
VFSConstants.TRANSPORT_FILE_FILE_URI);
         if (fileURI == null) {
             return false;
         } else {
+            
             if (fileURI.startsWith(VFSConstants.VFS_PREFIX)) {
                 fileURI = fileURI.substring(VFSConstants.VFS_PREFIX.length());
             }
+            
             replyFileURI = ParamUtils.getOptionalParam(params, 
VFSConstants.REPLY_FILE_URI);
             fileNamePattern = ParamUtils.getOptionalParam(params,
                     VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN);
+
             contentType = ParamUtils.getRequiredParam(params,
                     VFSConstants.TRANSPORT_FILE_CONTENT_TYPE);
             String option = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS);
-            actionAfterProcess =
-                VFSTransportListener.MOVE.equals(option) ? PollTableEntry.MOVE 
: PollTableEntry.DELETE;
+                    params, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS);
+            actionAfterProcess = VFSTransportListener.MOVE.equals(option) ?
+                    PollTableEntry.MOVE : PollTableEntry.DELETE;
+
             option = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_ERRORS);
-            actionAfterErrors =
-                VFSTransportListener.MOVE.equals(option) ? PollTableEntry.MOVE 
: PollTableEntry.DELETE;
+                    params, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_ERRORS);
+            actionAfterErrors = VFSTransportListener.MOVE.equals(option) ?
+                    PollTableEntry.MOVE : PollTableEntry.DELETE;
+
             option = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE);
-            actionAfterFailure =
-                VFSTransportListener.MOVE.equals(option) ? PollTableEntry.MOVE 
: PollTableEntry.DELETE;
+                    params, VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE);
+            actionAfterFailure = VFSTransportListener.MOVE.equals(option) ?
+                    PollTableEntry.MOVE : PollTableEntry.DELETE;
 
             String moveDirectoryAfterProcess = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_MOVE_AFTER_PROCESS);
+                    params, VFSConstants.TRANSPORT_FILE_MOVE_AFTER_PROCESS);
             setMoveAfterProcess(moveDirectoryAfterProcess);
+
             String moveDirectoryAfterErrors = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_MOVE_AFTER_ERRORS);
+                    params, VFSConstants.TRANSPORT_FILE_MOVE_AFTER_ERRORS);
             setMoveAfterErrors(moveDirectoryAfterErrors);
+
             String moveDirectoryAfterFailure = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE);
+                    params, VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE);
             setMoveAfterFailure(moveDirectoryAfterFailure);
 
             String moveFileTimestampFormat = ParamUtils.getOptionalParam(
-                params, VFSConstants.TRANSPORT_FILE_MOVE_TIMESTAMP_FORMAT);
+                    params, VFSConstants.TRANSPORT_FILE_MOVE_TIMESTAMP_FORMAT);
             if(moveFileTimestampFormat != null) {
                 moveTimestampFormat = new 
SimpleDateFormat(moveFileTimestampFormat);
             }
@@ -209,16 +217,15 @@
             }
             
             String strMaxRetryCount = ParamUtils.getOptionalParam(
-                params, VFSConstants.MAX_RETRY_COUNT);
-            if(strMaxRetryCount != null) {
-                maxRetryCount = Integer.parseInt(strMaxRetryCount);
-            }
+                    params, VFSConstants.MAX_RETRY_COUNT);
+            maxRetryCount = strMaxRetryCount != null ? 
Integer.parseInt(strMaxRetryCount) :
+                    VFSConstants.DEFAULT_MAX_RETRY_COUNT;
 
             String strReconnectTimeout = ParamUtils.getOptionalParam(
-                params, VFSConstants.RECONNECT_TIMEOUT);            
-            if(strReconnectTimeout != null) {
-                reconnectTimeout = Integer.parseInt(strReconnectTimeout) * 
1000;
-            }
+                    params, VFSConstants.RECONNECT_TIMEOUT);
+            reconnectTimeout = strReconnectTimeout != null ?
+                    Integer.parseInt(strReconnectTimeout) * 1000 :
+                    VFSConstants.DEFAULT_RECONNECT_TIMEOUT;
             
             return super.loadConfiguration(params);
         }

Modified: 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java?rev=802468&r1=802467&r2=802468&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
 (original)
+++ 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
 Sun Aug  9 00:27:39 2009
@@ -18,18 +18,23 @@
 */
 package org.apache.synapse.transport.vfs;
 
-import org.apache.axis2.transport.OutTransportInfo;
-import org.apache.axis2.transport.MessageFormatter;
-import org.apache.axis2.transport.base.*;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.TransportOutDescription;
-import org.apache.commons.vfs.*;
-import org.apache.commons.vfs.impl.StandardFileSystemManager;
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.OutTransportInfo;
+import org.apache.axis2.transport.base.AbstractTransportSender;
+import org.apache.axis2.transport.base.BaseUtils;
+import org.apache.axis2.transport.base.ManagementSupport;
 import org.apache.commons.io.output.CountingOutputStream;
 import org.apache.commons.logging.LogFactory;
-import org.apache.axiom.om.OMOutputFormat;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.impl.StandardFileSystemManager;
 
 import java.io.IOException;
 
@@ -77,11 +82,11 @@
      * @throws AxisFault on error
      */
     public void sendMessage(MessageContext msgCtx, String targetAddress,
-        OutTransportInfo outTransportInfo) throws AxisFault {
+                            OutTransportInfo outTransportInfo) throws 
AxisFault {
 
         if (waitForSynchronousResponse(msgCtx)) {
             throw new AxisFault("The VFS transport doesn't support synchronous 
responses. " +
-                       "Please use the appropriate (out only) message exchange 
pattern.");
+                    "Please use the appropriate (out only) message exchange 
pattern.");
         }
 
         VFSOutTransportInfo vfsOutInfo = null;
@@ -98,35 +103,36 @@
                 
                 boolean wasError = true;
                 int retryCount = 0;
-                int maxRetryCount = VFSUtils.getMaxRetryCount(msgCtx, 
vfsOutInfo);
-                long reconnectionTimeout = VFSUtils.getReconnectTimout(msgCtx, 
vfsOutInfo);
+                int maxRetryCount = VFSUtils.getMaxRetryCount(vfsOutInfo);
+                long reconnectionTimeout = 
VFSUtils.getReconnectTimout(vfsOutInfo);
                 boolean append = vfsOutInfo.isAppend();
                 
-                while(wasError == true) {
-                  try {
-                    retryCount++;
-                    replyFile = 
fsManager.resolveFile(vfsOutInfo.getOutFileURI());
+                while (wasError) {
                     
-                    if(replyFile == null) {
-                      log.error("replyFile is null");
-                      throw new FileSystemException("replyFile is null");
-                    }
+                    try {
+                        retryCount++;
+                        replyFile = 
fsManager.resolveFile(vfsOutInfo.getOutFileURI());
                     
-                    wasError = false;
+                        if(replyFile == null) {
+                            log.error("replyFile is null");
+                            throw new FileSystemException("replyFile is null");
+                        }
+                    
+                        wasError = false;
                                         
-                  } catch(FileSystemException e) {
-                    log.error("cannot resolve replyFile", e);
-                    if(maxRetryCount <= retryCount)
-                      handleException("cannot resolve replyFile repeatedly: " 
+ e.getMessage(), e);
-                  }
+                    } catch(FileSystemException e) {
+                        log.error("cannot resolve replyFile", e);
+                        if(maxRetryCount <= retryCount)
+                            handleException("cannot resolve replyFile 
repeatedly: " + e.getMessage(), e);
+                    }
                 
-                  if(wasError == true) {
-                    try {
-                      Thread.sleep(reconnectionTimeout);
-                    } catch (InterruptedException e2) {
-                      e2.printStackTrace();
+                    if (wasError) {
+                        try {
+                            Thread.sleep(reconnectionTimeout);
+                        } catch (InterruptedException e2) {
+                            e2.printStackTrace();
+                        }
                     }
-                  }
                 }
                 
                 if (replyFile.exists()) {
@@ -134,7 +140,7 @@
                     if (replyFile.getType() == FileType.FOLDER) {
                         // we need to write a file containing the message to 
this folder
                         FileObject responseFile = 
fsManager.resolveFile(replyFile,
-                            VFSUtils.getFileName(msgCtx, vfsOutInfo));
+                                VFSUtils.getFileName(msgCtx, vfsOutInfo));
 
                         acquireLockForSending(responseFile, vfsOutInfo);
                         if (!responseFile.exists()) {
@@ -151,7 +157,7 @@
                         
                     } else {
                         handleException("Unsupported reply file type : " + 
replyFile.getType() +
-                            " for file : " + vfsOutInfo.getOutFileURI());
+                                " for file : " + vfsOutInfo.getOutFileURI());
                     }
                 } else {
                     acquireLockForSending(replyFile, vfsOutInfo);
@@ -161,7 +167,7 @@
                 }
             } catch (FileSystemException e) {
                 handleException("Error resolving reply file : " +
-                    vfsOutInfo.getOutFileURI(), e);
+                        vfsOutInfo.getOutFileURI(), e);
             } finally {
                 if (replyFile != null) {
                     try {

Modified: 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java?rev=802468&r1=802467&r2=802468&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java
 (original)
+++ 
synapse/branches/1.3/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java
 Sun Aug  9 00:27:39 2009
@@ -24,16 +24,16 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.vfs.FileContent;
-import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemManager;
 
-import java.util.Map;
-import java.util.Random;
-import java.util.Arrays;
-import java.io.OutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Random;
 
 public class VFSUtils extends BaseUtils {
 
@@ -52,7 +52,7 @@
             if (o instanceof String) {
                 return (String) o;
             }
-        } catch (FileSystemException e) {}
+        } catch (FileSystemException ignored) {}
         return null;
     }
 
@@ -85,20 +85,14 @@
         return fileName;
     }
     
-    public static int getMaxRetryCount(MessageContext msgCtx, 
VFSOutTransportInfo vfsOutInfo) {
-          if(vfsOutInfo.getMaxRetryCount() != 0) {
-            return vfsOutInfo.getMaxRetryCount();
-          }
-          
-          return VFSConstants.DEFAULT_MAX_RETRY_COUNT; 
-    }    
-
-    public static long getReconnectTimout(MessageContext msgCtx, 
VFSOutTransportInfo vfsOutInfo) {
-      if(vfsOutInfo.getReconnectTimeout() != 0) {
-        return vfsOutInfo.getReconnectTimeout();
-      }
+    public static int getMaxRetryCount(VFSOutTransportInfo vfsOutInfo) {
+        return vfsOutInfo.getMaxRetryCount() != 0 ? 
vfsOutInfo.getMaxRetryCount() :
+                VFSConstants.DEFAULT_MAX_RETRY_COUNT;
+    }
 
-      return VFSConstants.DEFAULT_RECONNECT_TIMEOUT; 
+    public static long getReconnectTimout(VFSOutTransportInfo vfsOutInfo) {
+        return vfsOutInfo.getReconnectTimeout() != 0 ? 
vfsOutInfo.getReconnectTimeout() :
+                VFSConstants.DEFAULT_RECONNECT_TIMEOUT;
     }
 
     /**
@@ -186,7 +180,7 @@
             // noinspection ResultOfMethodCallIgnored
             is.read(val);
             if (Arrays.equals(lockValue, val) && is.read() == -1) {
-               return true;
+                return true;
             } else {
                 log.debug("The lock has been acquired by an another party");
             }


Reply via email to