package therm;
import java.lang.Thread;
import java.rmi.*;
public class ThermApplication implements Runnable
{
// Create Thermometer object
Thermometer T;
public ThermApplication( Thermometer T )
{
this.T = T;
}
public static void main( String arg[] )
{
try
{
// Create and install a security manager
// System.out.println( "ThermApplication: installing security mgr");
System.setSecurityManager( new RMISecurityManager() );
Thermometer T = new ThermometerImpl( "Thermometer RMI Demo",0,100,33);
// Bind the thermometer obj to the remote registry.
System.out.println( "Registrying thermometer w RMIregistry");
Naming.rebind( "thermometer", T );
ThermApplication ta = new ThermApplication( T );
Thread animatorThread = new Thread( ta );
animatorThread.start();
} catch (Exception e)
{
System.out.println( "An exception occurred." );
e.printStackTrace();
System.out.println(e.getMessage());
}
}
public void run()
{
System.out.println( "Enter ThermApplication: run()" +
" and wait for 10 secs for observers." );
try{ Thread.sleep(10000); } // Wait for observers to start
catch(InterruptedException e)
{
System.out.println(e);
System.exit(1);
}
System.out.println( "Continuing ThermApplication: run()" );
try
{
T.setTitle("Boy, it's sweltering!");
}
catch (RemoteException e)
{}
for (int i = 91; i > 0; i--)
{
try{ Thread.sleep(500); }
catch(InterruptedException e)
{System.out.println(e);
System.exit(1);
}
try{
T.setTemp(i);
}
catch (RemoteException e)
{}
switch (i)
{
case 10: try{
T.setTitle("Baby, its cold outside!");
}
catch (RemoteException e)
{}
break;
case 32: try{
T.setTitle("It's a cool day.");
}
catch (RemoteException e)
{}
break;
case 65: try{
T.setTitle("It's a nice day.");
}
catch (RemoteException e)
{}
break;
case 80: try{
T.setTitle("It's cooling off!");
}
catch (RemoteException e)
{}
break;
case 90: try{
T.setTitle("Boy, it's sweltering!");
}
catch (RemoteException e)
{}
break;
default:
}
}
}
}