01: /* CVS ID: $Id: ConnectionTimer.java,v 1.1.1.1 2002/10/02 18:42:51 wastl Exp $ */
02: package net.wastl.webmail.server;
03:
04: import java.util.*;
05: import net.wastl.webmail.debug.ErrorHandler;
06: import net.wastl.webmail.exceptions.*;
07:
08: /*
09: * ConnectionTimer.java
10: *
11: * Created: Tue Feb 2 12:27:43 1999
12: *
13: * Copyright (C) 1999-2000 Sebastian Schaffert
14: *
15: * This program is free software; you can redistribute it and/or
16: * modify it under the terms of the GNU General Public License
17: * as published by the Free Software Foundation; either version 2
18: * of the License, or (at your option) any later version.
19: *
20: * This program is distributed in the hope that it will be useful,
21: * but WITHOUT ANY WARRANTY; without even the implied warranty of
22: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23: * GNU General Public License for more details.
24: *
25: * You should have received a copy of the GNU General Public License
26: * along with this program; if not, write to the Free Software
27: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28: */
29: /**
30: *
31: *
32: *
33: * @author Sebastian Schaffert
34: * @version $Revision: 1.1.1.1 $
35: */
36: public class ConnectionTimer extends Thread {
37:
38: private Vector connections;
39: private static final long sleep_interval = 1000;
40:
41: public ConnectionTimer() {
42: connections = new Vector();
43: this .start();
44: }
45:
46: public void printStatus() {
47: System.err.println(" Vulture: " + connections.size()
48: + " connections in queue");
49: }
50:
51: public void addTimeableConnection(TimeableConnection c) {
52: synchronized (connections) {
53: connections.addElement(c);
54: }
55: }
56:
57: public void removeTimeableConnection(TimeableConnection c) {
58: synchronized (connections) {
59: connections.removeElement(c);
60: }
61: }
62:
63: public void removeAll() {
64: Enumeration e;
65: synchronized (connections) {
66: e = connections.elements();
67: }
68: while (e.hasMoreElements()) {
69: TimeableConnection t = (TimeableConnection) e.nextElement();
70: t.timeoutOccured();
71: }
72: }
73:
74: public void run() {
75: Enumeration e;
76: while (true) {
77: synchronized (connections) {
78: e = connections.elements();
79: }
80: while (e.hasMoreElements()) {
81: TimeableConnection t = (TimeableConnection) e
82: .nextElement();
83: if (System.currentTimeMillis() - t.getLastAccess() > t
84: .getTimeout()) {
85: t.timeoutOccured();
86: }
87: }
88: try {
89: this .sleep(sleep_interval);
90: } catch (InterruptedException ex) {
91: new ErrorHandler(ex);
92: }
93: }
94: }
95: } // ConnectionTimer
|