User: user57
Date: 02/02/24 02:24:33
Added: src/main/org/jboss Main.java Shutdown.java Version.java
Log:
o moved core system from server to system (includes
all of org.jboss.system, some of org.jboss.deployment +
Main, Shutdown & Version)
o finished the integration of ServerLoader, Server and
ServerConfig are now interfaces so had to update refering
classes to use ServerConfigImplMBean
o ServerLoader changes effectivly remove the need for lib/ + lib/ext
seperation, updated build to use lib for lib/ext and updated
config files
Revision Changes Path
1.1 jboss-system/src/main/org/jboss/Main.java
Index: Main.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss;
import java.io.File;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Properties;
import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
import gnu.getopt.Getopt;
import gnu.getopt.LongOpt;
import org.jboss.system.server.Server;
import org.jboss.system.server.ServerConfig;
import org.jboss.system.server.ServerLoader;
/**
* The main entry-point for the JBoss server.
*
* <p>To enable debug messages durring boot, create
* a log4j properties file named debugboot.properties,
* specify the base directory path where that file
* lives with the <tt>-C</tt> option and then tell log4j to
* use that file with <tt>-Dlog4j.configuration=debugboot.properties</tt>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class Main
{
/** The JAXP library to use. */
private String jaxpLib = "crimson.jar";
/** The JMX library to use. */
private String jmxLib = "jmxri.jar";
/** Extra libraries to load the server with .*/
private List extraLibraries = new LinkedList();
/** Extra classpath URLS to load the server with .*/
private List extraClasspath = new LinkedList();
/**
* Explicit constructor.
*/
public Main()
{
super();
}
/**
* Boot up JBoss.
*
* @param args The command line arguments.
*
* @throws Exception Failed to boot.
*/
public void boot(final String[] args) throws Exception
{
//
// Set a jboss.home property from the location of the Main.class jar
// if the property does not exist.
//
// marcf: we don't use this property at all for now
// it should be used for all the modules that need a file "anchor"
// it should be moved to an "FileSystemAnchor" MBean
//
if (System.getProperty("jboss.home") == null)
{
String path =
Main.class.getProtectionDomain().getCodeSource().getLocation().getFile();
File runJar = new File(path);
// Home dir should be the parent of the dir containing run.jar
File homeDir = new File(runJar.getParent(), "..");
System.setProperty("jboss.home", homeDir.getCanonicalPath());
}
String home = System.getProperty("jboss.home");
//
// FIXME: Change me to jboss.server.home, system is too confusing here
//
if (System.getProperty("jboss.system.home") == null)
{
// default to jboss.home if jboss.system.home is not set
System.setProperty("jboss.system.home", home);
}
String systemHome = System.getProperty("jboss.system.home");
// Create a new server properties. This object holds all
// of the required information to get the server up and running.
// Use System properties for defaults.
Properties props = new Properties(System.getProperties());
// Use jboss.home for HOME_DIR and/or INSTALL_URL if not set.
if (!props.containsKey(ServerConfig.HOME_DIR)) {
props.setProperty(ServerConfig.HOME_DIR, home);
}
if (!props.containsKey(ServerConfig.INSTALL_URL)) {
props.setProperty(ServerConfig.INSTALL_URL, new
File(home).toURL().toString());
}
// set this from a system property or default to jboss
String programName = System.getProperty("jboss.boot.loader.name", "jboss");
String sopts = "-:hD:p:n:c:Vj:L:C:";
LongOpt[] lopts =
{
new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'),
new LongOpt("patch-dir", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
new LongOpt("net-boot", LongOpt.REQUIRED_ARGUMENT, null, 'n'),
new LongOpt("configuration", LongOpt.REQUIRED_ARGUMENT, null, 'c'),
new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V'),
new LongOpt("jaxp", LongOpt.REQUIRED_ARGUMENT, null, 'j'),
new LongOpt("library", LongOpt.REQUIRED_ARGUMENT, null, 'L'),
new LongOpt("classpath", LongOpt.REQUIRED_ARGUMENT, null, 'C'),
};
Getopt getopt = new Getopt(programName, args, sopts, lopts);
int code;
String arg;
while ((code = getopt.getopt()) != -1)
{
switch (code)
{
case ':':
case '?':
// for now both of these should exit with error status
System.exit(1);
break; // for completeness
case 1:
// this will catch non-option arguments
// (which we don't currently care about)
System.err.println(programName +
": unused non-option argument: " +
getopt.getOptarg());
break; // for completeness
case 'h':
// show command line help
System.out.println("usage: " + programName + " [options]");
System.out.println();
System.out.println("options:");
System.out.println(" -h, --help Show this help
message");
System.out.println(" -V, --version Show version
information");
System.out.println(" -- Stop processing
options");
System.out.println(" -D<name>[=<value>] Set a system
property");
System.out.println(" -p, --patch-dir=<dir> Set the patch
directory; Must be absolute");
System.out.println(" -n, --net-boot=<url> Boot from net
with the given url as base");
System.out.println(" -c, --configuration=<name> Set the server
configuration name");
System.out.println(" -j, --jaxp=<type> Set the JAXP
impl type (ie. crimson)");
System.out.println(" -L, --library=<filename> Add an extra
library to the loaders classpath");
System.out.println(" -C, --classpath=<url> Add an extra
url to the loaders classpath");
System.out.println();
System.exit(0);
break; // for completeness
case 'D':
// set a system property
arg = getopt.getOptarg();
String name, value;
int i = arg.indexOf("=");
if (i == -1)
{
name = arg;
value = "true";
}
else
{
name = arg.substring(0, i);
value = arg.substring(i + 1, arg.length());
}
System.setProperty(name, value);
break;
case 'p':
// set the local patch directory
arg = getopt.getOptarg();
props.put(ServerConfig.PATCH_URL, new URL(arg).toString());
break;
case 'n':
// set the net boot url
arg = getopt.getOptarg();
// make sure there is a trailing '/'
if (!arg.endsWith("/")) arg += "/";
props.put(ServerConfig.INSTALL_URL, new URL(arg).toString());
break;
case 'c':
// set the configuration name
arg = getopt.getOptarg();
props.put(ServerConfig.CONFIG_NAME, arg);
break;
case 'V':
// show version information
System.out.println("JBoss " + Version.getInstance());
System.out.println();
System.out.println("Distributable under LGPL license.");
System.out.println("See terms of license at gnu.org.");
System.out.println();
System.exit(0);
break; // for completness
case 'j':
// set the JAXP impl type
arg = getopt.getOptarg().toLowerCase();
String domFactoryType, saxFactoryType;
if (arg.equals("crimson"))
{
domFactoryType =
"org.apache.crimson.jaxp.DocumentBuilderFactoryImpl";
saxFactoryType = "org.apache.crimson.jaxp.SAXParserFactoryImpl";
jaxpLib = "crimson.jar";
}
else if (arg.equals("xerces"))
{
domFactoryType =
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl";
saxFactoryType = "org.apache.xerces.jaxp.SAXParserFactoryImpl";
jaxpLib = "xerces.jar";
}
else
{
System.err.println("Invalid JAXP type: " + arg +
" (Expected 'crimson' or 'xerces')");
// don't continue, user needs to fix this!
System.exit(1);
// trick the compiler, so it does not complain that
// the above variables might not being set
break;
}
// set the controlling properties
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
domFactoryType);
System.setProperty("javax.xml.parsers.SAXParserFactory",
saxFactoryType);
break;
case 'L':
arg = getopt.getOptarg();
extraLibraries.add(arg);
break;
case 'C':
arg = getopt.getOptarg();
URL url;
try {
File file = new File(arg);
url = file.toURL();
}
catch (Exception e) {
url = new URL(arg);
}
extraClasspath.add(url);
break;
default:
// this should not happen,
// if it does throw an error so we know about it
throw new Error("unhandled option code: " + code);
}
}
// Load the server instance
ServerLoader loader = new ServerLoader(props);
// Add JAXP and JMX libs
loader.addLibrary(jaxpLib);
loader.addLibrary(jmxLib);
// Add any extra libraries
for (Iterator iter=extraLibraries.iterator(); iter.hasNext();) {
loader.addLibrary((String)iter.next());
}
// Add any extra classapth
for (Iterator iter=extraClasspath.iterator(); iter.hasNext();) {
loader.addURL((URL)iter.next());
}
// Load the server
Server server = loader.load(Thread.currentThread().getContextClassLoader());
// Initialize & make sure that shutdown exits the VM
server.init(props);
ServerConfig config = server.getConfig();
config.setExitOnShutdown(true);
// Start 'er up mate!
server.start();
}
/**
* This is where the magic begins.
*
* <P>Starts up inside of a "jboss" thread group to allow better
* identification of JBoss threads.
*
* @param args The command line arguments.
*/
public static void main(final String[] args) throws Exception
{
Runnable worker = new Runnable() {
public void run()
{
try
{
Main main = new Main();
main.boot(args);
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
ThreadGroup threads = new ThreadGroup("jboss");
new Thread(threads, worker, "main").start();
}
/**
* This method is here so that if JBoss is running under
* Alexandria (An NT Service Installer), Alexandria can shutdown
* the system down correctly.
*/
public static void systemExit(String argv[])
{
System.exit(0);
}
}
1.1 jboss-system/src/main/org/jboss/Shutdown.java
Index: Shutdown.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss;
import java.net.URL;
import java.net.URLEncoder;
/**
* Provides an OS-independent way of shutting down JBoss. This
* works by accessing the JMX server and giving it the shutdown
* command. The host to the JMX server can be passed in as well
* as the port number. If neither is supplied, the defaults of
* <tt>localhost</tt> and <tt>8082</tt> are used.
*
* <h3>Usage:</h3>
* <pre>
* java org.jboss.Shutdown [host] [port]
* </pre>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dewayne McNair</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class Shutdown
{
private static final String COMMAND =
"/InvokeAction//jboss%2Esystem%3Atype%3DServer/action=shutdown?action=shutdown";
/**
* Parse the command line and shutdown the remote server.
*
* @param argv Command line arguments.
* @throws Exception Invalid port number.
*/
public static void main(final String argv[]) throws Exception
{
String host = "localhost";
int port = 8082;
if (argv.length >= 1) {
host = argv[0];
}
if (argv.length >= 2) {
port = Integer.parseInt(argv[1]);
}
shutdown(host, port);
}
/**
* Connect to the JBoss servers HTML JMX adapter and invoke the
* shutdown service.
*
* @param host The hostname of the JMX server.
* @param port The port of the JMX server.
*
*/
public static void shutdown(final String host, final int port) {
try {
URL url = new URL("http", host, port, COMMAND);
url.getContent();
}
catch (Exception ignore) {
// we do nothing because even if everything went
// right, ie JBoss is shutdown, we'd get an exception
}
}
}
1.1 jboss-system/src/main/org/jboss/Version.java
Index: Version.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.Date;
/**
* Provides access to JBoss version (and build) properties.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public final class Version
{
public final static String VERSION_MAJOR = "version.major";
public final static String VERSION_MINOR = "version.minor";
public final static String VERSION_REVISION = "version.revision";
public final static String VERSION_TAG = "version.tag";
public final static String VERSION_NAME = "version.name";
public final static String BUILD_NUMBER = "build.number";
public final static String BUILD_ID = "build.id";
public final static String BUILD_DATE = "build.day";
/**
* The single instance.
*/
private static Version instance = null;
/**
* The version properties.
*/
private Properties props;
/**
* Do not allow direct public construction.
*/
private Version()
{
props = loadProperties();
}
/**
* Get the single <tt>Version</tt> instance.
*
* @return The single <tt>Version</tt> instance.
*/
public static Version getInstance()
{
if (instance == null)
{
instance = new Version();
}
return instance;
}
/**
* Returns an unmodifiable map of version properties.
*
* @return An unmodifiable map of version properties.
*/
public Map getProperties()
{
return Collections.unmodifiableMap(props);
}
/**
* Returns the value for the given property name.
*
* @param name - The name of the property.
* @return The property value or null if the property is not set.
*/
public String getProperty(final String name)
{
return props.getProperty(name);
}
/**
* Returns the major number of the version.
*
* @return The major number of the version.
*/
public int getMajor()
{
return getIntProperty(VERSION_MAJOR);
}
/**
* Returns the minor number of the version.
*
* @return The minor number of the version.
*/
public int getMinor()
{
return getIntProperty(VERSION_MINOR);
}
/**
* Returns the revision number of the version.
*
* @return The revision number of the version.
*/
public int getRevision()
{
return getIntProperty(VERSION_REVISION);
}
/**
* Returns the tag of the version.
*
* @return The tag of the version.
*/
public String getTag()
{
return props.getProperty(VERSION_TAG);
}
/**
* Returns the name number of the version.
*
* @return The name of the version.
*/
public String getName()
{
return props.getProperty(VERSION_NAME);
}
/**
* Returns the build identifier for this version.
*
* @return The build identifier for this version.
*/
public String getBuildID()
{
return props.getProperty(BUILD_ID);
}
/**
* Returns the build number for this version.
*
* @return The build number for this version.
*/
public String getBuildNumber()
{
return props.getProperty(BUILD_NUMBER);
}
/**
* Returns the build date for this version.
*
* @return The build date for this version.
*/
public String getBuildDate()
{
return props.getProperty(BUILD_DATE);
}
/**
* Returns the version information as a string.
*
* @return Basic information as a string.
*/
public String toString()
{
StringBuffer buff = new StringBuffer();
buff.append(getMajor()).append(".");
buff.append(getMinor()).append(".");
buff.append(getRevision()).append(getTag());
buff.append("(").append(getBuildID()).append(")");
return buff.toString();
}
/**
* Returns a property value as an int.
*
* @param name - The name of the property.
* @return The property value, or -1 if there was a problem converting
* it to an int.
*/
private int getIntProperty(final String name)
{
try {
return Integer.valueOf(props.getProperty(name)).intValue();
}
catch (Exception e) {
return -1;
}
}
/**
* Returns a property value as a long.
*
* @param name - The name of the property.
* @return The property value, or -1 if there was a problem converting
* it to an long.
*/
private long getLongProperty(final String name)
{
try {
return Long.valueOf(props.getProperty(name)).longValue();
}
catch (Exception e) {
return -1;
}
}
/**
* Load the version properties from a resource.
*/
private Properties loadProperties()
{
props = new Properties();
try
{
InputStream in =
Version.class.getResourceAsStream("/org/jboss/version.properties");
props.load(in);
in.close();
}
catch (IOException e)
{
throw new Error("Missing version.properties");
}
return props;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development