portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggol...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets AbstractInstancePortlet.java
Date Wed, 15 May 2002 02:46:12 GMT
ggolden     02/05/14 19:46:11

  Modified:    webapp/WEB-INF/conf TurbineResources.properties
               src/java/org/apache/jetspeed/services/portletfactory
                        JetspeedPortletFactoryService.java
               src/java/org/apache/jetspeed/portal/portlets
                        AbstractInstancePortlet.java
  Added:       src/java/org/apache/jetspeed/services/rundata
                        JetspeedRunDataService.java
  Log:
  Introducing the JetspeedRunDataService, an extension of the
  TurbineRunDataService which keeps track, for each active thread
  processing a request, of the JetspeedRunData assigned to that request.
  Clients of this service can call for the runData at any time during the request
  processing, even if the runData was not passed as a parameter.
  
  TurbineResources.properties updated to use this service as our RunDataService.
  
  JetspeedPortletFactoryService uses the service to fill out the pageId in the PortletConfig
  (also changed the cache debug logging).
  
  AbstractInstancePortlet completed to include the PortletConfig's pageId as well
  as the portletId in the cache handle (also added some comments).
  
  Revision  Changes    Path
  1.52      +2 -2      jakarta-jetspeed/webapp/WEB-INF/conf/TurbineResources.properties
  
  Index: TurbineResources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/TurbineResources.properties,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- TurbineResources.properties	9 May 2002 08:44:54 -0000	1.51
  +++ TurbineResources.properties	15 May 2002 02:46:10 -0000	1.52
  @@ -1,5 +1,5 @@
   # -------------------------------------------------------------------
  -# $Id: TurbineResources.properties,v 1.51 2002/05/09 08:44:54 kimptoc Exp $
  +# $Id: TurbineResources.properties,v 1.52 2002/05/15 02:46:10 ggolden Exp $
   #
   # This is the configuration file for Turbine.
   #
  @@ -433,7 +433,7 @@
   services.LoggingService.classname=org.apache.turbine.services.logging.TurbineLoggingService
   services.FactoryService.classname=org.apache.turbine.services.factory.TurbineFactoryService
   services.PoolService.classname=org.apache.turbine.services.pool.TurbinePoolService
  -services.RunDataService.classname=org.apache.turbine.services.rundata.TurbineRunDataService
  +services.RunDataService.classname=org.apache.jetspeed.services.rundata.JetspeedRunDataService
   services.ServletService.classname=org.apache.turbine.services.servlet.TurbineServletService
   services.AssemblerBrokerService.classname=org.apache.turbine.services.assemblerbroker.TurbineAssemblerBrokerService
   services.LocalizationService.classname=org.apache.turbine.services.localization.TurbineLocalizationService
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/rundata/JetspeedRunDataService.java
  
  Index: JetspeedRunDataService.java
  ===================================================================
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/rundata/JetspeedRunDataService.java,v
1.1 2002/05/15 02:46:10 ggolden Exp $
  *
  * ====================================================================
  *
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" and
  *     "Apache Jetspeed" must not be used to endorse or promote products
  *    derived from this software without prior written permission. For
  *    written permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache" or
  *    "Apache Jetspeed", nor may "Apache" appear in their name, without
  *    prior written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  *
  **********************************************************************************/
  
  // package
  package org.apache.jetspeed.services.rundata;
  
  // imports
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Map;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  import org.apache.turbine.services.rundata.TurbineRunDataService;
  import org.apache.turbine.services.InitializationException;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.util.Log;
  
  import org.apache.jetspeed.services.rundata.JetspeedRunData;
  
  
  /**
  * The JetspeedRunDataService extends TurbineRunDataService,
  * adding the ability to get the current runData object for the thread
  * at any time.  This is accomplished by storing the active runData objects
  * in a map, keyed by thread.
  *
  * @author <a href="mailto:ggolden@umich.edu">Glenn R. Golden</a>
  * @version $Revision: 1.1 $
  */
  public class JetspeedRunDataService
      extends TurbineRunDataService 
  {
      /** The collection of active JetspeedRunData objects, keyed by Thread. */
      private Map m_runDataStore = null;
  
      /*******************************************************************************
      * Service implementation
      *******************************************************************************/
  
      /**
      * Initializes the service
      *
      * @throws InitializationException if initialization fails.
      */
      public void init()
          throws InitializationException
      {
          super.init();
  
          // allocate a thread-safe map
          m_runDataStore = Collections.synchronizedMap(new HashMap());
  
      }   // init
  
      /*******************************************************************************
      * TurbineRunDataService implementation
      *******************************************************************************/
  
      /**
      * Gets a RunData instance from a specific configuration.
      *
      * @param key a configuration key.
      * @param req a servlet request.
      * @param res a servlet response.
      * @param config a servlet config.
      * @return a new or recycled RunData object.
      * @throws TurbineException if the operation fails.
      * @throws IllegalArgumentException if any of the parameters are null.
      */
      public RunData getRunData(String key,
                                  HttpServletRequest req,
                                  HttpServletResponse res,
                                  ServletConfig config)
          throws TurbineException, IllegalArgumentException
      {
          // let the super do the work
          JetspeedRunData r = (JetspeedRunData)super.getRunData(key, req, res, config);
  
          // store the rundata associated with this thread
          m_runDataStore.put(Thread.currentThread(), r);
  
          if (Log.getLogger().isDebugEnabled())
              Log.debug("JetspeedRunDataService: storing rundata " + r
                          + " for thread: " + Thread.currentThread());
  
          return r;
  
      }   // getRunData
  
      /**
      * Puts the used RunData object back to the factory for recycling.
      *
      * @param data the used RunData object.
      * @return true, if pooling is supported and the object was accepted.
      */
      public boolean putRunData(RunData data)
      {
          // remove this thread's rundata
          m_runDataStore.remove(Thread.currentThread());
  
          if (Log.getLogger().isDebugEnabled())
              Log.debug("JetspeedRunDataService: releasing rundata for thread: "
                  + Thread.currentThread());
  
          // let super do the work
          return super.putRunData(data);
  
      }   // putRunData
  
      /**
      * Access the current rundata object - the one associated with the current thread.
      * @return The current JetspeedRunData object associatd with the current thread.
      */
      public JetspeedRunData getCurrentRunData()
      {
          if (Log.getLogger().isDebugEnabled())
              Log.debug("JetspeedRunDataService: accessing rundata "
                          + m_runDataStore.get(Thread.currentThread())
                          + " for thread: " + Thread.currentThread());
  
          return (JetspeedRunData) m_runDataStore.get(Thread.currentThread());
  
      }   // getCurrentRunData
  
  }   // JetspeedRunDataService
  
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/rundata/JetspeedRunDataService.java,v
1.1 2002/05/15 02:46:10 ggolden Exp $
  *
  **********************************************************************************/
  
  
  
  
  1.11      +38 -6     jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletfactory/JetspeedPortletFactoryService.java
  
  Index: JetspeedPortletFactoryService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletfactory/JetspeedPortletFactoryService.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JetspeedPortletFactoryService.java	14 May 2002 06:32:59 -0000	1.10
  +++ JetspeedPortletFactoryService.java	15 May 2002 02:46:10 -0000	1.11
  @@ -71,14 +71,18 @@
   import org.apache.jetspeed.services.portletcache.Cacheable;
   import org.apache.jetspeed.om.registry.PortletEntry;
   import org.apache.jetspeed.om.registry.SkinEntry;
  +import org.apache.jetspeed.om.profile.Profile;
   import org.apache.jetspeed.util.MetaData;
   import org.apache.jetspeed.util.JetspeedException;
  +import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
  +import org.apache.jetspeed.services.rundata.JetspeedRunData;
   
   import org.apache.turbine.services.TurbineServices;
   import org.apache.turbine.services.TurbineBaseService;
   import org.apache.turbine.services.InitializationException;
   import org.apache.turbine.services.resources.ResourceService;
   import org.apache.turbine.util.Log;
  +import org.apache.turbine.services.rundata.RunDataService;
   
   import java.util.Enumeration;
   import java.util.Hashtable;
  @@ -90,7 +94,7 @@
    * Simple implementation of the PortalFactoryService.
    * 
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  - * @version $Id: JetspeedPortletFactoryService.java,v 1.10 2002/05/14 06:32:59 taylor Exp
$
  + * @version $Id: JetspeedPortletFactoryService.java,v 1.11 2002/05/15 02:46:10 ggolden
