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