KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > slave > socket > SocketSlaveManager


1 /*
2  * SocketSlaveManager.java
3  *
4  * Created on April 20, 2004, 2:42 PM
5  */

6
7 package org.drftpd.slave.socket;
8
9 import java.rmi.RemoteException JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Hashtable JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Properties JavaDoc;
14
15 import net.sf.drftpd.master.ConnectionManager;
16 import net.sf.drftpd.master.RemoteSlave;
17 /**
18  *
19  * @author jbarrett
20  */

21 public class SocketSlaveManager extends java.lang.Thread JavaDoc {
22     
23     private ConnectionManager _conman;
24     private String JavaDoc _serverName;
25     private String JavaDoc _socketPass;
26     private int _socketPort;
27     
28     /** Creates a new instance of SocketSlaveManager */
29     public SocketSlaveManager(ConnectionManager conman, Properties JavaDoc cfg) {
30         _conman = conman;
31     _serverName = cfg.getProperty("master.bindname", "slavemaster");
32     _socketPass = cfg.getProperty("master.socketpass", "");
33     _socketPort = Integer.parseInt(cfg.getProperty("master.socketport", "1100"));
34         start();
35     }
36     
37     public void run()
38     {
39         SocketSlaveListener ssl = new SocketSlaveListener(_conman, _socketPort, _socketPass);
40         
41         while (true) {
42             Collection JavaDoc slaves = _conman.getSlaveManager().getSlaves();
43             for (Iterator JavaDoc i=slaves.iterator(); i.hasNext();) {
44                 RemoteSlave rslave = (RemoteSlave)i.next();
45                 Hashtable JavaDoc cfg = rslave.getConfig();
46                 if (rslave.isAvailable()) continue;
47                 if (cfg.get("addr") == null) continue;
48                 String JavaDoc host = (String JavaDoc)cfg.get("addr");
49                 if (host.equals("Dynamic")) continue;
50                 // unconnected socket slave, try to connect
51
try {
52                     SocketSlaveImpl tmp = new SocketSlaveImpl(_conman, rslave.getConfig());
53                 } catch (RemoteException JavaDoc e) {
54                 }
55             }
56             try {
57                 sleep(60000);
58             } catch (Exception JavaDoc e) {}
59         }
60     }
61     
62 }
63
Popular Tags