Methods Summary |
---|
public synchronized void | addTemperaturePulseListener(TemperaturePulseListener l)
// if there is already a listener, throw an exception
if (listener != null)
{
throw new TooManyListenersException();
}
// store the listener
listener = l;
|
public int | getRate()
return rate;
|
public boolean | isRunning()
return running;
|
private void | readObject(java.io.ObjectInputStream stream)
try
{
// defer to the default process
stream.defaultReadObject();
// read back the listener
Object obj = stream.readObject();
addTemperaturePulseListener((TemperaturePulseListener)obj);
// start the pulse thread
startThread();
}
catch (Exception e)
{
System.out.println(e);
}
|
public synchronized void | removeTemperaturePulseListener(TemperaturePulseListener l)
// make sure this is the listener we have
if (listener == l)
{
listener = null;
}
|
public void | run()
// loop forever
while(true)
{
try
{
// sleep for the time specified by rate
thrd.sleep(rate);
// if there is a listener and the service is running, then
// send the pulse event
if (listener != null && running)
{
listener.temperaturePulse(new TemperaturePulseEvent(this, temp));
}
}
catch (Exception e)
{
}
}
|
public void | setRate(int r)
rate = r;
|
public synchronized void | setRunning(boolean b)
// don't bother if there is no change
if (running == b)
{
return;
}
// save the new value
running = b;
// set the appropriate label text and background color
if (running)
{
setText(onText);
setBackground(onColor);
}
else
{
setText(offText);
setBackground(offColor);
}
|
private void | startThread()
// create and start the pulse thread
thrd = new Thread(this);
thrd.start();
|
private void | writeObject(java.io.ObjectOutputStream stream)
// defer to the default process
stream.defaultWriteObject();
// get a copy
TemperaturePulseListener lstnr = null;
synchronized (this)
{
lstnr = listener;
}
boolean bWriteNull = (lstnr == null);
if (!bWriteNull)
{
// is it serializable?
if (lstnr instanceof Serializable)
{
stream.writeObject(lstnr);
}
else
{
// write a null to the stream
bWriteNull = true;
}
}
// should we write a null?
if (bWriteNull)
{
stream.writeObject(null);
}
|