Coverage report

  %line %branch
org.apache.jetspeed.aggregator.impl.PortletTrackingManagerImpl
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.aggregator.impl;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import org.apache.jetspeed.aggregator.PortletTrackingManager;
 27  
 import org.apache.jetspeed.aggregator.RenderTrackable;
 28  
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
 29  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 30  
 import org.apache.pluto.om.window.PortletWindow;
 31  
 
 32  
 /**
 33  
  * Tracks out of service status for portlets
 34  
  *  
 35  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 36  
  * @version $Id: $
 37  
  */
 38  
 public class PortletTrackingManagerImpl implements PortletTrackingManager
 39  
 {
 40  0
     protected Map outOfService = Collections.synchronizedMap(new HashMap());
 41  
 
 42  
     /**
 43  
      * when rendering a portlet, the default timeout period in milliseconds
 44  
      * setting to zero will disable (no timeout) the timeout
 45  
      *  
 46  
      */
 47  
     protected long defaultPortletTimeout; 
 48  
     
 49  
     /**
 50  
      * Out of service limit, if a portlet entity times out past its limit (or default limit) n consecutive times, 
 51  
      * it is taken out of service
 52  
      */
 53  
     protected int outOfServiceLimit;
 54  
     
 55  
     protected PortletWindowAccessor windowAccessor;
 56  
     
 57  
     public PortletTrackingManagerImpl(PortletWindowAccessor windowAccessor, long defaultPortletTimeout, int outOfServiceLimit)
 58  0
     {
 59  0
         this.windowAccessor = windowAccessor;
 60  0
         this.defaultPortletTimeout = defaultPortletTimeout;
 61  0
         this.outOfServiceLimit = outOfServiceLimit;
 62  0
     }
 63  
     
 64  
     public long getDefaultPortletTimeout()
 65  
     {
 66  0
         return this.defaultPortletTimeout;
 67  
     }
 68  
 
 69  
     public boolean exceededTimeout(long renderTime, PortletWindow window)
 70  
     {
 71  0
         RenderTrackable trackInfo = (RenderTrackable)window.getPortletEntity();
 72  0
         long defaultTimeout = this.getDefaultPortletTimeout();
 73  0
         if (trackInfo.getExpiration() > 0)
 74  
         {
 75  0
             return (renderTime > trackInfo.getExpiration());
 76  
         }
 77  0
         else if (defaultTimeout > 0)
 78  
         {
 79  0
             return (renderTime > defaultTimeout);
 80  
         }
 81  0
         return false;
 82  
     }
 83  
     
 84  
     public boolean isOutOfService(PortletWindow window)
 85  
     {
 86  0
         RenderTrackable trackable = (RenderTrackable)window.getPortletEntity();
 87  0
         if (trackable.getRenderTimeoutCount() > this.outOfServiceLimit)
 88  
         {
 89  0
             return true;
 90  
         }
 91  0
         return false;
 92  
     }
 93  
     
 94  
     public int getOutOfServiceLimit()
 95  
     {
 96  0
         return this.outOfServiceLimit;
 97  
     }
 98  
     
 99  
     public void incrementRenderTimeoutCount(PortletWindow window)
 100  
     {
 101  0
         RenderTrackable trackable = (RenderTrackable)window.getPortletEntity();
 102  0
         trackable.incrementRenderTimeoutCount();       
 103  0
     }
 104  
    
 105  
     public void success(PortletWindow window)
 106  
     {
 107  0
         RenderTrackable trackable = (RenderTrackable)window.getPortletEntity();
 108  0
         trackable.success();
 109  0
     }
 110  
     
 111  
     public void setExpiration(PortletWindow window, long expiration)
 112  
     {
 113  0
         RenderTrackable trackable = (RenderTrackable)window.getPortletEntity();
 114  0
         trackable.setExpiration(expiration); // * 1000);                
 115  0
     }
 116  
         
 117  
     public void takeOutOfService(PortletWindow window)
 118  
     {
 119  0
         RenderTrackable trackable = (RenderTrackable)window.getPortletEntity();
 120  0
         trackable.setRenderTimeoutCount((int)this.defaultPortletTimeout + 1);
 121  0
     }
 122  
     
 123  
     public void putIntoService(PortletWindow window)
 124  
     {
 125  0
         RenderTrackable trackable = (RenderTrackable)window.getPortletEntity();
 126  0
         trackable.setRenderTimeoutCount(0);        
 127  0
     }
 128  
     
 129  
     public void putIntoService(List fullPortletNames)
 130  
     {
 131  0
         Iterator windows = this.windowAccessor.getPortletWindows().iterator();
 132  0
         while (windows.hasNext())
 133  
         {
 134  0
             PortletWindow window = (PortletWindow)windows.next();
 135  0
             PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();          
 136  0
             for (int ix = 0; ix < fullPortletNames.size(); ix++)
 137  
             {
 138  0
                 if (pd.getUniqueName().equals(fullPortletNames.get(ix)))
 139  
                 {
 140  0
                     putIntoService(window);
 141  
                 }
 142  
             }
 143  0
         }        
 144  0
     }
 145  
     
 146  
     public List getOutOfServiceList(String fullPortletName)
 147  
     {
 148  0
         List outs = new ArrayList();
 149  0
         Iterator windows = this.windowAccessor.getPortletWindows().iterator();
 150  0
         while (windows.hasNext())
 151  
         {
 152  0
             PortletWindow window = (PortletWindow)windows.next();
 153  0
             PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
 154  0
             if (pd.getUniqueName().equals(fullPortletName) && isOutOfService(window))
 155  
             {
 156  0
                 outs.add(window);
 157  
             }
 158  0
         }
 159  0
         return outs;
 160  
     }
 161  
     
 162  
     public List getOutOfServiceList()
 163  
     {
 164  0
         List outs = new ArrayList();
 165  0
         Iterator windows = this.windowAccessor.getPortletWindows().iterator();
 166  0
         while (windows.hasNext())
 167  
         {
 168  0
             PortletWindow window = (PortletWindow)windows.next();
 169  0
             if (isOutOfService(window))
 170  
             {
 171  0
                 outs.add(window);                
 172  
             }
 173  0
         }
 174  0
         return outs;
 175  
     }
 176  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.