cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/generation EventCacheGenerator.java
Date Mon, 29 Mar 2004 12:31:25 GMT
cziegeler    2004/03/29 04:31:25

  Modified:    src/blocks/eventcache/java/org/apache/cocoon/acting
                        CacheEventAction.java
               src/blocks/eventcache/java/org/apache/cocoon/generation
                        EventCacheGenerator.java
  Log:
  Make cache role configurable on event action
  Always release cache in action
  Use ServiceSelector and dispose selector in generator
  
  Revision  Changes    Path
  1.6       +17 -12    cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/acting/CacheEventAction.java
  
  Index: CacheEventAction.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/acting/CacheEventAction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CacheEventAction.java	5 Mar 2004 13:01:56 -0000	1.5
  +++ CacheEventAction.java	29 Mar 2004 12:31:25 -0000	1.6
  @@ -50,19 +50,24 @@
                       String src,
                       Parameters par
       ) throws Exception {
  -        Cache cache = (Cache)this.manager.lookup(Cache.ROLE + "/EventAware");
  -        if (cache instanceof EventAwareCacheImpl) {
  -            String eventName = par.getParameter("event");
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("Configured for cache event named: " + eventName);
  +        final String cacheRole = par.getParameter("cache-role", Cache.ROLE + "/EventAware");
  +        Cache cache = (Cache)this.manager.lookup(cacheRole);
  +        try {
  +            // FIXME - This cast might not work with every container!
  +            if (cache instanceof EventAwareCacheImpl) {
  +                String eventName = par.getParameter("event");
  +                if (getLogger().isDebugEnabled()) {
  +                    getLogger().debug("Configured for cache event named: " + eventName);
  +                }
  +                if (eventName == null || "".equals(eventName)) {
  +                    return null;
  +                }
  +                ((EventAwareCacheImpl)cache).processEvent(
  +                                                    new NamedEvent(eventName));
               }
  -            if (eventName == null || "".equals(eventName)) {
  -                return null;
  -            }
  -            ((EventAwareCacheImpl)cache).processEvent(
  -                                                new NamedEvent(eventName));
  +        } finally {
  +            this.manager.release(cache);
           }
  -        this.manager.release(cache);
           return EMPTY_MAP;
       }
   }
  
  
  
  1.5       +39 -10    cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/generation/EventCacheGenerator.java
  
  Index: EventCacheGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/generation/EventCacheGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EventCacheGenerator.java	5 Mar 2004 13:01:56 -0000	1.4
  +++ EventCacheGenerator.java	29 Mar 2004 12:31:25 -0000	1.5
  @@ -20,8 +20,6 @@
   import java.util.HashMap;
   import java.util.Map;
   
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -29,6 +27,7 @@
   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.ServiceSelector;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CacheableProcessingComponent;
   import org.apache.cocoon.caching.validity.Event;
  @@ -100,7 +99,7 @@
       
       // ---------------------------------------------------- member variables
       
  -    private ComponentSelector m_generatorSelector;
  +    private ServiceSelector m_generatorSelector;
       private Generator m_delegate;
       private Serializable m_key;
       private Event m_event;
  @@ -108,14 +107,18 @@
       private Map m_types = new HashMap();
       
       
  -    // ---------------------------------------------------- lifecycle methods
  -    
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
  +     */
       public void service(ServiceManager manager)  throws ServiceException {
           super.service(manager);
  -        m_generatorSelector = (ComponentSelector) 
  +        m_generatorSelector = (ServiceSelector) 
               manager.lookup(Generator.ROLE + "Selector");
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
  +     */
       public void configure(Configuration configuration) throws ConfigurationException {
           Configuration[] factories = configuration.getChildren(FACTORY_CONF);
           for (int i = 0; i < factories.length; i++) {
  @@ -139,9 +142,12 @@
           }
       }
       
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
  +     */
       public void setup(SourceResolver resolver, Map objectModel, String src,
                         Parameters par)
  -        throws ProcessingException, SAXException, IOException {
  +    throws ProcessingException, SAXException, IOException {
   
           // delegate
           String delegate = par.getParameter(DELEGATE_PARAM, null);
  @@ -152,7 +158,7 @@
           }
           try {
               m_delegate = (Generator) m_generatorSelector.select(delegate);
  -        } catch (ComponentException e) {
  +        } catch (ServiceException e) {
               final String message =
                   "Transformer '" + delegate + "' could not be found.";
               throw new ProcessingException(message); 
  @@ -176,14 +182,23 @@
           m_key = SourceUtil.appendParameters(src,par);
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.xml.XMLProducer#setConsumer(org.apache.cocoon.xml.XMLConsumer)
  +     */
       public void setConsumer(XMLConsumer consumer) {
           m_delegate.setConsumer(consumer);
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.generation.Generator#generate()
  +     */
       public void generate() throws IOException, SAXException, ProcessingException {
           m_delegate.generate();
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
  +     */
       public void recycle() {
           if ( m_delegate != null ) {
               m_generatorSelector.release(m_delegate);
  @@ -195,14 +210,28 @@
       }
   
       
  -    // ---------------------------------------------------- caching strategy
  -    
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
  +     */
       public Serializable getKey() {
           return m_key;
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
  +     */
       public SourceValidity getValidity() {
           return new EventValidity(m_event);
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.activity.Disposable#dispose()
  +     */
  +    public void dispose() {
  +        if ( this.manager != null ) {
  +            this.manager.release(m_generatorSelector);
  +            m_generatorSelector = null;
  +        }
  +        super.dispose();
  +    }
   }
  
  
  

Mime
View raw message