1 | |
package org.apache.maven.archiva.repository.scanner; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
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 | |
|
32 | |
|
33 | |
|
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 | |
} |