1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package net.sf.infrared.agent.transport.impl; |
23 |
|
|
24 |
|
import net.sf.infrared.agent.transport.Aggregator; |
25 |
|
import net.sf.infrared.agent.transport.Forwarder; |
26 |
|
import net.sf.infrared.base.model.OperationStatistics; |
27 |
|
import net.sf.infrared.base.util.LoggingFactory; |
28 |
|
|
29 |
|
import org.apache.log4j.Logger; |
30 |
|
|
31 |
|
import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer; |
32 |
|
import EDU.oswego.cs.dl.util.concurrent.Executor; |
33 |
|
import EDU.oswego.cs.dl.util.concurrent.PooledExecutor; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
0 |
public class PooledAggregator implements Aggregator { |
40 |
0 |
private static final Logger log = LoggingFactory.getLogger(PooledAggregator.class); |
41 |
|
|
42 |
|
private PooledExecutor executor; |
43 |
|
|
44 |
|
private Aggregator aggregator; |
45 |
|
|
46 |
0 |
public PooledAggregator(Aggregator aggregator, int bufferLength, class="keyword">int maxThreads) { |
47 |
0 |
this.aggregator = aggregator; |
48 |
|
|
49 |
0 |
executor = new PooledExecutor(class="keyword">new BoundedBuffer(bufferLength), maxThreads); |
50 |
0 |
executor.setKeepAliveTime(1000 * 60 * 5); |
51 |
0 |
executor.discardOldestWhenBlocked(); |
52 |
0 |
} |
53 |
|
|
54 |
|
public void aggregate(final OperationStatistics stats) { |
55 |
|
try { |
56 |
0 |
executor.execute(new Runnable() { |
57 |
|
public void run() { |
58 |
|
aggregator.aggregate(stats); |
59 |
|
} |
60 |
|
}); |
61 |
|
|
62 |
0 |
if (log.isDebugEnabled()) { |
63 |
0 |
log.debug("Scheduled " + stats + " for merging"); |
64 |
|
} |
65 |
0 |
} catch (InterruptedException e) { |
66 |
0 |
log.error("Error in aggregate, ignoring", e); |
67 |
0 |
} |
68 |
0 |
} |
69 |
|
|
70 |
|
public void flush() { |
71 |
0 |
aggregator.flush(); |
72 |
0 |
} |
73 |
|
|
74 |
|
public void setForwarder(Forwarder forwarder) { |
75 |
0 |
aggregator.setForwarder(forwarder); |
76 |
0 |
} |
77 |
|
|
78 |
|
public void shutdown() { |
79 |
0 |
executor.shutdownNow(); |
80 |
0 |
aggregator.shutdown(); |
81 |
0 |
} |
82 |
|
} |