001         package com.croftsoft.apps.vaft.app;
002    
003         import java.io.*;
004         import java.net.MalformedURLException;
005         import java.rmi.*;
006         import java.util.*;
007    
008         import com.croftsoft.apps.vaft.core.*;
009         import com.croftsoft.apps.vaft.security.HostSecurityManager;
010         import com.croftsoft.core.net.http.WebServer;
011    
012         /*********************************************************************
013         * <P>
014         * @author
015         *   <A HREF="http://www.alumni.caltech.edu/~croft">David W. Croft</A>
016         * @version
017         *   2000-04-30
018         *********************************************************************/
019    
020         public class  VAFT
021         //////////////////////////////////////////////////////////////////////
022         //////////////////////////////////////////////////////////////////////
023         {
024    
025         private static final String  CODEBASE_PROPERTY
026           = "java.rmi.server.codebase";
027    
028         private Config        config;
029         private WebServer     webServer;
030         private Host          host;
031    
032         //////////////////////////////////////////////////////////////////////
033         //////////////////////////////////////////////////////////////////////
034    
035         public static void  main ( String [ ]  args )
036           throws AlreadyBoundException,
037                  MalformedURLException,
038                  RemoteException,
039                  UnknownHostException
040         //////////////////////////////////////////////////////////////////////
041         {
042           System.setSecurityManager ( new HostSecurityManager ( ) );
043    
044           Config  config = Config.parse ( args, System.out );
045           if ( config == null ) return;
046    
047           if ( config.getUse_control_panel ( ) )
048             new ControlPanel ( config );
049           else
050             new VAFT ( config );
051         }
052    
053         //////////////////////////////////////////////////////////////////////
054         //////////////////////////////////////////////////////////////////////
055    
056         protected  VAFT ( Config  config )
057           throws AlreadyBoundException,
058                  MalformedURLException,
059                  RemoteException,
060                  UnknownHostException
061         //////////////////////////////////////////////////////////////////////
062         {
063           this.config = config;
064           start_WebServer ( );
065           start_Host      ( );
066         }
067    
068         //////////////////////////////////////////////////////////////////////
069         //////////////////////////////////////////////////////////////////////
070    
071         protected WebServer  getWebServer ( ) { return webServer; }
072         protected Host       getHost      ( ) { return host;      }
073    
074         //////////////////////////////////////////////////////////////////////
075         //////////////////////////////////////////////////////////////////////
076    
077         protected void  start_WebServer ( )
078         //////////////////////////////////////////////////////////////////////
079         {
080           Properties  properties = System.getProperties ( );
081           String  codebase
082             = "http://" + config.getWeb_server_name ( ) + ":"
083             + config.getWeb_server_port ( ) + "/";
084           properties.put ( CODEBASE_PROPERTY, codebase );
085           this.webServer = new WebServer (
086             config.getWeb_server_root ( ),
087             config.getWeb_server_port ( ) );
088           new Thread ( webServer ).start ( );
089         }
090    
091         protected void  start_Host ( )
092           throws AlreadyBoundException,
093                  MalformedURLException,
094                  RemoteException,
095                  UnknownHostException
096         //////////////////////////////////////////////////////////////////////
097         {
098           HostInfo  self = new HostInfo (
099             config.getRmi_server_name ( ),
100             config.getRmi_server_port ( ),
101             config.getRmi_object_name ( ),
102             new String [ ] { "com.orbs.pub.app.agent.vaft.core.SwapRemote" }
103             );
104    
105           HostList  hostList = new HostList (
106             self, config.createSeed ( ), config.getSwap_delay ( ) );
107    
108           // null password
109           host = Host.bind_Host (
110             config.getRmi_object_name ( ), null, hostList );
111         }
112    
113         protected void  shutdown ( )
114         //////////////////////////////////////////////////////////////////////
115         {
116           try { host.shutdown ( null ); } catch ( Exception  e ) { }
117           try { webServer.shutdown ( ); } catch ( Exception  e ) { }
118         }
119    
120         //////////////////////////////////////////////////////////////////////
121         //////////////////////////////////////////////////////////////////////
122         }