You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/02/04 18:32:09 UTC

cvs commit: jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/connector/file FileSessionPool.java

mcconnell    02/02/04 09:32:09

  Modified:    apps/enterprise/pss build.xml
               apps/enterprise/pss/dist psdl-2.0.1.jar pss-2.0.1.jar
               apps/enterprise/pss/src/java/org/apache/pss Initializer.java
               apps/enterprise/pss/src/java/org/apache/pss/connector/database
                        DatabaseSessionPool.java
               apps/enterprise/pss/src/java/org/apache/pss/connector/file
                        FileSessionPool.java
  Added:       apps/enterprise/pss build.properties
  Removed:     apps/enterprise/pss pss.properties
  Log:
  runtime correction to interceptor management
  
  Revision  Changes    Path
  1.5       +4 -4      jakarta-avalon-cornerstone/apps/enterprise/pss/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/enterprise/pss/build.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.xml	2 Feb 2002 18:35:36 -0000	1.4
  +++ build.xml	4 Feb 2002 17:32:08 -0000	1.5
  @@ -7,7 +7,7 @@
   <project name="pss" default="help" basedir=".">
   
     <property file="local.properties"/>
  -  <property file="pss.properties"/>
  +  <property file="build.properties"/>
   
     <target name="help" >
       <echo>
  @@ -96,7 +96,7 @@
   
     <target name="compiler" depends="compiler.context" unless="compiler.uptodate" >
         <echo message="Building PSDL Compiler."/>
  -      <javac debug="off" destdir="${build}/compiler/lib" deprecation="true">
  +      <javac debug="off" destdir="${build}/compiler/lib" deprecation="true" target="1.2" >
           <src path="${src}/java" />
           <include name="org/apache/pss/compiler/**"/>
           <include name="org/apache/pss/wrapper/**"/>
  @@ -157,7 +157,7 @@
   
     <target name="pss" depends="pss.idl,pss.build.context" unless="pss.uptodate" >
         <echo message="Building PSS Implementation."/>
  -      <javac debug="off" destdir="${build}/pss/lib" deprecation="true">
  +      <javac debug="off" destdir="${build}/pss/lib" deprecation="true" target="1.2" >
           <classpath>
   	    <path refid="project.classpath" />
   	  </classpath>
  @@ -243,7 +243,7 @@
   
     <target name="test.build.action" >
         <echo message="Compilation Test for ${connector} connector."/>
  -      <javac debug="off" destdir="${build}/test/${connector}/lib" deprecation="true">
  +      <javac debug="off" destdir="${build}/test/${connector}/lib" deprecation="true" target="1.2" >
           <classpath>
   	    <path refid="project.classpath" />
             <pathelement path="${dist}/${pss.jar}" />
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/enterprise/pss/build.properties
  
  Index: build.properties
  ===================================================================
  
  #
  # The pss.properties file is read in by the build.xml file.  It 
  # contains information related to resource dependencies and paths
  # to related cornerstone resource
  #
  
  orb.path=../orb/lib
  orb.jar=openorb-1.2.2.jar
  idl.jar=openorb_tools-1.2.2.jar
  
  ots.path=../ots/lib
  ots.jar=openorb_ots-1.2.1.jar
  ots.jta.jar=jta_1.0.1.jar
  
  
  
  
  1.3       +52 -52    jakarta-avalon-cornerstone/apps/enterprise/pss/dist/psdl-2.0.1.jar
  
  	<<Binary file>>
  
  
  1.4       +179 -171  jakarta-avalon-cornerstone/apps/enterprise/pss/dist/pss-2.0.1.jar
  
  	<<Binary file>>
  
  
  1.5       +152 -50   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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Initializer.java	2 Feb 2002 10:29:54 -0000	1.4
  +++ Initializer.java	4 Feb 2002 17:32:09 -0000	1.5
  @@ -22,8 +22,10 @@
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.LogKitLogger;
   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.CascadingRuntimeException;
   import org.apache.log.output.io.FileTarget;
   import org.apache.log.Hierarchy;
   
  @@ -72,33 +74,91 @@
    * </pre>
    */
   public class Initializer extends LocalObject
  -         implements ORBInitializer
  +         implements ORBInitializer, LogEnabled, Configurable
   {
   
  +    //==========================================================================
  +    // static
  +    //==========================================================================
  +
  +    public static FileSessionManager getFileSessionManager()
  +    {
  +        if( m_file_session_manager == null ) throw new IllegalStateException(
  +         "Initalizer has not been initialized.");
  +        return m_file_session_manager;
  +    }
  +
  +    public static DatabaseSessionManager getDatabaseSessionManager()
  +    {
  +        if( m_database_session_manager == null ) throw new IllegalStateException(
  +         "Initalizer has not been initialized.");
  +        return m_database_session_manager;
  +    }
  +
       private static final String PSS = "PSS:";
   
       private final static String DEFAULT_FORMAT =
           "%{time} [%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
   
  +    private static FileSessionManager m_file_session_manager;
   
  -    /**
  -     * The file session manager.
  -     */
  -    public static FileSessionManager _session_manager_file;
  +    private static DatabaseSessionManager m_database_session_manager;
  +    
  +    //==========================================================================
  +    // state
  +    //==========================================================================
   
  -    /**
  -     * The database session manager.
  -     */
  -    public static DatabaseSessionManager _session_manager_database;
  +    private Logger m_logger;
   
  -    private Logger logger;
  +    private Configuration m_config;
   
  +    //==========================================================================
  +    // constructor
  +    //==========================================================================
   
       /**
        * Constructor for the Initializer object
        */
       public Initializer() { }
   
  +    //==========================================================================
  +    // LogEnabled
  +    //==========================================================================
  +
  +   /**
  +    * Sets the logging channel for this instance.
  +    * @param logger the logging channel
  +    */
  +    public void enableLogging( Logger logger )
  +    {
  +        m_logger = logger;
  +    }
  +
  +   /**
  +    * Returns the logging channel.
  +    * @return Logger the logging channel.
  +    */
  +    protected Logger getLogger()
  +    {
  +        return m_logger;
  +    }
  +
  +    //==========================================================================
  +    // Configurable
  +    //==========================================================================
  +
  +   /**
  +    * Set the static configuration for this instance.
  +    */
  +    public void configure( Configuration config )
  +    {
  +        if( getLogger().isDebugEnabled() ) getLogger().debug("configuration");
  +        this.m_config = config;
  +    }
  +
  +    //==========================================================================
  +    // ORBInitializer
  +    //==========================================================================
   
       /**
        * Registers inital references to the file, database and memory connectors.
  @@ -110,98 +170,135 @@
        */
       public void pre_init( ORBInitInfo orbinitinfo )
       {
  +
  +        if( getLogger() != null ) if( getLogger().isDebugEnabled() ) getLogger().debug("pre_init");
  +
           PIDFactory.info = orbinitinfo;
   
  +        //
  +        // get the implmentation default configuration
  +        //
  +
           Configuration defaults = null;
           String vendor = "NULL";
           try
           {
  -            defaults = getConfiguration( this.getClass(), "org/apache/pss/config.xml" );
  +            defaults = getConfiguration( "org/apache/pss/config.xml" );
               vendor = defaults.getAttribute("vendor","APACHE") + ":" ;
           }
           catch ( Throwable e )
           {
  -            System.out.println("Could not load configuration.");
  -		e.printStackTrace();
  +            final String error = "Could not load default configuration.";
  +		throw new CascadingRuntimeException( error, e );
           }
   
  +        //
  +        // if a logging channel has not been declared then bootstrap 
  +        // a channel now
  +        //
  +
           String loggingPath = "";
  -        try
  +        if( getLogger() == null ) try
           {
               loggingPath = defaults.getChild("logging").getAttribute("file");
               String loggingPriority = defaults.getChild("logging").getAttribute("priority", "INFO" );
  -            logger = createLogger( loggingPath, loggingPriority );
  +            m_logger = createLogger( loggingPath, loggingPriority );
           }
           catch ( Throwable e )
           {
               final String error = "Could not create logger on path: " + loggingPath;
  -            throw new INITIALIZE( error + " due to " + e.toString());
  +		throw new CascadingRuntimeException( error, e );
           }
   
  +        //
  +        // if this instance has been configured, use the supplied configuration
  +        // for the remainder fo the operations, otherwise use the defautlt 
  +        // configuration
  +        //
  +
  +        Configuration config = m_config;
  +        if( config == null )
  +        {
  +            if( getLogger().isDebugEnabled() ) getLogger().debug("bootstrap configuration");
  +            config = defaults;
  +        }
  +        else
  +        {
  +            if( getLogger().isDebugEnabled() ) getLogger().debug("managed configuration");
  +        }
  +
  +        //
  +        // create a singleton file connector
  +        //
  +
           try
           {
  -            Configuration config = defaults.getChild("connector").getChild("file");
  -            final FileConnector connector = new FileConnector( config, orbinitinfo );
  -            connector.enableLogging( logger.getChildLogger("file") );
  +            Configuration c = config.getChild("connector").getChild("file");
  +            final FileConnector connector = new FileConnector( c, orbinitinfo );
  +            connector.enableLogging( getLogger().getChildLogger("file") );
               orbinitinfo.register_initial_reference( 
  -              PSS + vendor + config.getAttribute("name"), connector );
  +              PSS + vendor + "file", connector );
           }
           catch ( Throwable e )
           {
  -            throw new INITIALIZE( "Unable to register file connector due to " + e.toString());
  +            final String error = "Unexpected exception while attempting to register the file connector.";
  +            throw new CascadingRuntimeException( error, e );
           }
   
  +        //
  +        // create a singleton database connector
  +        //
  +
           try
           {
  -            Configuration config = defaults.getChild("connector").getChild("database");
  -            final DatabaseConnector connector = new DatabaseConnector( config, orbinitinfo );
  -            connector.enableLogging( logger.getChildLogger("db") );
  +            Configuration c = config.getChild("connector").getChild("database");
  +            final DatabaseConnector connector = new DatabaseConnector( c, orbinitinfo );
  +            connector.enableLogging( getLogger().getChildLogger("db") );
               orbinitinfo.register_initial_reference( 
  -              PSS + vendor + config.getAttribute("name"), connector );
  +              PSS + vendor + "database", connector );
           }
           catch ( Throwable e )
           {
  -            throw new INITIALIZE( "Unable to register database connector due to: " + e.toString() );
  +            final String error = "Unexpected exception while attempting to register the database connector.";
  +            throw new CascadingRuntimeException( error, e );
           }
   
           try
           {
  -            Configuration config = defaults.getChild("connector").getChild("memory");
  -            final MemoryConnector connector = new MemoryConnector( config, orbinitinfo );
  -            connector.enableLogging( logger.getChildLogger("memory") );
  +            Configuration c = config.getChild("connector").getChild("memory");
  +            final MemoryConnector connector = new MemoryConnector( c, orbinitinfo );
  +            connector.enableLogging( getLogger().getChildLogger("memory") );
               orbinitinfo.register_initial_reference( 
  -              PSS + vendor + config.getAttribute("name"), connector );
  +              PSS + vendor + "memory", connector );
           }
           catch ( Throwable e )
           {
  -            throw new INITIALIZE( "Unable to register memory connector due to: " + e.toString() );
  +            final String error = "Unexpected exception while attempting to register the memory connector.";
  +            throw new CascadingRuntimeException( error, e );
           }
   
  -        
  -        if( defaults.getChild("ots").getAttributeAsBoolean("boot", false) )
  +        if( config.getChild("ots").getAttributeAsBoolean("boot", false) )
           {
               org.openorb.ots.Initializer initializer = new org.openorb.ots.Initializer();
               initializer.pre_init( orbinitinfo );
           }
   
  -
  -        ORBLoader orbloader = ( ( OpenORBInitInfo ) orbinitinfo ).orb().getLoader();
  -        boolean flag1 = orbloader.getBooleanProperty( "PSS.Debug", false );
  -        if ( flag1 )
  +        try
           {
  -            debug.debugMode( true );
  +            m_file_session_manager = new FileSessionManager( orbinitinfo );
  +            m_database_session_manager = new DatabaseSessionManager( orbinitinfo );
  +            orbinitinfo.add_server_request_interceptor( getFileSessionManager() );
  +            orbinitinfo.add_server_request_interceptor( getDatabaseSessionManager() );
           }
  -
  -        _session_manager_file = new FileSessionManager( orbinitinfo );
  -        _session_manager_database = new DatabaseSessionManager( orbinitinfo );
  -        try
  +        catch ( DuplicateName duplicateName )
           {
  -            orbinitinfo.add_server_request_interceptor( _session_manager_file );
  -            orbinitinfo.add_server_request_interceptor( _session_manager_database );
  +            final String error = "Illegal attempt to register an interceptor under an duplicate name.";
  +            throw new CascadingRuntimeException( error, duplicateName );
           }
  -        catch ( DuplicateName duplicatename )
  +        catch( Throwable e )
           {
  -            Verbose.exception( "Initializer", "Duplicate name when adding the interceptor", duplicatename );
  +            final String error = "Unexpected error while attempting to register an interceptor.";
  +            throw new CascadingRuntimeException( error, e );
           }
       }
   
  @@ -213,25 +310,30 @@
       public void post_init( ORBInitInfo orbinitinfo ) { }
   
   
  +    //==========================================================================
  +    // internals
  +    //==========================================================================
  +
      /**
       * Returns the configuration resource.
       */
  -    private static Configuration getConfiguration( Class c, String path ) throws Exception
  +    private Configuration getConfiguration( String path ) throws Exception
       {
   	  DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder( );
  -	  InputStream is = c.getClassLoader().getResourceAsStream( path );
  +	  InputStream is = this.getClass().getClassLoader().getResourceAsStream( path );
           if( is == null ) throw new Exception(
   			"Could not find the configuration resource \"" + path + "\"" );
           return builder.build( is );
       }
   
  -    private static Logger createLogger( final String filename, String priority )
  +    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 ), false, new AvalonFormatter( DEFAULT_FORMAT ) ) );
  +            hierarchy.setDefaultLogTarget( new FileTarget( new File( filename ), 
  +               false, new AvalonFormatter( DEFAULT_FORMAT ) ) );
               return new LogKitLogger( hierarchy.getLoggerFor( "pss" ) );
           }
           catch( Exception e)
  
  
  
  1.4       +1 -1      jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/connector/database/DatabaseSessionPool.java
  
  Index: DatabaseSessionPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/connector/database/DatabaseSessionPool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatabaseSessionPool.java	2 Feb 2002 03:04:45 -0000	1.3
  +++ DatabaseSessionPool.java	4 Feb 2002 17:32:09 -0000	1.4
  @@ -134,7 +134,7 @@
           _tx_policy = tx_policy;
           if ( _tx_policy == TRANSACTIONAL.value )
           {
  -            Initializer._session_manager_database.register( this );
  +            Initializer.getDatabaseSessionManager().register( this );
           }
       }
   
  
  
  
  1.4       +1 -1      jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/connector/file/FileSessionPool.java
  
  Index: FileSessionPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/enterprise/pss/src/java/org/apache/pss/connector/file/FileSessionPool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileSessionPool.java	2 Feb 2002 10:29:54 -0000	1.3
  +++ FileSessionPool.java	4 Feb 2002 17:32:09 -0000	1.4
  @@ -101,7 +101,7 @@
           _tx_policy = policy;
           if ( _tx_policy == TRANSACTIONAL.value )
           {
  -            Initializer._session_manager_file.register( this );
  +            Initializer.getFileSessionManager().register( this );
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>