Coverage Report - org.apache.maven.archiva.repository.scanner.RepositoryScanStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
RepositoryScanStatistics
0%
0/70
0%
0/20
0
 
 1  
 package org.apache.maven.archiva.repository.scanner;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.commons.collections.CollectionUtils;
 23  
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 24  
 import org.apache.maven.archiva.model.RepositoryContentStatistics;
 25  
 
 26  
 import java.text.SimpleDateFormat;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * RepositoryScanStatistics - extension to the RepositoryContentStatistics model.
 32  
  *
 33  
  * @version $Id: RepositoryScanStatistics.java 1042689 2010-12-06 15:56:35Z brett $
 34  
  */
 35  0
 public class RepositoryScanStatistics
 36  
     extends RepositoryContentStatistics
 37  
 {
 38  
     private transient List<String> knownConsumers;
 39  
 
 40  
     private transient List<String> invalidConsumers;
 41  
 
 42  
     private transient long startTimestamp;
 43  
     
 44  0
     private SimpleDateFormat df = new SimpleDateFormat();
 45  
 
 46  
     private Map<String, Long> consumerCounts;
 47  
 
 48  
     private Map<String, Long> consumerTimings;
 49  
 
 50  
     public void triggerStart()
 51  
     {
 52  0
         startTimestamp = System.currentTimeMillis();
 53  0
     }
 54  
 
 55  
     public void triggerFinished()
 56  
     {
 57  0
         long finished = System.currentTimeMillis();
 58  0
         setDuration( finished - startTimestamp );
 59  0
         setWhenGathered( new java.util.Date( finished ) );
 60  0
     }
 61  
 
 62  
     public void increaseFileCount()
 63  
     {
 64  0
         long count = getTotalFileCount();
 65  0
         setTotalFileCount( ++count );
 66  0
     }
 67  
 
 68  
     public void increaseNewFileCount()
 69  
     {
 70  0
         long count = getNewFileCount();
 71  0
         setNewFileCount( ++count );
 72  0
     }
 73  
 
 74  
     public void setKnownConsumers( List<String> consumers )
 75  
     {
 76  0
         knownConsumers = consumers;
 77  0
     }
 78  
 
 79  
     public void setInvalidConsumers( List<String> consumers )
 80  
     {
 81  0
         invalidConsumers = consumers;
 82  0
     }
 83  
 
 84  
     public String toDump( ManagedRepositoryConfiguration repo )
 85  
     {
 86  0
         StringBuffer buf = new StringBuffer();
 87  
 
 88  0
         buf.append( "\n.\\ Scan of " ).append( this.getRepositoryId() );
 89  0
         buf.append( " \\.__________________________________________" );
 90  
 
 91  0
         buf.append( "\n  Repository Dir    : " ).append( repo.getLocation() );
 92  0
         buf.append( "\n  Repository Name   : " ).append( repo.getName() );
 93  0
         buf.append( "\n  Repository Layout : " ).append( repo.getLayout() );
 94  
 
 95  0
         buf.append( "\n  Known Consumers   : " );
 96  0
         if ( CollectionUtils.isNotEmpty( knownConsumers ) )
 97  
         {
 98  0
             buf.append( "(" ).append( knownConsumers.size() ).append( " configured)" );
 99  0
             for ( String id : knownConsumers )
 100  
             {
 101  0
                 buf.append( "\n                      " ).append( id );
 102  0
                 if ( consumerTimings.containsKey( id ) )
 103  
                 {
 104  0
                     long time = consumerTimings.get( id );
 105  0
                     buf.append( " (Total: " ).append( time ).append( "ms" );
 106  0
                     if ( consumerCounts.containsKey( id ) )
 107  
                     {
 108  0
                         long total = consumerCounts.get( id );
 109  0
                         buf.append( "; Avg.: " + ( time / total ) + "; Count: " + total );
 110  
                     }
 111  0
                     buf.append( ")" );
 112  0
                 }
 113  
             }
 114  
         }
 115  
         else
 116  
         {
 117  0
             buf.append( "<none>" );
 118  
         }
 119  
 
 120  0
         buf.append( "\n  Invalid Consumers : " );
 121  0
         if ( CollectionUtils.isNotEmpty( invalidConsumers ) )
 122  
         {
 123  0
             buf.append( "(" ).append( invalidConsumers.size() ).append( " configured)" );
 124  0
             for ( String id : invalidConsumers )
 125  
             {
 126  0
                 buf.append( "\n                      " ).append( id );
 127  0
                 if ( consumerTimings.containsKey( id ) )
 128  
                 {
 129  0
                     long time = consumerTimings.get( id );
 130  0
                     buf.append( " (Total: " ).append( time ).append( "ms" );
 131  0
                     if ( consumerCounts.containsKey( id ) )
 132  
                     {
 133  0
                         long total = consumerCounts.get( id );
 134  0
                         buf.append( "; Avg.: " + ( time / total ) + "ms; Count: " + total );
 135  
                     }
 136  0
                     buf.append( ")" );
 137  0
                 }
 138  
             }
 139  
         }
 140  
         else
 141  
         {
 142  0
             buf.append( "<none>" );
 143  
         }
 144  
 
 145  0
         buf.append( "\n  Duration          : " );
 146  0
         buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
 147  0
         buf.append( "\n  When Gathered     : " );
 148  0
         if ( this.getWhenGathered() == null )
 149  
         {
 150  0
             buf.append( "<null>" );
 151  
         }
 152  
         else
 153  
         {
 154  0
             buf.append( df.format( this.getWhenGathered() ) );
 155  
         }
 156  
 
 157  0
         buf.append( "\n  Total File Count  : " ).append( this.getTotalFileCount() );
 158  
 
 159  0
         long averageMsPerFile = 0;
 160  
 
 161  0
         if ( getTotalFileCount() != 0 )
 162  
         {
 163  0
             averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
 164  
         }
 165  
 
 166  0
         buf.append( "\n  Avg Time Per File : " );
 167  0
         buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
 168  0
         buf.append( "\n______________________________________________________________" );
 169  
 
 170  0
         return buf.toString();
 171  
     }
 172  
 
 173  
     public void setConsumerCounts( Map<String, Long> consumerCounts )
 174  
     {
 175  0
         this.consumerCounts = consumerCounts;
 176  0
     }
 177  
 
 178  
     public void setConsumerTimings( Map<String, Long> consumerTimings )
 179  
     {
 180  0
         this.consumerTimings = consumerTimings;
 181  0
     }
 182  
 }