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 org.apache.archiva.repository.ManagedRepository;
23 import org.apache.commons.collections.CollectionUtils;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28 import java.util.List;
32 * RepositoryScanStatistics - extension to the RepositoryContentStatistics model.
36 @XmlRootElement( name = "repositoryScanStatistics" )
37 public class RepositoryScanStatistics
39 private transient List<String> knownConsumers;
41 private transient List<String> invalidConsumers;
43 private transient long startTimestamp;
45 private SimpleDateFormat df = new SimpleDateFormat();
50 private String repositoryId;
55 private Date whenGathered;
60 private long duration = 0;
63 * Field totalFileCount
65 private long totalFileCount = 0;
70 private long newFileCount = 0;
75 private long totalSize = 0;
77 private Map<String, Long> consumerCounts;
79 private Map<String, Long> consumerTimings;
81 public void triggerStart()
83 startTimestamp = System.currentTimeMillis();
86 public java.util.Date getWhenGathered()
91 public void triggerFinished()
93 long finished = System.currentTimeMillis();
94 this.duration = finished - startTimestamp;
95 this.whenGathered = new java.util.Date( finished );
98 public void increaseFileCount()
100 this.totalFileCount += 1;
103 public void increaseNewFileCount()
105 this.newFileCount += 1;
108 public void setKnownConsumers( List<String> consumers )
110 knownConsumers = consumers;
113 public void setInvalidConsumers( List<String> consumers )
115 invalidConsumers = consumers;
118 public String toDump( ManagedRepository repo )
120 StringBuilder buf = new StringBuilder();
122 buf.append( "\n.\\ Scan of " ).append( this.getRepositoryId() );
123 buf.append( " \\.__________________________________________" );
125 buf.append( "\n Repository Dir : " ).append( repo.getLocation() );
126 buf.append( "\n Repository Name : " ).append( repo.getName() );
127 buf.append( "\n Repository Layout : " ).append( repo.getLayout() );
129 buf.append( "\n Known Consumers : " );
130 if ( CollectionUtils.isNotEmpty( knownConsumers ) )
132 buf.append( "(" ).append( knownConsumers.size() ).append( " configured)" );
133 for ( String id : knownConsumers )
135 buf.append( "\n " ).append( id );
136 if ( consumerTimings.containsKey( id ) )
138 long time = consumerTimings.get( id );
139 buf.append( " (Total: " ).append( time ).append( "ms" );
140 if ( consumerCounts.containsKey( id ) )
142 long total = consumerCounts.get( id );
143 buf.append( "; Avg.: " + ( time / total ) + "; Count: " + total );
151 buf.append( "<none>" );
154 buf.append( "\n Invalid Consumers : " );
155 if ( CollectionUtils.isNotEmpty( invalidConsumers ) )
157 buf.append( "(" ).append( invalidConsumers.size() ).append( " configured)" );
158 for ( String id : invalidConsumers )
160 buf.append( "\n " ).append( id );
161 if ( consumerTimings.containsKey( id ) )
163 long time = consumerTimings.get( id );
164 buf.append( " (Total: " ).append( time ).append( "ms" );
165 if ( consumerCounts.containsKey( id ) )
167 long total = consumerCounts.get( id );
168 buf.append( "; Avg.: " + ( time / total ) + "ms; Count: " + total );
176 buf.append( "<none>" );
179 buf.append( "\n Duration : " );
180 buf.append( org.apache.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
181 buf.append( "\n When Gathered : " );
182 if ( this.getWhenGathered() == null )
184 buf.append( "<null>" );
188 buf.append( df.format( this.getWhenGathered() ) );
191 buf.append( "\n Total File Count : " ).append( this.getTotalFileCount() );
193 long averageMsPerFile = 0;
195 if ( getTotalFileCount() != 0 )
197 averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
200 buf.append( "\n Avg Time Per File : " );
201 buf.append( org.apache.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
202 buf.append( "\n______________________________________________________________" );
204 return buf.toString();
207 public void setRepositoryId( String repositoryId )
209 this.repositoryId = repositoryId;
212 public String getRepositoryId()
217 public long getDuration()
222 public long getTotalFileCount()
224 return totalFileCount;
227 public long getNewFileCount()
232 public long getTotalSize()
237 public void setConsumerCounts( Map<String, Long> consumerCounts )
239 this.consumerCounts = consumerCounts;
242 public void setConsumerTimings( Map<String, Long> consumerTimings )
244 this.consumerTimings = consumerTimings;