Exp $
    */
   public class JetspeedPortletFactoryService extends TurbineBaseService
       implements PortletFactoryService
  @@ -99,6 +103,9 @@
       /** The default control to use when none is specified */
       private boolean enableCache = false;
   
  +    /** The JetspeedRunData Service. */
  +    private JetspeedRunDataService runDataService = null;
  +    
       /**
        * This is the early initialization method called by the 
        * Turbine <code>Service</code> framework
  @@ -111,8 +118,12 @@
   
           this.enableCache = serviceConf.getBoolean("enable.cache",true);
           
  -        setInit(true);
  +        // get the runData service
  +        this.runDataService =
  +            (JetspeedRunDataService)TurbineServices.getInstance()
  +                .getService(RunDataService.SERVICE_NAME);
   
  +        setInit(true);
       }
               
       /**
  @@ -282,8 +293,16 @@
                   //publicly accessible.
                   //Alternative: we could wrap the portlet before putting
                   //it in the cache.
  +
  +                //now compute the time it took to instantate and log it...
  +                // time in millis, sugested by Thomas Schaeck (schaeck@de.ibm.com)
  +                long milliseconds = ( System.currentTimeMillis() - begin );
  +        
  +                if (Log.getLogger().isDebugEnabled())
  +                    Log.debug( "PortletFactory.getPortlet(): found in cache in "
  +                        + milliseconds + " ms - handle: " + handle );
  +
                   return PortletWrapper.wrap( portlet );
  -                
               }
   
               // if not found in the cache, instanciate a new Portlet
  @@ -346,7 +365,9 @@
           // time in millis, sugested by Thomas Schaeck (schaeck@de.ibm.com)
           long milliseconds = ( System.currentTimeMillis() - begin );
   
  -        Log.debug( "PortletFactory.getPortlet(): took a total of " + milliseconds + " millisecond(s)
-> " + handle );
  +        if (Log.getLogger().isDebugEnabled())
  +            Log.debug( "PortletFactory.getPortlet(): constructed in "
  +                + milliseconds + " ms - handle: " + handle );
   
           return PortletWrapper.wrap( portlet );
   
  @@ -370,9 +391,20 @@
           pc.setMetainfo( getMetaData( entry ) );
           pc.setURL( entry.getURL() );
           pc.setCachedOnURL( entry.isCachedOnURL() );
  -        //pc.setPageId(pageId); // LEFT OFF HERE: need to get the page id somehow
  +        if (runDataService != null)
  +        {
  +            JetspeedRunData rundata = runDataService.getCurrentRunData();
  +            if (rundata != null)
  +            {
  +                Profile profile = rundata.getProfile();
  +                if (profile != null)
  +                {
  +                    pc.setPageId(profile.getId());
  +                }
  +            }
  +        }
           pc.setPortletId(id);
  -        
  +
           return pc;
       }
       
  
  
  
  1.2       +26 -18    jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/AbstractInstancePortlet.java
  
  Index: AbstractInstancePortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/AbstractInstancePortlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractInstancePortlet.java	14 May 2002 06:32:59 -0000	1.1
  +++ AbstractInstancePortlet.java	15 May 2002 02:46:11 -0000	1.2
  @@ -1,5 +1,3 @@
  -package org.apache.jetspeed.portal.portlets;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -54,15 +52,26 @@
    * <http://www.apache.org/>.
    */
   
  +// package
  +package org.apache.jetspeed.portal.portlets;
  +
  +// imports
   import org.apache.jetspeed.portal.PortletConfig;
   
  - /** ClearPortlet
  -  * Empty Portlet which displays no content
  -  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  -  */
  -public class AbstractInstancePortlet extends AbstractPortlet 
  +/**
  +* Extend AbstractPortlet to re-define the handle used for portlet caching:
  +* This handle uses the portlet's unique id and the portal page's id to form
  +* a portlet instance id for caching.
  +* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  +* @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>
  +*/
  +public class AbstractInstancePortlet
  +    extends AbstractPortlet
   {
  -    
  +    /**
  +    * Construct the handle used for caching.
  +    * @param config The config object, expected to be a PortletConfig.
  +    */
       public static Object getHandle(Object config)
       {
           //this implementation expects a PortletConfig object as its
  @@ -71,22 +80,21 @@
   
           if (!(config instanceof PortletConfig))
           {
  -            return null;
  -            
  +            return null;            
           }
   
  -        // By default, only take into account the init parameters 
  +        // form the key from the current request's portal page profile
  +        // and the portlet id in the config
           pc = (PortletConfig)config;
  -        StringBuffer handle = new StringBuffer(256);
   
  -        //handle.append(pc.getPageId());
  -        //handle.append("/");
  +        StringBuffer handle = new StringBuffer(256);
  +        handle.append(pc.getPageId());
  +        handle.append('/');
           handle.append(pc.getPortletId());
   
  -        return handle.toString();
  -        
  -    }
  +        return handle.toString();   
   
  -}
  +    }   // getHandle
   
  +}   // AbstractInstancePortlet
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message