User: user57  
  Date: 02/02/22 00:00:45

  Added:       src/main/org/jboss/system/server Server.java
                        ServerConfig.java ServerImpl.java ServerLoader.java
                        package.html
  Log:
   o basic ServerLoader completed
   o still need to fix up ServerImpl (much) and adapting a ServerConfigImpl
     to adapt property style config to typed style
  
  Revision  Changes    Path
  1.1                  jboss-system/src/main/org/jboss/system/server/Server.java
  
  Index: Server.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.system.server;
  
  import java.util.Map;
  
  /**
   * The interface of the basic JBoss server component.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public interface Server
  {
     /**
      * Initialize the Server instance.
      *
      * @param props     The configuration properties for the server.
      * @return          Typed server configuration object.
      *
      * @throws IllegalStateException    Already initialized.
      * @throws Exception                Failed to initialize.
      */
     void init(Map props) throws IllegalStateException, Exception;
  
     /**
      * Get the typed server configuration object which the
      * server has been initalized to use.
      *
      * @return          Typed server configuration object.
      *
      * @throws IllegalStateException    Not initialized.
      */
     ServerConfig getConfig() throws IllegalStateException;
  
     /**
      * Start the Server instance.
      *
      * @throws IllegalStateException    Already started or not initialized.
      * @throws Exception                Failed to start.
      */
     void start() throws IllegalStateException, Exception;
  
     /**
      * Shutdown the Server instance.
      *
      * @throws IllegalStateException    No started.
      * @throws Exception                Failed to shutdown.
      */
     void shutdown() throws IllegalStateException, Exception;
  
     /**
      * Check if the server is started.
      *
      * @return   True if the server is started, else false.
      */
     boolean isStarted();
  
  }
  
  
  
  1.1                  jboss-system/src/main/org/jboss/system/server/ServerConfig.java
  
  Index: ServerConfig.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.system.server;
  
  import java.io.File;
  
  import java.net.URL;
  
  /**
   * The interface of the basic <em>typed</em> JBoss server configuration.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public interface ServerConfig
  {
     /////////////////////////////////////////////////////////////////////////
     //                   Configuration Value Identifiers                   //
     /////////////////////////////////////////////////////////////////////////
  
      /**
       * Constant that holds the name of the environment property
       * for specifying a comma seperated list of the basenames of 
       * to the boot libraries required load the core system.
       *
       * <p>These libraries will be loaded from <tt>LIBRARY_URL</tt>.
       */
     String BOOT_LIBRARY_LIST = "org.jboss.system.server.boot.library.list";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the class type of the server to create.
       */
     String SERVER_TYPE = "org.jboss.system.server.type";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the home directory for JBoss.  
       *
       * <p>If not set then the value of <tt>user.home</tt> will be used.
       */
     String HOME_DIR = "org.jboss.system.server.home.dir";
     
      /**
       * Constant that holds the name of the environment property
       * for specifying the directory which JBoss will use for
       * temporary file storage.
       *
       * <p>If not set then the value of <tt><em>HOME_DIR</em>/tmp</tt> 
       *    will be used.
       */
     String TEMP_DIR = "org.jboss.system.server.temp.dir";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the directory which JBoss will use for
       * persistent data file storage.
       *
       * <p>If not set then the value of <tt><em>HOME_DIR</em>/db</tt> 
       *    will be used.
       */
     String DATA_DIR = "org.jboss.system.server.data.dir";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the base URL which JBoss will use.
       */
     String INSTALL_URL = "org.jboss.system.server.install.url";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the base URL from which JBoss will read it's 
       * configuration from.
       *
       * <p>If not set then the value of <tt><em>INSTALL_URL</em>/conf</tt> 
       *    will be used.
       */
     String CONFIG_URL = "org.jboss.system.server.config.url";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the name of the configuration which JBoss
       * will read from under <tt>CONFIG_URL</tt>.
       *
       * <p>If not set then the value of <tt>default</tt> 
       *    will be used.
       */
     String CONFIG_NAME = "org.jboss.system.server.confign.ame";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the URL where JBoss will read library files
       * from.
       *
       * <p>If not set then the value of <tt><em>INSTALL_URL</em>/lib</tt> 
       *    will be used.
       */
     String LIBRARY_URL = "org.jboss.system.server.library.url";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying the URL where JBoss will read patch library files
       * from.
       *
       * <p>If not set then the no patch files will be loaded.
       */
     String PATCH_URL = "org.jboss.system.server.patch.url";
  
      /**
       * Constant that holds the name of the environment property
       * for specifying whether or not the server should exit the
       * JVM on shutdown.
       *
       * <p>If not set then the server will default to exiting on shutdown.
       */
     String EXIT_ON_SHUTDOWN = "org.jboss.system.server.exitonshutdown";
  
  
     /////////////////////////////////////////////////////////////////////////
     //                         Typed Access Methods                        //
     /////////////////////////////////////////////////////////////////////////
  
     /**
      * Get the configuration name of the server.
      *
      * @return    The configuration name of the server.
      */
     String getConfigName();
  
     /**
      * Get the local home directory which the server is running from.
      *
      * @return    The local server home directory.
      */
     File getHomeDir();
  
     /**
      * Get the directory where temporary files will be stored.
      *
      * @return    The directory where the server stores temporary files.
      */
     File getTempDir();
  
     /**
      * Get the directory where local data will be stored.
      *
      * @return    The directory where the server stores local data.
      */
     File getDataDir();
     
     /**
      * Get the installation URL for the server.
      *
      * @return    The installation URL for the server.
      */
     URL getInstallURL();
     
     /**
      * Get the library URL for the server.
      *
      * @return    The library URL for the server.
      */
     URL getLibraryURL();
     
     /**
      * Get the configuration URL for the server.
      *
      * @return    The configuration URL for the server.
      */
     URL getConfigURL();
     
     /**
      * Get the patch URL for the server.
      *
      * @return    The patch URL for the server.
      */
     URL getPatchURL();
     
     /**
      * Enable or disable exiting the JVM when {@link #shutdown} is called.
      * If enabled, then shutdown calls {@link #exit}.  If disabled, then
      * only the shutdown hook will be run.
      *
      * @param flag    True to enable calling exit on shutdown.
      */
     void setExitOnShutdown(boolean flag);
  
      /**
       * Get the current value of the exit on shutdown flag.  Default value is
       * false, though it will be set to true when bootstrapped with 
       * {@link org.jboss.Main}.
       *
       * @return    The current value of the exit on shutdown flag.
       */
     boolean getExitOnShutdown();
  
  }
  
  
  
  1.1                  jboss-system/src/main/org/jboss/system/server/ServerImpl.java
  
  Index: ServerImpl.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.system.server;
  
  import java.util.Map;
  
  /**
   * The default (and probably only) {@link Server} implementation.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class ServerImpl
     implements Server
  {
     protected boolean started;
     protected ServerConfig config;
  
     /**
      * Required no-args constructor for {@link ServerLoader}.
      */
     public ServerImpl()
     {
        super();
     }
  
     /**
      * Initialize the Server instance.
      *
      * @param props    The configuration properties for the server.
      *
      * @throws IllegalStateException    Already initialized.
      * @throws Exception                Failed to initialize.
      */
     public void init(Map props) throws IllegalStateException, Exception 
     {
        System.out.println("Init: " + props);
        // config = new ServerConfig() {};
     }
  
     /**
      * Get the typed server configuration object which the
      * server has been initalized to use.
      *
      * @return          Typed server configuration object.
      *
      * @throws IllegalStateException    Not initialized.
      */
     public ServerConfig getConfig() throws IllegalStateException
     {
        return config;
     }
  
     /**
      * Start the Server instance.
      *
      * @throws IllegalStateException    Already started or not initialized.
      * @throws Exception                Failed to start.
      */
     public void start() throws IllegalStateException, Exception 
     {
        System.out.println("Start");
     }
  
     /**
      * Shutdown the Server instance.
      *
      * @throws IllegalStateException    No started.
      * @throws Exception                Failed to shutdown.
      */
     public void shutdown() throws IllegalStateException, Exception 
     {
        System.out.println("shutdown");
     }
  
     /**
      * Check if the server is started.
      *
      * @return   True if the server is started, else false.
      */
     public boolean isStarted()
     {
        return started;
     }
  }
  
  
  
  1.1                  jboss-system/src/main/org/jboss/system/server/ServerLoader.java
  
  Index: ServerLoader.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.system.server;
  
  import java.util.Map;
  import java.util.StringTokenizer;
  import java.util.List;
  import java.util.LinkedList;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.net.MalformedURLException;
  
  /**
   * A helper class to load a JBoss server instance.
   *
   * <p>Basic usage is something like this:
   * <pre>
   *    // setup the basic server config properties
   *    Map props = new HashMap();
   *    props.put(ServerConfig.LIBRARY_URL, "http://myserver.com/myjboss/lib/";);
   *    // set some more properties
   *
   *    // create a new loader to do the dirty work
   *    ServerLoader loader = new ServerLoader(props);
   *
   *    // add the jaxp library to use
   *    loader.addBootLibrary("crimson.jar");
   *
   *    // load and initialize the server instance
   *    Server server = loader.load();
   *    server.init(props);
   *
   *    // start up the server
   *    server.start();
   *
   *    // go make some coffee, drink a beer or play GTA3
   *    // ...
   *
   *    // shutdown and go to sleep
   *    server.shutdown();
   * </pre>
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class ServerLoader
  {
     /** 
      * The default list of boot libraries.  Does not include
      * the JAXP impl, users of this class should append the 
      * proper jar to this list.
      */
     public static final String DEFUALT_BOOT_LIBRARY_LIST = 
