mcconnell 02/02/11 15:57:49
Modified: apps/enterprise/pss/src/java/org/apache/pss Initializer.java
Log:
simplified bootstrap mechanisms if running under non-Avalon manager
Revision Changes Path
1.9 +122 -85
jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/Initializer.java
Index: Initializer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/Initializer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Initializer.java 11 Feb 2002 21:57:06 -0000 1.8
+++ Initializer.java 11 Feb 2002 23:57:49 -0000 1.9
@@ -14,9 +14,9 @@
package org.apache.pss;
+import java.io.File;
import java.io.PrintStream;
import java.io.InputStream;
-import java.io.File;
import java.lang.reflect.Method;
import org.apache.avalon.framework.logger.Logger;
@@ -25,11 +25,12 @@
import org.apache.avalon.framework.logger.AvalonFormatter;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.log.output.io.FileTarget;
import org.apache.log.Hierarchy;
@@ -69,15 +70,51 @@
* throw new RuntimeException( error, invalidName );
* }
* </pre>
+ *
+ * <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
+ * <tr bgcolor="#ccccff">
+ * <td colspan="2"><b>PSS Interceptor Lifecycle Phases</b></td>
+ * <tr><td width="20%"><b>Phase</b></td><td><b>Description</b></td></tr>
+ * <tr>
+ * <td width="20%" valign="top">Configurable</td>
+ * <td>
+ * A configuration if supplied is used to modify implementation defaults
+ * for the PSS interceptor. The implementation defaults correcpoond to the
+ * following configuration.
+ * <pre><code>
+ * <pss>
+ * <memory/>
+ * <file flush="40"/>
+ * <database flush="40"/>
+ * </pss>
+ * </code></pre>
+ * </td></tr>
+ * <tr>
+ * <td width="20%" valign="top">Contextualizable</td>
+ * <td>
+ * The <code>Context</code> value passed to the <code>PSS</code>
+ * interceptor will be used by the implemetation for resolution of
+ * the application base directory (required by the file connector).
+ * </td></tr>
+ * <tr><td width="20%" valign="top">Disposable</td>
+ * <td>
+ * Invoked by the ORB triggering cleanup and disposal of state members.
+ * </td></tr>
+ * </table>
+
+ * @see org.apache.orb.ORB
*/
public class Initializer extends LocalObject
- implements ORBInitializer, LogEnabled, Contextualizable,
Configurable
+ implements ORBInitializer, LogEnabled, Contextualizable,
Configurable, Disposable
{
//==========================================================================
// static
//==========================================================================
+ /**
+ * Static accessor to the singleton file session manager.
+ */
public static FileSessionManager getFileSessionManager()
{
if( m_file_session_manager == null ) throw new IllegalStateException(
@@ -85,6 +122,9 @@
return m_file_session_manager;
}
+ /**
+ * Static accessor to the singleton database session manager.
+ */
public static DatabaseSessionManager getDatabaseSessionManager()
{
if( m_database_session_manager == null ) throw new
IllegalStateException(
@@ -93,30 +133,21 @@
}
private static final String PSS = "PSS:";
-
private static final String VENDOR = "APACHE:";
-
private final static String DEFAULT_FORMAT =
"%{time} [%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
private static FileSessionManager m_file_session_manager;
-
private static DatabaseSessionManager m_database_session_manager;
-
+
//==========================================================================
// state
//==========================================================================
private Logger m_logger;
-
private Configuration m_config;
-
- private Configuration m_bootstrap_config;
-
private Context m_context;
- private File m_root;
-
//==========================================================================
// constructor
//==========================================================================
@@ -146,8 +177,7 @@
protected Logger getLogger()
{
if( null != m_logger ) return m_logger;
- m_logger = getBootstrapLogger( getBootstrapConfiguration() );
- if( m_logger.isDebugEnabled() ) m_logger.debug("bootstrap logging
enabled");
+ m_logger = getBootstrapLogger();
return m_logger;
}
@@ -157,6 +187,9 @@
/**
* Set the execution context.
+ * @param context a <code>Context</code> that provides the runtime
application
+ * context from which the implementation will attempt to resolve the
+ * base directory.
*/
public void contextualize( Context context )
{
@@ -170,20 +203,64 @@
/**
* Set the static configuration for this instance.
+ * A <code>Configuration</code> instance may optionally be provided
+ * in order to override default PSS implementation parameters. A valid
+ * configuration structure showing implementation defaults is described
here:
+ *
+ * <pre><code>
+ * <pss>
+ *
+ * <!--
+ * Declaration of default for the memory connector
+ * (currently none).
+ * -->
+ *
+ * <memory/>
+ *
+ * <!--
+ * Declaration of defaults for the file connector.
+ * The value of the flush attribute is an integer that
+ * controls the perodic flushing of cached data entries
+ * to the underlying file system.
+ * -->
+ *
+ * <file flush="40"/>
+ *
+ * <!--
+ * Declaration of defaults for the database connector.
+ * The value of the flush attribute is an integer that
+ * controls the perodic flushing of cached data entries
+ * to the underlying JDBC database.
+ * -->
+ *
+ * <database flush="40"/>
+ *
+ * </pss>
+ * </code></pre>
+ *
+ * @param config the Initilizer configuration
+ * @exception IllegalStateException if an attempt is made to reconfigure
+ * the initalizer.
*/
public void configure( Configuration config )
{
+ if( m_config != null ) throw new IllegalStateException(
+ "Illegal attempt to reconfigure.");
if( getLogger().isDebugEnabled() ) getLogger().debug("configure");
this.m_config = config;
}
/**
- * Returns the configuration resource.
+ * Returns the configuration resource supplied under the configuration
+ * phase or a default empty configuration if no configuration has been
+ * previously supplied.
+ *
+ * @see #configure( Configuration )
*/
private Configuration getConfiguration()
{
if( m_config != null ) return m_config;
- m_config = new DefaultContiguration( "-", null );
+ m_config = new DefaultConfiguration( "-", null );
return m_config;
}
@@ -192,6 +269,7 @@
//==========================================================================
/**
+ * Methoid invoked by an ORB during Interceptor initialization.
* Registers inital references to the file, database and memory
connectors.
* Connectors are accessible to users through the
resolve_inital_references
* operation using the "PSS:APACHE:xxx" where "xxx" many be one of
"file",
@@ -205,8 +283,6 @@
PIDFactory.info = orbinitinfo;
- if( m_root == null ) m_root = getBaseDirectory();
-
//
// create a singleton file connector
//
@@ -232,7 +308,8 @@
try
{
- if( getLogger().isDebugEnabled() ) getLogger().debug("creating
singleton database connector");
+ if( getLogger().isDebugEnabled() ) getLogger().debug(
+ "creating singleton database connector");
Configuration c =
getConfiguration().getChild("connector").getChild("database");
final DatabaseConnector connector = new DatabaseConnector(
m_context, c, orbinitinfo );
connector.enableLogging( getLogger().getChildLogger("db") );
@@ -245,6 +322,10 @@
throw new CascadingRuntimeException( error, e );
}
+ //
+ // create a singleton memory based simulator
+ //
+
try
{
if( getLogger().isDebugEnabled() ) getLogger().debug("creating
singleton memory connector");
@@ -290,90 +371,46 @@
}
/**
- * Post initalization of the interceptor.
- * @param orbinitinfo
+ * Post initalization of the interceptor (empty implementation) invoked
by
+ * ORB in which this interceptor is installed.
+ * @param info
*/
- public void post_init( ORBInitInfo orbinitinfo ) { }
-
+ public void post_init( ORBInitInfo info ) { }
//==========================================================================
- // internals
+ // Disposable
//==========================================================================
/**
- * Returns the configuration resource.
+ * Notification of disposal of the componet.
*/
- private Configuration getBootstrapConfiguration( )
+ public void dispose()
{
- if( m_bootstrap_config != null ) return m_bootstrap_config;
- m_bootstrap_config = getBootstrapConfiguration(
"org/apache/pss/config.xml" );
- return m_bootstrap_config;
+ m_file_session_manager = null;
+ m_database_session_manager = null;
+ m_logger = null;
+ m_config = null;
+ m_context = null;
}
- /**
- * Returns the configuration resource.
- */
- private Configuration getBootstrapConfiguration( String path )
- {
- try
- {
- DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder( );
- InputStream is =
this.getClass().getClassLoader().getResourceAsStream( path );
- if( is == null ) throw new Exception(
- "Could not find the configuration resource \"" + path +
"\"" );
- return builder.build( is );
- }
- catch( Throwable e )
- {
- final String error = "Could not build the bootstrap
configuration.";
- throw new CascadingRuntimeException( error, e );
- }
- }
+
//==========================================================================
+ // internals
+
//==========================================================================
- private Logger getBootstrapLogger( Configuration bootstrap )
+ private Logger getBootstrapLogger( )
{
- String loggingPath = "";
try
{
- loggingPath = bootstrap.getChild("logging").getAttribute("file");
- String loggingPriority =
bootstrap.getChild("logging").getAttribute("priority", "INFO" );
- return createLogger( loggingPath, loggingPriority );
- }
- catch ( Throwable e )
- {
- final String error = "Could not create bootstrap logger on path:
'" + loggingPath + "'.";
- throw new CascadingRuntimeException( error, e );
- }
- }
-
-
- private Logger createLogger( final String filename, String priority )
- {
- try
- {
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
- hierarchy.setDefaultPriority(
org.apache.log.Priority.getPriorityForName( priority ));
- hierarchy.setDefaultLogTarget( new FileTarget( new File(
filename ),
+ hierarchy.setDefaultPriority(
org.apache.log.Priority.getPriorityForName( "INFO" ));
+ hierarchy.setDefaultLogTarget( new FileTarget( new File(
"pss.log" ),
false, new AvalonFormatter( DEFAULT_FORMAT ) ) );
return new LogKitLogger( hierarchy.getLoggerFor( "pss" ) );
}
- catch( Exception e)
- {
- throw new RuntimeException("Failed to establish logger.",e);
- }
- }
-
- private File getBaseDirectory()
- {
- if( m_context != null ) try
- {
- Method method = m_context.getClass().getMethod(
"getBaseDirectory", new Class[0] );
- return (File) method.invoke( m_context, new Object[0] );
- }
- catch( Throwable e )
+ catch ( Throwable e )
{
+ final String error = "Could not create bootstrap logger";
+ throw new CascadingRuntimeException( error, e );
}
- return new File( System.getProperty("user.dir") );
}
-
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>