1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.model; |
18 |
|
|
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.List; |
21 |
|
|
22 |
|
import javax.xml.bind.annotation.XmlAccessType; |
23 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
24 |
|
import javax.xml.bind.annotation.XmlAttribute; |
25 |
|
import javax.xml.bind.annotation.XmlElement; |
26 |
|
import javax.xml.bind.annotation.XmlElementRef; |
27 |
|
import javax.xml.bind.annotation.XmlRootElement; |
28 |
|
|
29 |
|
import org.apache.camel.Processor; |
30 |
|
import org.apache.camel.impl.RouteContext; |
31 |
|
import org.apache.camel.processor.Throttler; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@XmlRootElement(name = "throttler") |
37 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
38 |
|
public class ThrottlerType extends ProcessorType { |
39 |
|
@XmlAttribute |
40 |
|
private Long maximumRequestsPerPeriod; |
41 |
|
@XmlAttribute |
42 |
3 |
private long timePeriodMillis = 1000; |
43 |
|
@XmlElementRef |
44 |
3 |
private List<InterceptorType> interceptors = new ArrayList<InterceptorType>(); |
45 |
|
@XmlElementRef |
46 |
3 |
private List<ProcessorType> outputs = new ArrayList<ProcessorType>(); |
47 |
|
|
48 |
0 |
public ThrottlerType() { |
49 |
0 |
} |
50 |
|
|
51 |
3 |
public ThrottlerType(long maximumRequestsPerPeriod) { |
52 |
3 |
this.maximumRequestsPerPeriod = maximumRequestsPerPeriod; |
53 |
3 |
} |
54 |
|
|
55 |
|
@Override |
56 |
|
public String toString() { |
57 |
0 |
return "Throttler[" + getMaximumRequestsPerPeriod() + " request per " + getTimePeriodMillis() |
58 |
|
+ " millis -> " + getOutputs() + "]"; |
59 |
|
} |
60 |
|
|
61 |
|
@Override |
62 |
|
public Processor createProcessor(RouteContext routeContext) throws Exception { |
63 |
3 |
Processor childProcessor = routeContext.createProcessor(this); |
64 |
3 |
return new Throttler(childProcessor, maximumRequestsPerPeriod, timePeriodMillis); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public ThrottlerType timePeriodMillis(long timePeriodMillis) { |
74 |
3 |
this.timePeriodMillis = timePeriodMillis; |
75 |
3 |
return this; |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
public Long getMaximumRequestsPerPeriod() { |
82 |
0 |
return maximumRequestsPerPeriod; |
83 |
|
} |
84 |
|
|
85 |
|
public void setMaximumRequestsPerPeriod(Long maximumRequestsPerPeriod) { |
86 |
0 |
this.maximumRequestsPerPeriod = maximumRequestsPerPeriod; |
87 |
0 |
} |
88 |
|
|
89 |
|
public long getTimePeriodMillis() { |
90 |
0 |
return timePeriodMillis; |
91 |
|
} |
92 |
|
|
93 |
|
public void setTimePeriodMillis(long timePeriodMillis) { |
94 |
0 |
this.timePeriodMillis = timePeriodMillis; |
95 |
0 |
} |
96 |
|
|
97 |
|
public List<InterceptorType> getInterceptors() { |
98 |
6 |
return interceptors; |
99 |
|
} |
100 |
|
|
101 |
|
public void setInterceptors(List<InterceptorType> interceptors) { |
102 |
0 |
this.interceptors = interceptors; |
103 |
0 |
} |
104 |
|
|
105 |
|
public List<ProcessorType> getOutputs() { |
106 |
6 |
return outputs; |
107 |
|
} |
108 |
|
|
109 |
|
public void setOutputs(List<ProcessorType> outputs) { |
110 |
0 |
this.outputs = outputs; |
111 |
0 |
} |
112 |
|
} |