You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by pr...@apache.org on 2002/07/22 19:20:38 UTC

cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration PersistentConfigurationRepositoryMBean.java FileSystemPersistentConfigurationRepository.java

proyal      2002/07/22 10:20:38

  Modified:    src/java/org/apache/avalon/phoenix/components/configuration
                        FileSystemPersistentConfigurationRepository.java
  Added:       src/java/org/apache/avalon/phoenix/components/configuration
                        PersistentConfigurationRepositoryMBean.java
  Log:
  Added ability to get at persisted config data via JMX
  
  Revision  Changes    Path
  1.5       +60 -1     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/FileSystemPersistentConfigurationRepository.java
  
  Index: FileSystemPersistentConfigurationRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/FileSystemPersistentConfigurationRepository.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileSystemPersistentConfigurationRepository.java	19 Jul 2002 18:34:04 -0000	1.4
  +++ FileSystemPersistentConfigurationRepository.java	22 Jul 2002 17:20:37 -0000	1.5
  @@ -20,6 +20,7 @@
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.avalon.excalibur.property.PropertyException;
   import org.apache.avalon.excalibur.property.PropertyUtil;
  +import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -32,7 +33,11 @@
   import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.phoenix.interfaces.ConfigurationRepository;
  +import org.apache.avalon.phoenix.interfaces.SystemManager;
   import org.apache.excalibur.configuration.merged.ConfigurationMerger;
   
   /**
  @@ -43,7 +48,8 @@
    * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
    */
   public class FileSystemPersistentConfigurationRepository extends AbstractLogEnabled
  -    implements ConfigurationRepository, Parameterizable, Configurable, Startable
  +    implements ConfigurationRepository, Parameterizable, Configurable, Startable, Serviceable,
  +    Initializable, PersistentConfigurationRepositoryMBean
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( FileSystemPersistentConfigurationRepository.class );
  @@ -51,6 +57,7 @@
       private final HashMap m_persistedConfigurations = new HashMap();
       private final HashMap m_configurations = new HashMap();
   
  +    private ServiceManager m_serviceManager;
       private String m_phoenixHome;
   
       private File m_storageDirectory;
  @@ -60,6 +67,12 @@
           this.m_phoenixHome = parameters.getParameter( "phoenix.home", ".." );
       }
   
  +    public void service( ServiceManager manager )
  +        throws ServiceException
  +    {
  +        this.m_serviceManager = manager;
  +    }
  +
       private Context createConfigurationContext()
       {
           final DefaultContext ctx = new DefaultContext();
  @@ -128,6 +141,20 @@
           }
       }
   
  +    public void initialize() throws Exception
  +    {
  +        final SystemManager systemManager =
  +            ( SystemManager ) this.m_serviceManager.lookup( SystemManager.ROLE );
  +        final SystemManager context =
  +            systemManager.getSubContext( null, "component" ).getSubContext( "ConfigurationManager",
  +                                                                            "persistent" );
  +
  +        context.register(
  +            "PersistentConfigurationRepository",
  +            this,
  +            new Class[]{PersistentConfigurationRepositoryMBean.class} );
  +    }
  +
       public void start()
           throws Exception
       {
  @@ -253,6 +280,38 @@
           else
           {
               return ConfigurationMerger.merge( p, c );
  +        }
  +    }
  +
  +    public Configuration getPersistentConfiguration( String application, String block )
  +        throws ConfigurationException
  +    {
  +        final Configuration configuration = ( Configuration ) m_persistedConfigurations.get(
  +            new ConfigurationKey( application, block ) );
  +
  +        if( null == configuration )
  +        {
  +            final String message = REZ.getString( "config.error.noconfig", block, application );
  +            throw new ConfigurationException( message );
  +        }
  +
  +        return configuration;
  +    }
  +
  +    public void storePersistentConfiguration( String application,
  +                                              String block,
  +                                              Configuration configuration )
  +        throws ConfigurationException
  +    {
  +        final ConfigurationKey key = new ConfigurationKey( application, block );
  +
  +        if( null == configuration )
  +        {
  +            m_persistedConfigurations.remove( key );
  +        }
  +        else
  +        {
  +            m_persistedConfigurations.put( key, configuration );
           }
       }
   }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/PersistentConfigurationRepositoryMBean.java
  
  Index: PersistentConfigurationRepositoryMBean.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phoenix.components.configuration;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * Management interface to a PersistentConfigurationRepository to allow modification of the
   * persisted configuration bits
   *
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface PersistentConfigurationRepositoryMBean
  {
      /**
       * Retrieve configuration information from the repository
       *
       * @param application Application name
       * @param block Block name to get configuration for
       *
       * @return Configuration information
       *
       * @throws ConfigurationException if no configuration could be found
       */
      Configuration getPersistentConfiguration( String application, String block )
          throws ConfigurationException;
  
      /**
       * Store configuration information in the repository
       *
       * @param application Application name
       * @param block Block name to store configuration for
       * @param configuration information to store.
       *
       * @throws ConfigurationException if configuration could not be stored
       */
      void storePersistentConfiguration( String application,
                                         String block,
                                         Configuration configuration )
          throws ConfigurationException;
  }
  
  
  

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