[jboss-cvs] JBossAS SVN: r97149 - in projects/embedded/trunk: core/src/main/java/org/jboss/embedded/core/server and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 30 00:05:43 EST 2009
Author: ALRubinger
Date: 2009-11-30 00:05:43 -0500 (Mon, 30 Nov 2009)
New Revision: 97149
Modified:
projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServerFactory.java
projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/SecurityActions.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
Log:
[EMB-72] Install boot.log directory on factory server creation
Modified: projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServerFactory.java
===================================================================
--- projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServerFactory.java 2009-11-30 03:25:37 UTC (rev 97148)
+++ projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServerFactory.java 2009-11-30 05:05:43 UTC (rev 97149)
@@ -16,6 +16,7 @@
*/
package org.jboss.embedded.api.server;
+import org.jboss.bootstrap.api.as.config.JBossASServerConfig;
import org.jboss.bootstrap.api.as.server.JBossASServerFactory;
/**
@@ -41,6 +42,11 @@
*/
private static final String DEFAULT_SERVER_IMPL_CLASS_NAME = "org.jboss.embedded.core.server.JBossASEmbeddedServerImpl";
+ /**
+ * System property denoting the location of the temp directory
+ */
+ private static final String SYS_PROP_TMP_DIR = "java.io.tmpdir";
+
//-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -66,6 +72,10 @@
* Thread Context ClassLoader. The returned server will additionally be created using
* the TCCL.
*
+ * This factory method will also set up a boot.log within the system temporary
+ * directory unless another location has been manually specified via the presense
+ * of the system property "jboss.boot.server.log.dir".
+ *
* @return The newly-created Server
*/
public static JBossASEmbeddedServer createServer()
@@ -79,12 +89,38 @@
* specified ClassLoader. The returned server will additionally be created using
* the ClassLoader denoted.
*
+ * This factory method will also set up a boot.log within the system temporary
+ * directory unless another location has been manually specified via the presense
+ * of the system property "jboss.boot.server.log.dir".
+ *
* @param cl The ClassLoader used to create the new server instance
* @throws IllegalArgumentException If the ClassLoader is null
* @return The newly-created Server
*/
public static JBossASEmbeddedServer createServer(final ClassLoader cl) throws IllegalArgumentException
{
+
+ /*
+ * Set boot log directory to a temp directory
+ */
+ final String sysPropBootLogDir = "jboss.boot.server.log.dir";
+ final String sysPropLogDir = JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_LOG_DIR;
+ final String manualBootLogDir = SecurityActions.getSystemProperty(sysPropBootLogDir);
+ final String manualLogDir = SecurityActions.getSystemProperty(sysPropLogDir);
+ // If nothing's been explicitly specified
+ if (manualBootLogDir == null && manualLogDir == null)
+ {
+ // We default it
+ final String serverLogDir = SecurityActions.getSystemProperty(SYS_PROP_TMP_DIR);
+ SecurityActions.setSystemProperty(sysPropBootLogDir, serverLogDir);
+ System.out.println("Boot Log available in: " + serverLogDir);
+ }
+ // If we've got a manual log dir, use it
+ else if (manualLogDir != null)
+ {
+ SecurityActions.setSystemProperty(sysPropBootLogDir, manualLogDir);
+ }
+
try
{
return JBossASServerFactory.createServer(DEFAULT_SERVER_IMPL_CLASS_NAME, cl, JBossASEmbeddedServer.class);
Modified: projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/SecurityActions.java
===================================================================
--- projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/SecurityActions.java 2009-11-30 03:25:37 UTC (rev 97148)
+++ projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/SecurityActions.java 2009-11-30 05:05:43 UTC (rev 97149)
@@ -49,6 +49,23 @@
}
//-------------------------------------------------------------------------------------||
+ // Protected Actions ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Action to obtain the Thread Context ClassLoader
+ */
+ private enum GetTcclAction implements PrivilegedAction<ClassLoader> {
+ INSTANCE;
+ public ClassLoader run()
+ {
+ // Return the TCCL
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ }
+
+ //-------------------------------------------------------------------------------------||
// Utility Methods --------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -59,15 +76,62 @@
*/
static ClassLoader getTccl()
{
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ return AccessController.doPrivileged(GetTcclAction.INSTANCE);
+ }
+
+ /**
+ * Obtains the system property with the specified key
+ *
+ * @param key
+ * @return
+ * @throws IllegalArgumentException If the key is null
+ */
+ static String getSystemProperty(final String key) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (key == null)
{
+ throw new IllegalArgumentException("key was null");
+ }
- public ClassLoader run()
+ // Get sysprop
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
{
- // Return the TCCL
- return Thread.currentThread().getContextClassLoader();
+ return System.getProperty(key);
}
+ });
+ }
+ /**
+ * Sets the system property with the specified key and value
+ *
+ * @param key
+ * @param value
+ * @return
+ * @throws IllegalArgumentException If the key or value is null
+ */
+ static void setSystemProperty(final String key, final String value) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (key == null)
+ {
+ throw new IllegalArgumentException("key was null");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("value was null");
+ }
+
+ // Get sysprop
+ AccessController.doPrivileged(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ System.setProperty(key, value);
+ return null;
+ }
});
}
}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-11-30 03:25:37 UTC (rev 97148)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-11-30 05:05:43 UTC (rev 97149)
@@ -432,40 +432,6 @@
@SuppressWarnings("deprecation")
final LifecycleEventHandler ipv4Handler = new SetIPv4LifecycleEventHandler();
this.registerEventHandler(LifecycleState.INITIALIZED, ipv4Handler);
-
- //TODO
- /*
- * Do we need some handler for boot.log? Something like:
- */
- log.warn(this + " has not installed any handler for a boot.log in $JBOSS_HOME/server/[name]/log");
- // /*
- // * Set boot log directory
- // */
- // final String sysPropBootLogDir = "jboss.boot.server.log.dir";
- // final String sysPropLogDir = JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_LOG_DIR;
- // String serverName = System.getProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_NAME);
- // if (serverName == null || serverName.length() == 0)
- // {
- // serverName = JBossASConfigurationInitializer.VALUE_SERVER_NAME_DEFAULT;
- // }
- // final String manualBootLogDir = System.getProperty(sysPropBootLogDir);
- // final String manualLogDir = System.getProperty(sysPropLogDir);
- // // If nothing's been explicitly specified
- // if (manualBootLogDir == null && manualLogDir == null)
- // {
- // // We default it
- // final File jbossHomeFile = new File(jbossHome);
- // final URL jbossHomeUrl = jbossHomeFile.toURI().toURL();
- // final URL serverLog = new URL(jbossHomeUrl, "server/" + serverName + "/log/");
- // final File serverLogFile = new File(serverLog.toURI());
- // final String serverLogString = serverLogFile.getAbsolutePath();
- // System.setProperty(sysPropBootLogDir, serverLogString);
- // }
- // // If we've got a manual log dir, use it
- // else if (manualLogDir != null)
- // {
- // System.setProperty(sysPropBootLogDir, manualLogDir);
- // }
}
/**
More information about the jboss-cvs-commits
mailing list