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.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
58 if (basefile.exists())
59 {
60 log.debug( "Sending to consumer: {}", id );
61
62 long startTime = System.currentTimeMillis( );
63 consumer.processFile( basefile.getRelativePath( ), executeOnEntireRepo );
64 long endTime = System.currentTimeMillis( );
65
66 if ( consumerTimings != null )
67 {
68 Long value = consumerTimings.get( id );
69 consumerTimings.put( id, ( value != null ? value : 0 ) + endTime - startTime );
70 }
71
72 if ( consumerCounts != null )
73 {
74 Long value = consumerCounts.get( id );
75 consumerCounts.put( id, ( value != null ? value : 0 ) + 1 );
76 }
77 }
78 }
79 catch ( Exception e )
80 {
81
82
83
84 log.error( "Consumer [" + id + "] had an error when processing file ["
85 + basefile.getAbsolutePath() + "]: " + e.getMessage(), e );
86 }
87 }
88 }
89
90 public BaseFile getBasefile()
91 {
92 return basefile;
93 }
94
95 public void setBasefile( BaseFile basefile )
96 {
97 this.basefile = basefile;
98 }
99
100 public boolean isExecuteOnEntireRepo()
101 {
102 return executeOnEntireRepo;
103 }
104
105 public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
106 {
107 this.executeOnEntireRepo = executeOnEntireRepo;
108 }
109
110 public void setConsumerTimings( Map<String, Long> consumerTimings )
111 {
112 this.consumerTimings = consumerTimings;
113 }
114
115 public void setConsumerCounts( Map<String, Long> consumerCounts )
116 {
117 this.consumerCounts = consumerCounts;
118 }
119
120 public Logger getLogger()
121 {
122 return log;
123 }
124
125 public void setLogger( Logger logger )
126 {
127 this.log = logger;
128 }
129 }