ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/PacketTimer.java
Revision: 1.8
Committed: Thu Mar 6 12:15:52 2003 UTC (21 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.7: +17 -7 lines
Log Message:
Bring Conient in line with new ihost changes.

Most obvious change is the addition of a new data component for
looking at IO statistics. It looks after two attributes and displays
them next to each other. Nothing fancy really, but is suitable for
paging, networking, and diskio.

Used this new IO data component to implement the above mentioned
new data types, and altered the existing disk and memory items
because of a change in the unit size.

Finally, altered the "time till next packet" counter because it
wasn't very accurate - it never seemed to get to zero. It's clock
based now, so should be spot on. Also added a funky feature to make
it go red and grow in the wrong direction when an expected packet
doesn't arrive :-)

File Contents

# User Rev Content
1 tdb 1.6 /*
2     * i-scream central monitoring system
3 tdb 1.7 * http://www.i-scream.org.uk
4 tdb 1.6 * Copyright (C) 2000-2002 i-scream
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 ajm 1.2 //---PACKAGE DECLARATION---
22 tdb 1.5 package uk.org.iscream.cms.conient;
23 ajm 1.1
24 ajm 1.2 //---IMPORTS---
25 tdb 1.8 import java.awt.Color;
26 ajm 1.1 import javax.swing.JProgressBar;
27 ajm 1.4 import javax.swing.JPanel;
28     import javax.swing.JLabel;
29     import javax.swing.BoxLayout;
30 ajm 1.1 import javax.swing.SwingUtilities;
31    
32 ajm 1.2 /**
33     * Shows a countdown timer for packet arrival times.
34     * When constructed it takes an integer value relating
35     * to the time in seconds between recieving packets.
36     *
37     * This then displays a JProgress bar which updates at
38     * 10th of a second intervals.
39     *
40 tdb 1.6 * @author $Author: tdb $
41 tdb 1.8 * @version $Id: PacketTimer.java,v 1.7 2002/05/21 16:47:10 tdb Exp $
42 ajm 1.2 */
43 ajm 1.4 public class PacketTimer extends JPanel implements Runnable {
44 ajm 1.1
45 ajm 1.2 //---FINAL ATTRIBUTES---
46    
47     /**
48     * The current CVS revision of this class
49     */
50 tdb 1.8 public static final String REVISION = "$Revision: 1.7 $";
51 ajm 1.2
52     //---STATIC METHODS---
53    
54     //---CONSTRUCTORS---
55    
56     /**
57     * Constructs a new PacketTimer
58     *
59     * @param timeBetweenPackets the time in seconds between packet arrival
60     */
61 ajm 1.4 public PacketTimer(String name, int timeBetweenPackets) {
62 tdb 1.8 _timeBetweenPackets = timeBetweenPackets * 1000;
63 ajm 1.4 _progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, _timeBetweenPackets);
64 tdb 1.8 _barColour = _progressBar.getForeground();
65 ajm 1.4 this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
66     JLabel label = new JLabel(name);
67     this.add(_progressBar);
68     this.add(label);
69 ajm 1.1 }
70 ajm 1.2
71     //---PUBLIC METHODS---
72 ajm 1.1
73 ajm 1.2 /**
74     * Updates the progress bar every 10th of a second.
75     */
76 ajm 1.1 public void run() {
77 ajm 1.2 while(_running) {
78 ajm 1.1 try {
79     Thread.sleep(100);
80     } catch (InterruptedException e) {
81     }
82    
83     SwingUtilities.invokeLater(new Runnable() {
84     public void run() {
85 tdb 1.8 long t = _nextTime - System.currentTimeMillis();
86     if(t >= 0) {
87     _progressBar.setValue((int) t);
88     }
89     else {
90     _progressBar.setValue((int) (t*-1));
91     _progressBar.setForeground(Color.red);
92     }
93 ajm 1.1 }
94     });
95     }
96     }
97    
98 ajm 1.2 /**
99     * Resets the progress bar.
100     */
101 ajm 1.1 public void reset() {
102 tdb 1.8 _nextTime = System.currentTimeMillis() + _timeBetweenPackets;
103 ajm 1.1 SwingUtilities.invokeLater(new Runnable() {
104     public void run() {
105 ajm 1.4 _progressBar.setValue(_timeBetweenPackets);
106 tdb 1.8 _progressBar.setForeground(_barColour);
107 ajm 1.1 }
108     });
109     }
110    
111 ajm 1.2 //---PRIVATE METHODS---
112    
113     //---ACCESSOR/MUTATOR METHODS---
114    
115     //---ATTRIBUTES---
116    
117     /**
118     * Holds the time between packets as used internally by this class
119     */
120 ajm 1.1 private int _timeBetweenPackets;
121 tdb 1.8 private long _nextTime;
122     private Color _barColour;
123 ajm 1.2
124     /**
125     * Used to indicate the state of the thread
126     */
127     private boolean _running = true;
128 ajm 1.4
129     private JProgressBar _progressBar;
130 ajm 1.2
131     //---STATIC ATTRIBUTES---
132    
133 ajm 1.1 }