KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
28 import org.drftpd.mirroring.ArchiveType;
29 import org.drftpd.sections.SectionInterface;
30
31 import net.sf.drftpd.ObjectNotFoundException;
32 import net.sf.drftpd.event.listeners.Archive;
33 import net.sf.drftpd.master.config.FtpConfig;
34 import net.sf.drftpd.mirroring.Job;
35 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface;
36
37 /**
38  * @author zubov
39  * @version $Id: MoveReleaseToSpecificSlaves.java,v 1.2 2004/05/20 14:09:00 zubov Exp $
40  */

41 public class MoveReleaseToSpecificSlaves extends ArchiveType {
42
43     private HashSet JavaDoc _destSlaves;
44     private static final Logger logger = Logger.getLogger(MoveReleaseToSpecificSlaves.class);
45     private int _numOfSlaves;
46     
47     public MoveReleaseToSpecificSlaves(Archive archive, SectionInterface section) {
48         super(archive,section);
49         Properties JavaDoc props = new Properties JavaDoc();
50         try {
51             props.load(new FileInputStream JavaDoc("conf/archive.conf"));
52         } catch (IOException JavaDoc e) {
53             throw new RuntimeException JavaDoc(e);
54         }
55         _destSlaves = new HashSet JavaDoc();
56         for (int i = 1;; i++) {
57             String JavaDoc slavename = null;
58             try {
59                 slavename = FtpConfig.getProperty(props, getSection().getName() + ".slavename." + i);
60             } catch (NullPointerException JavaDoc e) {
61                 _numOfSlaves = i-1;
62                 break; // done
63
}
64             try {
65                 _destSlaves.add(_parent.getConnectionManager().getSlaveManager().getSlave(slavename));
66             } catch (ObjectNotFoundException e) {
67                 logger.debug("Unable to get slave " + slavename + " from the SlaveManager");
68             }
69         }
70         if (_destSlaves.isEmpty()) {
71             throw new NullPointerException JavaDoc("Cannot continue, 0 destination slaves found for MoveReleaseToSpecificSlave for section " + getSection().getName());
72         }
73     }
74
75     public HashSet JavaDoc findDestinationSlaves() {
76         return _destSlaves;
77     }
78
79     public void cleanup(ArrayList JavaDoc jobList) {
80         for (Iterator JavaDoc iter = jobList.iterator(); iter.hasNext();) {
81             Job job = (Job) iter.next();
82             job.getFile().deleteOthers(getRSlaves());
83         }
84     }
85
86     protected boolean isArchivedDir(LinkedRemoteFileInterface lrf)
87     throws IncompleteDirectoryException, OfflineSlaveException {
88         return isArchivedToXSlaves(lrf,_numOfSlaves);
89     }
90     
91     public void waitForSendOfFiles(ArrayList JavaDoc jobQueue) {
92         while (true) {
93             for (Iterator JavaDoc iter = jobQueue.iterator(); iter.hasNext();) {
94                 Job job = (Job) iter.next();
95                 if (job.isDone()) {
96                     logger.debug(
97                         "File "
98                             + job.getFile().getPath()
99                             + " is done being sent");
100                     iter.remove();
101                 }
102             }
103             try {
104                 Thread.sleep(10000);
105             } catch (InterruptedException JavaDoc e) {
106             }
107             if (jobQueue.isEmpty()) {
108                 break;
109             }
110         }
111     }
112     public String JavaDoc toString() {
113         return "MoveReleaseToSpecificSlaves=[directory=[" + getDirectory().getPath() + "]dest=[" + outputSlaves(getRSlaves()) + "]numOfSlaves=[" + _numOfSlaves + "]]";
114     }
115 }
116
Popular Tags