KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > mirroring > archivetypes > MoveReleaseToMostFreeSlaves


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.drftpd.mirroring.archivetypes;
19
20 import java.io.FileInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 import net.sf.drftpd.event.listeners.Archive;
28 import net.sf.drftpd.master.config.FtpConfig;
29 import net.sf.drftpd.mirroring.Job;
30 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface;
31
32 import org.apache.log4j.Logger;
33 import org.drftpd.mirroring.ArchiveType;
34 import org.drftpd.sections.SectionInterface;
35
36 /**
37  * @author zubov
38  * @version $Id: MoveReleaseToMostFreeSlaves.java,v 1.3 2004/05/22 15:08:43 zubov Exp $
39  */

40 public class MoveReleaseToMostFreeSlaves extends ArchiveType {
41     private static final Logger logger = Logger.getLogger(MoveReleaseToMostFreeSlaves.class);
42     private int _numOfSlaves;
43
44     public MoveReleaseToMostFreeSlaves(Archive archive, SectionInterface section) {
45         super(archive,section);
46         Properties JavaDoc props = new Properties JavaDoc();
47         try {
48             props.load(new FileInputStream JavaDoc("conf/archive.conf"));
49         } catch (IOException JavaDoc e) {
50             throw new RuntimeException JavaDoc(e);
51         }
52         try {
53             _numOfSlaves = Integer.parseInt(FtpConfig.getProperty(props,getSection().getName() + ".numOfSlaves"));
54         } catch (NullPointerException JavaDoc e) {
55             _numOfSlaves = 1;
56         }
57     }
58
59     public void cleanup(ArrayList JavaDoc jobList) {
60         for (Iterator JavaDoc iter = jobList.iterator(); iter.hasNext();) {
61             Job job = (Job) iter.next();
62             job.getFile().deleteOthers(getRSlaves());
63         }
64     }
65
66     public HashSet JavaDoc findDestinationSlaves() {
67         HashSet JavaDoc set = _parent.getConnectionManager().getSlaveManager().findSlavesBySpace(_numOfSlaves,new HashSet JavaDoc(), false);
68         if (set.isEmpty())
69             return null;
70         return set;
71     }
72     
73     public void waitForSendOfFiles(ArrayList JavaDoc jobQueue) {
74         while (true) {
75             for (Iterator JavaDoc iter = jobQueue.iterator(); iter.hasNext();) {
76                 Job job = (Job) iter.next();
77                 if (job.isDone()) {
78                     logger.debug(
79                         "File "
80                             + job.getFile().getPath()
81                             + " is done being sent");
82                     iter.remove();
83                 }
84             }
85             try {
86                 Thread.sleep(10000);
87             } catch (InterruptedException JavaDoc e) {
88             }
89             if (jobQueue.isEmpty()) {
90                 break;
91             }
92         }
93     }
94
95     /**
96      * Returns true if this directory is Archived by this ArchiveType's definition
97      */

98
99     protected boolean isArchivedDir(LinkedRemoteFileInterface lrf)
100         throws IncompleteDirectoryException, OfflineSlaveException {
101             return isArchivedToXSlaves(lrf,_numOfSlaves);
102     }
103     public String JavaDoc toString() {
104         return "MoveReleaseToMostFreeSlaves=[directory=[" + getDirectory().getPath() + "]dest=[" + outputSlaves(getRSlaves()) + "]numOfSlaves=[" + _numOfSlaves + "]]";
105     }
106
107 }
108
Popular Tags