"jaxp.jar,jmxri.jar,jboss-common.jar,jboss-system.jar";
  
     /** The default server type. */
     public static final String DEFAULT_SERVER_TYPE = 
"org.jboss.system.server.ServerImpl";
  
     /** 
      * Map of configuration properties.
      *
      * <p>Required unset values will be read from System properties
      *    else defaults will be used if applicable.
      */
     protected Map props;
  
     /**
      * The URL where libraries are read from.
      */
     protected URL libraryURL;
  
     /**
      * A list of extra library file names to load from the library 
      * URL in addition to the list specified in the configuration
      * properties.
      */
     protected List extraBootLibraries = new LinkedList();
  
     /**
      * Construct a <tt>ServerLoader</tt>.  The properties map
      * passed in must contain a value for {@link ServerConfig.INSTALL_URL}
      * or {@link ServerConfig.LIBRARY_URL} at the very minimum for the 
      * loader to function.  Other values may be required by the server 
      * implementation as well.
      *
      * @param props    Configuration properties.
      *
      * @throws Exception    Invalid configuration
      */
     public ServerLoader(final Map props) throws Exception
     {
        if (props == null)
           throw new IllegalArgumentException("props is null");
  
        this.props = props;
  
        libraryURL = getURL(ServerConfig.LIBRARY_URL, null);
  
        if (libraryURL == null) {
           // must have install url, or we can't continue
           URL installURL = getURL(ServerConfig.INSTALL_URL, null);
           if (installURL == null)
              throw new Exception("Missing configuration value for: " + 
ServerConfig.INSTALL_URL);
  
           // need libraray url to make boot urls list
           libraryURL = new URL(installURL, "lib");
        }
     }
  
     /**
      * Add an extra boot library to the end of list of libraries
      * which will be loaded from the library URL when loading
      * the Server class.
      *
      * @param filename   A filename (no directory parts)
      *
      * @throws MalformedURLException   Could not generate URL from library URL + 
filename
      */
     public void addBootLibrary(String filename) throws MalformedURLException
     {
        if (filename == null)
           throw new IllegalArgumentException("filename is null");
  
        extraBootLibraries.add(new URL(libraryURL, filename));
     }
  
     /**
      * Load a {@link Server} instance.
      *
      * @return    An uninitialized (and unstarted) Server instance.
      *
      * @throws Exception   Failed to load or create Server instance.
      */
     public Server load() throws Exception
     {
        // get the boot lib list
        URL[] urls = getBootLibraryList(libraryURL);
        URLClassLoader classLoader = 
           new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
  
        // construct a new Server instance
        String typename = readValue(ServerConfig.SERVER_TYPE, DEFAULT_SERVER_TYPE);
        Server server = createServer(typename, classLoader);
  
        // thats all folks, have fun
        return server;
     }
  
     /**
      * Get a URL from configuration or system properties.
      */
     protected URL getURL(final String name, final URL defaultValue) throws 
