Author: jflesch
Date: 2006-07-10 18:58:40 +0000 (Mon, 10 Jul 2006)
New Revision: 9549

Added:
   trunk/apps/Thaw/src/thaw/fcp/FCPTransferQuery.java
Modified:
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/core/QueueKeeper.java
   trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
   trunk/apps/Thaw/src/thaw/fcp/FCPQuery.java
   trunk/apps/Thaw/src/thaw/fcp/FCPQueueManager.java
   trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DetailPanel.java
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java
Log:
Simplify FCPQuery and create a child interface called FCPTransferQuery

Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-10 15:55:18 UTC (rev 
9548)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-10 18:58:40 UTC (rev 
9549)
@@ -151,15 +151,14 @@
                        }

                        queryManager = new FCPQueryManager(connection);
+                       queueManager = new FCPQueueManager(queryManager,
+                                                          
config.getValue("thawId"),
+                                                          (new 
Integer(config.getValue("maxSimultaneousDownloads"))).intValue(),
+                                                          (new 
Integer(config.getValue("maxSimultaneousInsertions"))).intValue());

                        if(connection.isConnected()) {
                                queryManager.startListening();

-                               queueManager = new FCPQueueManager(queryManager,
-                                                                  
config.getValue("thawId"),
-                                                                  (new 
Integer(config.getValue("maxSimultaneousDownloads"))).intValue(),
-                                                                  (new 
Integer(config.getValue("maxSimultaneousInsertions"))).intValue());
-
                                QueueKeeper.loadQueue(queueManager, 
"thaw.queue.xml");



Modified: trunk/apps/Thaw/src/thaw/core/QueueKeeper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/QueueKeeper.java      2006-07-10 15:55:18 UTC 
(rev 9548)
+++ trunk/apps/Thaw/src/thaw/core/QueueKeeper.java      2006-07-10 18:58:40 UTC 
(rev 9549)
@@ -42,7 +42,7 @@


        private static void loadQuery(FCPQueueManager queueManager, Element 
queryEl, boolean runningQueue) {
-               FCPQuery newQuery = null;
+               FCPTransferQuery newQuery = null;
                HashMap params = new HashMap();

                NodeList paramList = queryEl.getElementsByTagName("param");
@@ -152,7 +152,7 @@
        }


-       private static Element saveQuery(FCPQuery query, Document xmlDoc) {
+       private static Element saveQuery(FCPTransferQuery query, Document 
xmlDoc) {
                HashMap params = query.getParameters();

                Element queryEl = xmlDoc.createElement("query");
@@ -226,7 +226,7 @@

                for(Iterator runIt = runningQueue.iterator() ;
                    runIt.hasNext(); ) {
-                       FCPQuery query = (FCPQuery)runIt.next();
+                       FCPTransferQuery query = (FCPTransferQuery)runIt.next();

                        runningQueueEl.appendChild(saveQuery(query, xmlDoc));

@@ -241,7 +241,7 @@
                        for(Iterator runIt = pendingQueue[i].iterator() ;
                            runIt.hasNext(); ) {

-                               FCPQuery query = (FCPQuery)runIt.next();
+                               FCPTransferQuery query = 
(FCPTransferQuery)runIt.next();

                                Element toSave = saveQuery(query, xmlDoc);


Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2006-07-10 15:55:18 UTC 
(rev 9548)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2006-07-10 18:58:40 UTC 
(rev 9549)
@@ -12,7 +12,7 @@
 /**
  * notify() only when progress has really changes.
  */
-public class FCPClientGet extends Observable implements Observer, FCPQuery {
+public class FCPClientGet extends Observable implements Observer, 
FCPTransferQuery {
        private final static int MAX_RETRIES = 3;
        private final static int PACKET_SIZE = 1024;
        private final static int BLOCK_SIZE = 32768;
@@ -184,11 +184,11 @@
                if(message.getMessageName().equals("ProtocolError")) {
                        Logger.debug(this, "ProtocolError !");

-                       status = "Protocol Error";
+                       status = "Protocol Error 
("+message.getValue("CodeDescription")+")";
                        progress = 100;
                        running = false;
                        successful = false;
-
+                       
                        queueManager.getQueryManager().deleteObserver(this);

                        setChanged();
@@ -205,7 +205,7 @@
                        attempt++;

                        if(attempt >= MAX_RETRIES || code == 25) {
-                           status = "Failed";
+                           status = "Failed 
("+message.getValue("CodeDescription")+")";
                            progress = 100;
                            running = false;
                            successful = false;
@@ -383,6 +383,10 @@
                return attempt;
        }

+       public int getMaxAttempt() {
+               return MAX_RETRIES;
+       }
+
        public boolean isSuccessful() {
                return successful;
        }
@@ -402,8 +406,13 @@
                result.put("destinationDir", destinationDir);
                result.put("attempt", ((new Integer(attempt)).toString()));

-               String[] cut = status.split(" ");
-               result.put("status", cut[0]);
+               if(status.indexOf("(?)") > 0) {
+                       String[] cut = status.split(" ");
+                       result.put("status", cut[0]);
+               } else {
+                       result.put("status", status);
+               }
+
                result.put("identifier", identifier);
                result.put("progress", ((new Integer(progress)).toString()));
                result.put("fileSize", ((new Long(fileSize)).toString()));

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPQuery.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPQuery.java  2006-07-10 15:55:18 UTC (rev 
9548)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPQuery.java  2006-07-10 18:58:40 UTC (rev 
9549)
@@ -1,11 +1,9 @@
 package thaw.fcp;

-import java.util.HashMap;

 /**
  * This interface was designed for file query (insertions / downloads)
  * but it's used sometimes for other things.
- * TODO : Simplify this interface and create an interface FCPTransferQuery 
extending this one.
  */
 public interface FCPQuery {

@@ -31,77 +29,9 @@

        /**
         * Tell if the query is a download query or an upload query.
-        * If >= 1 then *must* be Observable.
-        * @return 0 : Meaningless ; 1 : Download ; 2 : Upload
+        * If >= 1 then *must* be Observable and implements FCPTransfertQuery.
+        * @return 0 : Meaningless ; 1 : Download ; 2 : Upload ; >= 2 : ?
         */
        public int getQueryType();

-
-       /**
-        * Informal.
-        * Human readable string describring the
-        * status of the query.
-        * @return can be null (== "Waiting")
-        */
-       public String getStatus();
-
-       /**
-        * Informal.
-        * In pourcents.
-        */
-       public int getProgression();
-
-       /**
-        * Informal.
-        * @return can be null
-        */
-       public String getFileKey();
-
-       /**
-        * Informal. In bytes.
-        * @return can be -1
-        */
-       public long getFileSize();
-
-       /**
-        * Informal.
-        * @return can return null
-        */
-       public String getPath();
-
-       /**
-        * Informal.
-        * @return can return -1
-        */
-       public int getAttempt();
-
-       public boolean isRunning();
-
-       public boolean isFinished();
-
-       /**
-        * If unknow, return false.
-        * Query is considered as a failure is isFinished() && !isSuccesful()
-        */
-       public boolean isSuccessful();
-
-       /**
-        * Use to save the query in an XML file / a database / whatever.
-        * @return A HashMap : String (parameter name) -> String (parameter 
value) or null.
-        */
-       public HashMap getParameters();
-
-       /**
-        * Opposite of getParameters().
-        * @return true if successful (or ignored) ; false if not.
-        */
-       public boolean setParameters(HashMap parameters);
-
-
-       public boolean isPersistent();
-
-       /**
-        * @return can be null (if non active, or meaningless).
-        */
-       public String getIdentifier();
 }

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPQueueManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPQueueManager.java   2006-07-10 15:55:18 UTC 
(rev 9548)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPQueueManager.java   2006-07-10 18:58:40 UTC 
(rev 9549)
@@ -5,7 +5,10 @@

 import thaw.core.Logger;

-
+/**
+ * Manage a running and a pending queue of FCPTransferQuery.
+ * Please notice that runningQueue contains too finished queries.
+ */
 public class FCPQueueManager extends java.util.Observable implements Runnable {

        private final static int PRIORITY_MIN = 6; /* So 0 to 6 */
@@ -81,7 +84,7 @@
                return runningQueries;
        }

-       public void addQueryToThePendingQueue(FCPQuery query) {
+       public void addQueryToThePendingQueue(FCPTransferQuery query) {
                if(query.getThawPriority() < 0) {
                        addQueryToTheRunningQueue(query);
                        return;
@@ -105,11 +108,11 @@
        /**
         * will call start() function of the query.
         */
-       public void addQueryToTheRunningQueue(FCPQuery query) {
+       public void addQueryToTheRunningQueue(FCPTransferQuery query) {
                addQueryToTheRunningQueue(query, true);
        }

-       public void addQueryToTheRunningQueue(FCPQuery query, boolean 
callStart) {
+       public void addQueryToTheRunningQueue(FCPTransferQuery query, boolean 
callStart) {
                Logger.debug(this, "Adding query to the running queue ...");

                if(!callStart) {
@@ -142,7 +145,7 @@
        /**
         * *Doesn't* call stop() from the query.
         */
-       public void moveFromRunningToPendingQueue(FCPQuery query) {
+       public void moveFromRunningToPendingQueue(FCPTransferQuery query) {
                remove(query);
                addQueryToThePendingQueue(query);
        }
@@ -157,7 +160,7 @@

                for(Iterator queryIt = getRunningQueue().iterator() ;
                    queryIt.hasNext();) {
-                       FCPQuery query = (FCPQuery)queryIt.next();
+                       FCPTransferQuery query = 
(FCPTransferQuery)queryIt.next();

                        if(!query.isPersistent() && !query.isFinished())
                                query.start(this);
@@ -167,7 +170,7 @@

        }

-       public void remove(FCPQuery query) {
+       public void remove(FCPTransferQuery query) {
                runningQueries.remove(query);

                for(int i = 0 ; i <= PRIORITY_MIN ; i++)
@@ -180,7 +183,7 @@
        /**
         * Compare using the key.
         */
-       public boolean isAlreadyPresent(FCPQuery query) {
+       public boolean isAlreadyPresent(FCPTransferQuery query) {
                boolean interrupted=true;

                Iterator it;
@@ -192,7 +195,7 @@
                                for(it = runningQueries.iterator();
                                    it.hasNext(); )
                                        {
-                                               FCPQuery plop = 
(FCPQuery)it.next();
+                                               FCPTransferQuery plop = 
(FCPTransferQuery)it.next();
                                                
if(plop.getFileKey().equals(query.getFileKey()))
                                                        return true;
                                        }
@@ -201,7 +204,7 @@
                                        for(it = pendingQueries[i].iterator();
                                            it.hasNext(); )
                                                {
-                                                       FCPQuery plop = 
(FCPQuery)it.next();
+                                                       FCPTransferQuery plop = 
(FCPTransferQuery)it.next();
                                                        
if(plop.getFileKey().equals(query.getFileKey()))
                                                                return true;
                                                }
@@ -227,7 +230,7 @@
                        int runningDownloads = 0;

                        for(Iterator it = runningQueries.iterator(); 
it.hasNext(); ) {
-                               FCPQuery query = (FCPQuery)it.next();
+                               FCPTransferQuery query = 
(FCPTransferQuery)it.next();

                                if(query.getQueryType() == 1 /* Download */
                                   && !query.isFinished())
@@ -252,7 +255,7 @@
                                                    && (runningInsertions < 
maxInsertions
                                                        || runningDownloads < 
maxDownloads); ) {

-                                               FCPQuery query = 
(FCPQuery)it.next();
+                                               FCPTransferQuery query = 
(FCPTransferQuery)it.next();

                                                if( (query.getQueryType() == 1
                                                     && runningDownloads < 
maxDownloads)

Added: trunk/apps/Thaw/src/thaw/fcp/FCPTransferQuery.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPTransferQuery.java  2006-07-10 15:55:18 UTC 
(rev 9548)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPTransferQuery.java  2006-07-10 18:58:40 UTC 
(rev 9549)
@@ -0,0 +1,85 @@
+package thaw.fcp;
+
+import java.util.HashMap;
+
+/**
+ * Transfer query == fetch / insert query. These queries must be able to
+ * give more informations than the other.
+ */
+public interface FCPTransferQuery extends FCPQuery {
+
+
+       
+       /**
+        * Informal.
+        * Human readable string describring the
+        * status of the query.
+        * @return can be null (== "Waiting")
+        */
+       public String getStatus();
+
+       /**
+        * Informal.
+        * In pourcents.
+        */
+       public int getProgression();
+
+       /**
+        * Informal.
+        * @return can be null
+        */
+       public String getFileKey();
+
+       /**
+        * Informal. In bytes.
+        * @return can be -1
+        */
+       public long getFileSize();
+
+       /**
+        * Where is the file on the disk.
+        */
+       public String getPath();
+
+       /**
+        * @return can return -1
+        */
+       public int getAttempt();
+
+       /**
+        * @return can return -1
+        */
+       public int getMaxAttempt();
+
+       public boolean isRunning();
+
+       public boolean isFinished();
+
+       /**
+        * If unknow, return false.
+        * Query is considered as a failure is isFinished() && !isSuccesful()
+        */
+       public boolean isSuccessful();
+
+       /**
+        * Use to save the query in an XML file / a database / whatever.
+        * @return A HashMap : String (parameter name) -> String (parameter 
value) or null.
+        */
+       public HashMap getParameters();
+
+       /**
+        * Opposite of getParameters().
+        * @return true if successful (or ignored) ; false if not.
+        */
+       public boolean setParameters(HashMap parameters);
+
+
+       public boolean isPersistent();
+
+       /**
+        * @return can be null (if non active, or meaningless).
+        */
+       public String getIdentifier();
+
+
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java  2006-07-10 15:55:18 UTC 
(rev 9548)
+++ trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java  2006-07-10 18:58:40 UTC 
(rev 9549)
@@ -95,7 +95,7 @@
                for(Iterator it = queries.iterator();
                    it.hasNext();) {

-                       FCPQuery query = (FCPQuery)it.next();
+                       FCPTransferQuery query = (FCPTransferQuery)it.next();

                        if(query.getQueryType() == 1)
                                queuePanels[0].addToTable(query);

Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DetailPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DetailPanel.java      
2006-07-10 15:55:18 UTC (rev 9548)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DetailPanel.java      
2006-07-10 18:58:40 UTC (rev 9549)
@@ -15,6 +15,12 @@
 import thaw.i18n.I18n;
 import thaw.fcp.*;

+
+/**
+ * Right panel of queueWatcher plugin. Show details about a transfer.
+ * Possible evolution: Display what is return by 
FCPTransferQuery.getParameters() 
+ * (doing an exception for the progressbar).
+ */
 public class DetailPanel implements Observer {

        private Core core;
@@ -22,15 +28,16 @@
        private JPanel subPanel;
        private JPanel panel;

-       private JTextField file     = new JTextField();
-       private JTextField size     = new JTextField();
+       private JTextField file       = new JTextField();
+       private JTextField size       = new JTextField();
        private JProgressBar progress = new JProgressBar(0, 100);
-       private JTextField key      = new JTextField();
-       private JTextField path     = new JTextField();
-       private JTextField priority = new JTextField();
-       private JTextField attempt  = new JTextField();
+       private JTextField status     = new JTextField(); 
+       private JTextField key        = new JTextField();
+       private JTextField path       = new JTextField();
+       private JTextField priority   = new JTextField();
+       private JTextField attempt    = new JTextField();

-       private FCPQuery query = null;
+       private FCPTransferQuery query = null;


        private final static Dimension dim = new Dimension(300, 275);
@@ -45,6 +52,7 @@
                String[] fieldNames = { I18n.getMessage("thaw.common.file"),
                                        I18n.getMessage("thaw.common.size"),
                                        I18n.getMessage("thaw.common.progress"),
+                                       I18n.getMessage("thaw.common.status"),
                                        I18n.getMessage("thaw.common.key"),
                                        
I18n.getMessage("thaw.common.localPath"),
                                        I18n.getMessage("thaw.common.priority"),
@@ -68,10 +76,11 @@
                                        progress.setString("");
                                        progress.setStringPainted(true);
                                        break;
-                               case(3): field = key; 
key.setEditable(false);break;
-                               case(4): field = path; path.setEditable(false); 
break;
-                               case(5): field = priority; 
priority.setEditable(false); break;
-                               case(6): field = attempt; 
attempt.setEditable(false); break;
+                               case(3): field = status; 
status.setEditable(false); break;
+                               case(4): field = key; 
key.setEditable(false);break;
+                               case(5): field = path; path.setEditable(false); 
break;
+                               case(6): field = priority; 
priority.setEditable(false); break;
+                               case(7): field = attempt; 
attempt.setEditable(false); break;
                                default: Logger.error(this, "Gouli goula ? ... 
is going to crash :p"); break;
                                }

@@ -92,7 +101,7 @@
        }


-       public void setQuery(FCPQuery query) {
+       public void setQuery(FCPTransferQuery query) {
                if(this.query != null)
                        ((Observable)this.query).deleteObserver(this);

@@ -116,9 +125,11 @@
                                progress.setString((new 
Integer(query.getProgression())).toString() + "%");
                        else
                                progress.setString("FAILED");
+                       status.setText(query.getStatus());
                } else {
                        progress.setValue(0);
                        progress.setString("");
+                       status.setText("");
                }
        }


Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-07-10 15:55:18 UTC (rev 9548)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-07-10 18:58:40 UTC (rev 9549)
@@ -107,7 +107,7 @@

                        if(!isSelected) {

-                               FCPQuery query = model.getQuery(row);
+                               FCPTransferQuery query = model.getQuery(row);

                                if(!query.isRunning() && !query.isFinished())
                                        cell.setBackground(PENDING);
@@ -133,20 +133,20 @@



-       public void addToTable(FCPQuery query) {
+       public void addToTable(FCPTransferQuery query) {
                if( (insertionQueue && query.getQueryType() == 2)
                    || (!insertionQueue && query.getQueryType() == 1))
                        tableModel.addQuery(query);
        }

        /**
-        * @param queries Vector of FCPQuery only
+        * @param queries Vector of FCPTransferQuery only
         */
        public void addToTable(Vector queries) {
                for(Iterator queryIt = queries.iterator();
                    queryIt.hasNext();) {

-                       FCPQuery query = (FCPQuery)queryIt.next();
+                       FCPTransferQuery query = 
(FCPTransferQuery)queryIt.next();

                        addToTable(query);
                }

Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java  
2006-07-10 15:55:18 UTC (rev 9548)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java  
2006-07-10 18:58:40 UTC (rev 9549)
@@ -53,7 +53,7 @@
                if(row >= queries.size())
                        return null;

-               FCPQuery query = (FCPQuery)queries.get(row);
+               FCPTransferQuery query = (FCPTransferQuery)queries.get(row);

                if(column == 0) {
                        String[] plop = query.getFileKey().split("/");
@@ -93,7 +93,7 @@
                notifyObservers();
        }

-       public void addQuery(FCPQuery query) {
+       public void addQuery(FCPTransferQuery query) {
                ((Observable)query).addObserver(this);

                queries.add(query);
@@ -101,8 +101,8 @@
                notifyObservers();
        }

-       public FCPQuery getQuery(int row) {
-               return (FCPQuery)queries.get(row);
+       public FCPTransferQuery getQuery(int row) {
+               return (FCPTransferQuery)queries.get(row);
        }

        public void notifyObservers() {


Reply via email to