FileDocCategorySizeDatePackage
NetPanel.javaAPI DocExample4656Sat Mar 13 18:17:04 GMT 2004None

NetPanel

public abstract class NetPanel extends JPanel implements Runnable
Displays one machines status. Part of the NetWatch program: watch the network on a bunch of machines (i.e., in a classroom or lab).

Each non-abstract subclass just needs to implement run(), which must, in a while (!done) loop:

  • Try to contact the host
  • call setState(); (argument below)
  • call ta.setText();
  • Thread.sleep(sleepTime * MSEC);

The argument to setState() must be one of:

  • FINE == Server has "expect"ed name registered.
  • DUBIOUS == Server does not have expected name registered.
  • EMPTY == Server has nothing registered.
  • NOREG == host is up but not running RMI
  • DOWN == host unreachable, not responding, ECONN, etc.
author
Ian F. Darwin, http://www.darwinsys.com/ Copyright (c) 2000, Ian F. Darwin. See LEGAL.NOTICE for licensing.
version
$Id: NetPanel.java,v 1.4 2004/03/14 00:17:03 ian Exp $

Fields Summary
protected String
hostName
The name of this host
protected JTextArea
ta
The text area to display a list of stuff
protected Properties
props
Properties, passed in to constructor
protected static int
DEFAULT_SLEEP
Default sleep time, in seconds.
protected int
sleepTime
Sleep time, in seconds.
protected int
MSEC
Conversion
protected static Font
cwFont
The constant-width font, shared by all instances.
protected static final int
FINE
The state for: has "expect"ed name registered.
protected static final int
DUBIOUS
The state for: does not have expected name registered.
protected static final int
EMPTY
The state for: Server has nothing registered.
protected static final int
NOREG
The state for: host is up but not running RMI
protected static final int
DOWN
The state for: host unreachable, not responding, ECONN, etc.
protected static final Color
COLOR_FINE
The color for when a machine is FINE
protected static final Color
COLOR_DUBIOUS
The color for when a machine is DUBIOUS
protected static final Color
COLOR_EMPTY
The color for when a machine is EMPTY
protected static final Color
COLOR_NOREG
The color for when a machine has NOREG
protected static final Color
COLOR_DOWN
The color for when a machine is NOREG
protected int
state
State of the monitored hosts RMI registry, up or down. Initially set 0, which isnt one of the named states, to force the background color to be set on the first transition.
boolean
done
Constructors Summary
public NetPanel(String host, Properties p)

	
	     
		hostName = host;
		props = p;
		String s = props.getProperty("rmiwatch.sleep");
		if (s != null)
			sleepTime = Integer.parseInt(s);
		// System.out.println("Sleep time now " + sleepTime);

		// Maybe get font name and size from props?
		if (cwFont == null)
			cwFont = new Font("lucidasansTypewriter", Font.PLAIN, 10);

		// Gooey gooey stuff.
		ta = new JTextArea(2, 26);
		ta.setEditable(false);
		ta.setFont(cwFont);
		add(BorderLayout.CENTER, ta);
		setBorder(BorderFactory.createTitledBorder(hostName));

		// Sparks. Ignition!
		new Thread(this).start();
	
Methods Summary
protected voidsetState(int newState)
Record the new state of the current machine. If this machine has changed state, set its color

param
newState - one of the five valid states in the introduction.

		if (state /*already*/ == newState)
			return;		// nothing to do.
		switch(newState) {
			case FINE:		// Server has "expect"ed name registered.
				ta.setBackground(COLOR_FINE);
				ta.setForeground(Color.black);
				break;
			case DUBIOUS:	// Server does not have expected name registered.
				ta.setBackground(COLOR_DUBIOUS);
				ta.setForeground(Color.black);
				break;
			case EMPTY:		// Server has nothing registered.
				ta.setBackground(COLOR_EMPTY);
				ta.setForeground(Color.black);
				break;
			case NOREG:		// host is up but not running RMI
				ta.setBackground(COLOR_NOREG);
				ta.setForeground(Color.white);
				break;
			case DOWN:		// host unreachable, not responding, ECONN, etc.
				ta.setBackground(COLOR_DOWN);
				ta.setForeground(Color.white);
				break;
			default:
				throw new IllegalStateException("setState("+state+") invalid");
			}
		state = newState;
	
public voidstop()
Stop this Thread

	    
	   
		done = true;