1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20
21 package ui.util;
22
23 import java.util.Date;
24 import java.util.Timer;
25 import java.util.TimerTask;
26
27 import org.apache.log4j.Logger;
28
29 import ui.Messages;
30 import base.ConfigurationManager;
31
32 public class LogoutDaemon {
33
34 private static final transient Logger logger = Logger
35 .getLogger(LogoutDaemon.class.getName());
36
37 private int seconds = 60;
38
39 private Timer timer;
40
41 public LogoutDaemon(int seconds) {
42 this.seconds = seconds;
43 timer = new Timer();
44 int scheduleTime = ConfigurationManager.getInstance()
45 .getLogoutScheduleRate() * 1000;
46 logger.debug("Logout Schedule Time :" + scheduleTime / 1000 + Messages.getString("common.unit.second"));
47 timer.scheduleAtFixedRate(new LogoutTask(), 0, ConfigurationManager
48 .getInstance().getLogoutScheduleRate() * 1000);
49 }
50
51 class LogoutTask extends TimerTask {
52 public void run() {
53 Date currentDate = new Date();
54 if (ConfigurationManager.getInstance().getLastSeenUserWorking()
55 .getTime()
56 + seconds * 1000 < currentDate.getTime()
57 && !ConfigurationManager.getInstance()
58 .getServerLoginDialog().isVisible()
59 && ConfigurationManager.getInstance().isPasswordProtect()) {
60 logger.debug(Messages.getString("message.logoutsuccess"));
61 ConfigurationManager.getInstance().getServerLoginDialog()
62 .setVisible(true);
63 }
64 }
65 }
66
67 public static void main(String args[]) {
68 new LogoutDaemon(5);
69 System.out.format("Task scheduled.%n");
70 }
71
72 }