KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > usermanager > ResetMonthlyStats


1 /*
2  * Created on Jun 1, 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.drftpd.usermanager;
8
9 import java.io.FileInputStream JavaDoc;
10 import java.lang.reflect.Field JavaDoc;
11 import java.lang.reflect.Method JavaDoc;
12 import java.util.Date JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Properties JavaDoc;
15
16 import net.sf.drftpd.master.ConnectionManager;
17 import net.sf.drftpd.master.usermanager.AbstractUser;
18 import net.sf.drftpd.slave.SlaveImpl;
19
20 import org.apache.log4j.BasicConfigurator;
21
22 /**
23  * @author mog
24  * @version $Id: ResetMonthlyStats.java,v 1.2 2004/06/02 00:32:43 mog Exp $
25  */

26 public class ResetMonthlyStats {
27
28     public ResetMonthlyStats() {
29         super();
30     }
31
32     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
33         System.out.println(SlaveImpl.VERSION + " resetmonth starting.");
34         System.out.println("All your sites are belong to mog ^^");
35         System.out.println("http://drftpd.org/");
36         BasicConfigurator.configure();
37         String JavaDoc cfgFileName;
38         if (args.length >= 1) {
39             cfgFileName = args[0];
40         } else {
41             cfgFileName = "drftpd.conf";
42         }
43
44         /** load master config **/
45         Properties JavaDoc cfg = new Properties JavaDoc();
46         cfg.load(new FileInputStream JavaDoc(cfgFileName));
47
48         CM cm = new CM(cfg, cfgFileName);
49         cm.getUserManager().getAllUsers();
50         Method JavaDoc m =
51             AbstractUser.class.getDeclaredMethod(
52                 "resetMonth",
53                 new Class JavaDoc[] { ConnectionManager.class, Date JavaDoc.class });
54         m.setAccessible(true);
55
56         Field JavaDoc f = AbstractUser.class.getDeclaredField("lastReset");
57         f.setAccessible(true);
58
59         for (Iterator JavaDoc iter = cm.getUserManager().getAllUsers().iterator();
60             iter.hasNext();
61             ) {
62             AbstractUser user = (AbstractUser) iter.next();
63             f.setLong(user, System.currentTimeMillis());
64             //user.resetMonth(cm, new Date())
65
m.invoke(user, new Object JavaDoc[] { cm, new Date JavaDoc()});
66             user.commit();
67         }
68         f.setAccessible(false);
69         m.setAccessible(false);
70     }
71
72     public static class CM extends ConnectionManager {
73         public CM(Properties JavaDoc cfg, String JavaDoc cfgFileName) {
74             loadUserManager(cfg, cfgFileName);
75             loadPlugins(cfg);
76         }
77     }
78 }
79
Popular Tags