1 package org.apache.archiva.repository.scanner;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.text.SimpleDateFormat;
23 import java.util.List;
26 import org.apache.commons.collections.CollectionUtils;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
30 * RepositoryScanStatistics - extension to the RepositoryContentStatistics model.
34 public class RepositoryScanStatistics
36 private transient List<String> knownConsumers;
38 private transient List<String> invalidConsumers;
40 private transient long startTimestamp;
42 private SimpleDateFormat df = new SimpleDateFormat();
47 private String repositoryId;
52 private java.util.Date whenGathered;
57 private long duration = 0;
60 * Field totalFileCount
62 private long totalFileCount = 0;
67 private long newFileCount = 0;
72 private long totalSize = 0;
74 private Map<String, Long> consumerCounts;
76 private Map<String, Long> consumerTimings;
78 public void triggerStart()
80 startTimestamp = System.currentTimeMillis();
83 public java.util.Date getWhenGathered()
88 public void triggerFinished()
90 long finished = System.currentTimeMillis();
91 this.duration = finished - startTimestamp;
92 this.whenGathered = new java.util.Date( finished );
95 public void increaseFileCount()
97 long count = getTotalFileCount();
98 this.totalFileCount = ++count;
101 public void increaseNewFileCount()
103 long count = getNewFileCount();
104 this.newFileCount = ++count;
107 public void setKnownConsumers( List<String> consumers )
109 knownConsumers = consumers;
112 public void setInvalidConsumers( List<String> consumers )
114 invalidConsumers = consumers;
117 public String toDump( ManagedRepositoryConfiguration repo )
119 StringBuffer buf = new StringBuffer();
121 buf.append( "\n.\\ Scan of " ).append( this.getRepositoryId() );
122 buf.append( " \\.__________________________________________" );
124 buf.append( "\n Repository Dir : " ).append( repo.getLocation() );
125 buf.append( "\n Repository Name : " ).append( repo.getName() );
126 buf.append( "\n Repository Layout : " ).append( repo.getLayout() );
128 buf.append( "\n Known Consumers : " );
129 if ( CollectionUtils.isNotEmpty( knownConsumers ) )
131 buf.append( "(" ).append( knownConsumers.size() ).append( " configured)" );
132 for ( String id : knownConsumers )
134 buf.append( "\n " ).append( id );
135 if ( consumerTimings.containsKey( id ) )
137 long time = consumerTimings.get( id );
138 buf.append( " (Total: " ).append( time ).append( "ms" );
139 if ( consumerCounts.containsKey( id ) )
141 long total = consumerCounts.get( id );
142 buf.append( "; Avg.: " + ( time / total ) + "; Count: " + total );
150 buf.append( "<none>" );
153 buf.append( "\n Invalid Consumers : " );
154 if ( CollectionUtils.isNotEmpty( invalidConsumers ) )
156 buf.append( "(" ).append( invalidConsumers.size() ).append( " configured)" );
157 for ( String id : invalidConsumers )
159 buf.append( "\n " ).append( id );
160 if ( consumerTimings.containsKey( id ) )
162 long time = consumerTimings.get( id );
163 buf.append( " (Total: " ).append( time ).append( "ms" );
164 if ( consumerCounts.containsKey( id ) )
166 long total = consumerCounts.get( id );
167 buf.append( "; Avg.: " + ( time / total ) + "ms; Count: " + total );
175 buf.append( "<none>" );
178 buf.append( "\n Duration : " );
179 buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
180 buf.append( "\n When Gathered : " );
181 if ( this.getWhenGathered() == null )
183 buf.append( "<null>" );
187 buf.append( df.format( this.getWhenGathered() ) );
190 buf.append( "\n Total File Count : " ).append( this.getTotalFileCount() );
192 long averageMsPerFile = 0;
194 if ( getTotalFileCount() != 0 )
196 averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
199 buf.append( "\n Avg Time Per File : " );
200 buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
201 buf.append( "\n______________________________________________________________" );
203 return buf.toString();
206 public void setRepositoryId( String repositoryId )
208 this.repositoryId = repositoryId;
211 public String getRepositoryId()
216 public long getDuration()
221 public long getTotalFileCount()
223 return totalFileCount;
226 public long getNewFileCount()
231 public long getTotalSize()
236 public void setConsumerCounts( Map<String, Long> consumerCounts )
238 this.consumerCounts = consumerCounts;
241 public void setConsumerTimings( Map<String, Long> consumerTimings )
243 this.consumerTimings = consumerTimings;