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.admin.model.beans.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 long count = getTotalFileCount();
101 this.totalFileCount = ++count;
104 public void increaseNewFileCount()
106 long count = getNewFileCount();
107 this.newFileCount = ++count;
110 public void setKnownConsumers( List<String> consumers )
112 knownConsumers = consumers;
115 public void setInvalidConsumers( List<String> consumers )
117 invalidConsumers = consumers;
120 public String toDump( ManagedRepository repo )
122 StringBuilder buf = new StringBuilder();
124 buf.append( "\n.\\ Scan of " ).append( this.getRepositoryId() );
125 buf.append( " \\.__________________________________________" );
127 buf.append( "\n Repository Dir : " ).append( repo.getLocation() );
128 buf.append( "\n Repository Name : " ).append( repo.getName() );
129 buf.append( "\n Repository Layout : " ).append( repo.getLayout() );
131 buf.append( "\n Known Consumers : " );
132 if ( CollectionUtils.isNotEmpty( knownConsumers ) )
134 buf.append( "(" ).append( knownConsumers.size() ).append( " configured)" );
135 for ( String id : knownConsumers )
137 buf.append( "\n " ).append( id );
138 if ( consumerTimings.containsKey( id ) )
140 long time = consumerTimings.get( id );
141 buf.append( " (Total: " ).append( time ).append( "ms" );
142 if ( consumerCounts.containsKey( id ) )
144 long total = consumerCounts.get( id );
145 buf.append( "; Avg.: " + ( time / total ) + "; Count: " + total );
153 buf.append( "<none>" );
156 buf.append( "\n Invalid Consumers : " );
157 if ( CollectionUtils.isNotEmpty( invalidConsumers ) )
159 buf.append( "(" ).append( invalidConsumers.size() ).append( " configured)" );
160 for ( String id : invalidConsumers )
162 buf.append( "\n " ).append( id );
163 if ( consumerTimings.containsKey( id ) )
165 long time = consumerTimings.get( id );
166 buf.append( " (Total: " ).append( time ).append( "ms" );
167 if ( consumerCounts.containsKey( id ) )
169 long total = consumerCounts.get( id );
170 buf.append( "; Avg.: " + ( time / total ) + "ms; Count: " + total );
178 buf.append( "<none>" );
181 buf.append( "\n Duration : " );
182 buf.append( org.apache.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
183 buf.append( "\n When Gathered : " );
184 if ( this.getWhenGathered() == null )
186 buf.append( "<null>" );
190 buf.append( df.format( this.getWhenGathered() ) );
193 buf.append( "\n Total File Count : " ).append( this.getTotalFileCount() );
195 long averageMsPerFile = 0;
197 if ( getTotalFileCount() != 0 )
199 averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
202 buf.append( "\n Avg Time Per File : " );
203 buf.append( org.apache.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
204 buf.append( "\n______________________________________________________________" );
206 return buf.toString();
209 public void setRepositoryId( String repositoryId )
211 this.repositoryId = repositoryId;
214 public String getRepositoryId()
219 public long getDuration()
224 public long getTotalFileCount()
226 return totalFileCount;
229 public long getNewFileCount()
234 public long getTotalSize()
239 public void setConsumerCounts( Map<String, Long> consumerCounts )
241 this.consumerCounts = consumerCounts;
244 public void setConsumerTimings( Map<String, Long> consumerTimings )
246 this.consumerTimings = consumerTimings;