| 
      
      
      From: <ha...@us...> - 2008-04-05 13:59:29
      
     | 
| Revision: 1956
          http://cogkit.svn.sourceforge.net/cogkit/?rev=1956&view=rev
Author:   hategan
Date:     2008-04-05 06:59:25 -0700 (Sat, 05 Apr 2008)
Log Message:
-----------
fixed data channel reuse stuff
Modified Paths:
--------------
    trunk/current/src/cog/modules/provider-gt2/CHANGES.txt
    trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/FileResourceImpl.java
    trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/old/FileResourceImpl.java
Modified: trunk/current/src/cog/modules/provider-gt2/CHANGES.txt
===================================================================
--- trunk/current/src/cog/modules/provider-gt2/CHANGES.txt	2008-04-04 12:29:00 UTC (rev 1955)
+++ trunk/current/src/cog/modules/provider-gt2/CHANGES.txt	2008-04-05 13:59:25 UTC (rev 1956)
@@ -1,3 +1,7 @@
+(04/05/2008)
+
+*** Fixed data channel reuse behavior
+
 (02/11/2008)
 
 *** The last commit broke things (mlst seems picky).
Modified: trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/FileResourceImpl.java
===================================================================
--- trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/FileResourceImpl.java	2008-04-04 12:29:00 UTC (rev 1955)
+++ trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/FileResourceImpl.java	2008-04-05 13:59:25 UTC (rev 1956)
@@ -69,7 +69,7 @@
         }
         else {
             try {
-                initializeDataChannel();
+                initializeDataChannel(RETRIEVE);
                 Vector v = this.getGridFTPClient().mlsd();
                 ArrayList list = new ArrayList();
                 Iterator i = v.iterator();
@@ -126,7 +126,7 @@
         }
         else {
             try {
-                initializeDataChannel();
+                initializeDataChannel(RETRIEVE);
                 Vector v = this.getGridFTPClient().mlsd(directory);
                 ArrayList list = new ArrayList();
                 Iterator i = v.iterator();
Modified: trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/old/FileResourceImpl.java
===================================================================
--- trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/old/FileResourceImpl.java	2008-04-04 12:29:00 UTC (rev 1955)
+++ trunk/current/src/cog/modules/provider-gt2/src/org/globus/cog/abstraction/impl/file/gridftp/old/FileResourceImpl.java	2008-04-05 13:59:25 UTC (rev 1956)
@@ -61,6 +61,9 @@
 public class FileResourceImpl extends AbstractFTPFileResource {
     public static final Logger logger = Logger
             .getLogger(FileResourceImpl.class);
+    
+    protected static final boolean STORE = true;
+    protected static final boolean RETRIEVE = false;
 
     /**
      * By default JGlobus sets this to 6000 ms. Experience has proved that it
@@ -71,6 +74,7 @@
     private GridFTPClient gridFTPClient;
     private boolean dataChannelReuse;
     private boolean dataChannelInitialized;
+    private boolean dataChannelDirection;
 
     /** throws InvalidProviderException */
     public FileResourceImpl() throws Exception {
@@ -102,10 +106,18 @@
             gridFTPClient = new GridFTPClient(host, port);
             Reply r = gridFTPClient.getLastReply();
 
-            if (r != null && r.getMessage().indexOf("GridFTP Server 2.3") != -1) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Initial reply: " + r.getMessage());
+            }
+            if (r != null && r.getMessage().indexOf("Virtual Broken GridFTP Server") != -1) {
+                dataChannelReuse = false;
+            }
+            else {
                 dataChannelReuse = true;
-                logger.debug("GridFTP version is 2.3. Enabling data channel reuse.");
             }
+            if (logger.isDebugEnabled()) {
+                logger.debug("Data channel reuse: " + dataChannelReuse);
+            }
             gridFTPClient.setClientWaitParams(MAX_REPLY_WAIT_TIME,
                     Session.DEFAULT_WAIT_DELAY);
             GSSCredential proxy = (GSSCredential) getSecurityContext()
@@ -124,14 +136,28 @@
                     "Error communicating with the GridFTP server", e);
         }
     }
+    
+    public boolean getDataChannelReuse() {
+        return dataChannelReuse;
+    }
+    
+    public void setDataChannelReuse(boolean dataChannelReuse) {
+        this.dataChannelReuse = dataChannelReuse;
+        this.dataChannelInitialized = false;
+    }
 
-    protected void initializeDataChannel() throws ClientException,
+    protected void initializeDataChannel(boolean mode) throws ClientException,
             ServerException, IOException {
-        if (!dataChannelInitialized || !dataChannelReuse) {
-            gridFTPClient.setPassiveMode(true);
+        if (!dataChannelInitialized || !dataChannelReuse || dataChannelDirection != mode) {
+            gridFTPClient.setPassiveMode(mode);
             dataChannelInitialized = true;
+            dataChannelDirection = mode;
         }
     }
+    
+    protected void resetDataChannel() {
+        dataChannelInitialized = false;
+    }
 
     protected void setSecurityOptions(GridFTPClient client)
             throws ServerException, IOException {
@@ -214,7 +240,7 @@
 
         Vector gridFileList = new Vector();
         try {
-            this.initializeDataChannel();
+            this.initializeDataChannel(RETRIEVE);
             Enumeration list = gridFTPClient.list().elements();
             while (list.hasMoreElements()) {
                 gridFileList.add(createGridFile((FileInfo) list.nextElement()));
@@ -309,7 +335,7 @@
     public void get(String remoteFileName, DataSink sink,
             MarkerListener mListener) throws FileResourceException {
         try {
-            initializeDataChannel();
+            initializeDataChannel(RETRIEVE);
             gridFTPClient.get(remoteFileName, sink, mListener);
         }
         catch (Exception e) {
@@ -321,7 +347,7 @@
     public void get(String remoteFileName, File localFile)
             throws FileResourceException {
         try {
-            initializeDataChannel();
+            initializeDataChannel(RETRIEVE);
             gridFTPClient.get(remoteFileName, localFile);
         }
         catch (Exception e) {
@@ -341,7 +367,7 @@
             final ProgressMonitor progressMonitor) throws FileResourceException {
         File localFile = new File(localFileName);
         try {
-            initializeDataChannel();
+            initializeDataChannel(RETRIEVE);
             final long size = localFile.length();
             DataSink sink;
             if (progressMonitor != null) {
@@ -374,7 +400,7 @@
 
         final File localFile = new File(localFileName);
         try {
-            initializeDataChannel();
+            initializeDataChannel(STORE);
             final long size = localFile.length();
             DataSource source;
             if (progressMonitor != null) {
@@ -408,7 +434,7 @@
             throws FileResourceException {
 
         try {
-            initializeDataChannel();
+            initializeDataChannel(STORE);
             gridFTPClient.put(localFile, remoteFileName, append);
         }
         catch (Exception e) {
@@ -424,7 +450,7 @@
     public void put(DataSource source, String remoteFileName,
             MarkerListener mListener) throws FileResourceException {
         try {
-            initializeDataChannel();
+            initializeDataChannel(STORE);
             gridFTPClient.put(remoteFileName, source, mListener);
         }
         catch (Exception e) {
@@ -495,7 +521,7 @@
                 setCurrentDirectory(currentDirectory);
             }
             catch (Exception e) {
-                // do nothihng
+                // do nothing
             }
         }
         return isDir;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |