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