You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryScanStatistics.java 6.8KB

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