1 | |
package org.apache.maven.archiva.repository.scanner.functors; |
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.Closure; |
23 | |
import org.apache.maven.archiva.common.utils.BaseFile; |
24 | |
import org.apache.maven.archiva.consumers.RepositoryContentConsumer; |
25 | |
import org.slf4j.Logger; |
26 | |
import org.slf4j.LoggerFactory; |
27 | |
|
28 | |
import java.util.HashMap; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class ConsumerProcessFileClosure |
37 | |
implements Closure |
38 | |
{ |
39 | 0 | private Logger log = LoggerFactory.getLogger( ConsumerProcessFileClosure.class ); |
40 | |
|
41 | |
private BaseFile basefile; |
42 | |
|
43 | |
private boolean executeOnEntireRepo; |
44 | |
|
45 | |
private Map<String,Long> consumerTimings; |
46 | |
|
47 | |
private Map<String,Long> consumerCounts; |
48 | |
|
49 | |
public void execute( Object input ) |
50 | |
{ |
51 | 0 | if ( input instanceof RepositoryContentConsumer ) |
52 | |
{ |
53 | 0 | RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; |
54 | |
|
55 | 0 | String id = consumer.getId(); |
56 | |
try |
57 | |
{ |
58 | 0 | log.debug( "Sending to consumer: " + id ); |
59 | |
|
60 | 0 | long startTime = System.currentTimeMillis(); |
61 | 0 | consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo ); |
62 | 0 | long endTime = System.currentTimeMillis(); |
63 | |
|
64 | 0 | if ( consumerTimings != null ) |
65 | |
{ |
66 | 0 | Long value = consumerTimings.get( id ); |
67 | 0 | consumerTimings.put( id, ( value != null ? value : 0 ) + endTime - startTime ); |
68 | |
} |
69 | |
|
70 | 0 | if ( consumerCounts != null ) |
71 | |
{ |
72 | 0 | Long value = consumerCounts.get( id ); |
73 | 0 | consumerCounts.put( id, ( value != null ? value : 0 ) + 1 ); |
74 | |
} |
75 | |
} |
76 | 0 | catch ( Exception e ) |
77 | |
{ |
78 | |
|
79 | |
|
80 | |
|
81 | 0 | log.error( "Consumer [" + id + "] had an error when processing file [" |
82 | |
+ basefile.getAbsolutePath() + "]: " + e.getMessage(), e ); |
83 | 0 | } |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
public BaseFile getBasefile() |
88 | |
{ |
89 | 0 | return basefile; |
90 | |
} |
91 | |
|
92 | |
public void setBasefile( BaseFile basefile ) |
93 | |
{ |
94 | 0 | this.basefile = basefile; |
95 | 0 | } |
96 | |
|
97 | |
public boolean isExecuteOnEntireRepo() |
98 | |
{ |
99 | 0 | return executeOnEntireRepo; |
100 | |
} |
101 | |
|
102 | |
public void setExecuteOnEntireRepo( boolean executeOnEntireRepo ) |
103 | |
{ |
104 | 0 | this.executeOnEntireRepo = executeOnEntireRepo; |
105 | 0 | } |
106 | |
|
107 | |
public void setConsumerTimings( Map<String, Long> consumerTimings ) |
108 | |
{ |
109 | 0 | this.consumerTimings = consumerTimings; |
110 | 0 | } |
111 | |
|
112 | |
public void setConsumerCounts( Map<String, Long> consumerCounts ) |
113 | |
{ |
114 | 0 | this.consumerCounts = consumerCounts; |
115 | 0 | } |
116 | |
|
117 | |
public Logger getLogger() |
118 | |
{ |
119 | 0 | return log; |
120 | |
} |
121 | |
|
122 | |
public void setLogger( Logger logger ) |
123 | |
{ |
124 | 0 | this.log = logger; |
125 | 0 | } |
126 | |
} |