MalformedURLException
     {
        String value = readValue(name, null);
        if (value != null)
           return new URL(value);
        return defaultValue;
     }
  
     /**
      * Retruns an array of URLs which will be used to load the
      * core system and construct a new Server object instance.
      */
     protected URL[] getBootLibraryList(final URL libraryURL) throws 
MalformedURLException
     {
        String value = readValue(ServerConfig.BOOT_LIBRARY_LIST, 
DEFUALT_BOOT_LIBRARY_LIST);
  
        List list = new LinkedList();
        StringTokenizer stok = new StringTokenizer(value.toString(), ",");
        while (stok.hasMoreElements()) {
           URL url = new URL(libraryURL, stok.nextToken());
           list.add(url);
        }
        
        list.addAll(extraBootLibraries);
        System.out.println(list);
  
        return (URL[])list.toArray(new URL[list.size()]);
     }
  
     /**
      * Read a value from configuration.  Consults System properties
      * if the key is not in our own config. 
      */
     protected String readValue(final String name, String defaultValue)
     {
        String value = (String)props.get(name);
        if (value == null)
           return value = System.getProperty(name, defaultValue);
        return value;
     }
  
     /**
      * Construct a new instance of Server, loading all required classes from
      * the given ClossLoader.
      */
     protected Server createServer(final String typename, final ClassLoader 
classLoader) throws Exception
     {
        // load the class first
        Class type = classLoader.loadClass(typename);
  
        // and then create a new instance
        Server server = (Server)type.newInstance();
        
        // here ya go
        return server;
     }
  }
  
  
  
  1.1                  jboss-system/src/main/org/jboss/system/server/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
    <head>
      <!-- $Id: package.html,v 1.1 2002/02/22 08:00:45 user57 Exp $ -->
      <!--
  
      JBoss: The OpenSource J2EE WebOS 
  
      Distributable under LGPL license.
      See terms of license at gnu.org.
  
      -->
    </head>
  
    <body bgcolor="white">
      <p>Core server and loading support.
  
      <h2>Package Specification</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
        
      <h2>Related Documentation</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
  
      <h2>Package Status</h2>
      <ul>
        <li><font color="green"><b>STABLE</b></font>
      </ul>
  
      <h2>Todo</h2>
      <ul>
        <li>???
      </ul>
  
      <!-- Put @see and @since tags down here. -->
  
    </body>
  </html>
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to