KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > system > UpdateDaemon


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

16 package net.sf.jftp.system;
17
18 import net.sf.jftp.JFtp;
19 import net.sf.jftp.config.Settings;
20 import net.sf.jftp.gui.*;
21 import net.sf.jftp.gui.base.LocalDir;
22 import net.sf.jftp.gui.base.RemoteDir;
23 import net.sf.jftp.util.*;
24
25
26 public class UpdateDaemon implements Runnable JavaDoc
27 {
28     private static int rem;
29     private static int loc;
30     private static int log;
31     private static int reg;
32     private static int cal;
33     private Thread JavaDoc runner = null;
34     private JFtp jftp;
35
36     public UpdateDaemon(JFtp jftp)
37     {
38         this.jftp = jftp;
39
40         runner = new Thread JavaDoc(this);
41         runner.start();
42     }
43
44     public static void updateRemoteDirGUI()
45     {
46         //System.out.print("+");
47
reg++;
48     }
49
50     public static void updateRemoteDir()
51     {
52         //System.out.print("-");
53
rem++;
54     }
55
56     public static void updateLocalDir()
57     {
58         //System.out.print("#");
59
loc++;
60     }
61
62     public static void updateLog()
63     {
64         //System.out.print(".");
65
log++;
66     }
67
68     public static void updateCall()
69     {
70         cal++;
71     }
72
73     public void run()
74     {
75         while(true)
76         {
77             try
78             {
79                 //System.out.print(":");
80
if(rem > 0)
81                 {
82                     ((RemoteDir) jftp.remoteDir).fresh();
83
84                     //System.out.print("R");
85
rem = 0;
86                     Thread.sleep(100);
87                 }
88
89                 if(reg > 0)
90                 {
91                     ((RemoteDir) jftp.remoteDir).gui(true);
92
93                     //System.out.print("r");
94
reg = 0;
95                     Thread.sleep(100);
96                 }
97
98                 if(loc > 0)
99                 {
100                     ((LocalDir) jftp.localDir).fresh();
101
102                     //System.out.print("L");
103
loc = 0;
104                     Thread.sleep(100);
105                 }
106
107                 if(cal > 0)
108                 {
109                     jftp.fireUpdate();
110                     cal = 0;
111                     Thread.sleep(100);
112                 }
113
114                 if(log > 0)
115                 {
116                     jftp.ensureLogging();
117
118                     //System.out.print("O");
119
log = 0;
120                     Thread.sleep(500);
121                 }
122
123                 Thread.sleep(Settings.uiRefresh);
124             }
125             catch(Exception JavaDoc ex)
126             {
127                 ex.printStackTrace();
128                 System.exit(1);
129             }
130         }
131     }
132 }
133
Popular Tags