| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.builder; |
| 18 |
|
|
| 19 |
|
import org.apache.camel.Expression; |
| 20 |
|
import org.apache.camel.Processor; |
| 21 |
|
import org.apache.camel.processor.DeadLetterChannel; |
| 22 |
|
import org.apache.camel.processor.Logger; |
| 23 |
|
import org.apache.camel.processor.LoggingLevel; |
| 24 |
|
import org.apache.camel.processor.RecipientList; |
| 25 |
|
import org.apache.camel.processor.RedeliveryPolicy; |
| 26 |
|
import org.apache.commons.logging.Log; |
| 27 |
|
import org.apache.commons.logging.LogFactory; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
public class DeadLetterChannelBuilder extends ErrorHandlerBuilderSupport { |
| 37 |
327 |
private RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy(); |
| 38 |
|
private ProcessorFactory deadLetterFactory; |
| 39 |
|
private Processor defaultDeadLetterEndpoint; |
| 40 |
|
private Expression defaultDeadLetterEndpointExpression; |
| 41 |
327 |
private String defaultDeadLetterEndpointUri = "log:org.apache.camel.DeadLetterChannel:error"; |
| 42 |
327 |
private Logger logger = DeadLetterChannel.createDefaultLogger(); |
| 43 |
|
|
| 44 |
321 |
public DeadLetterChannelBuilder() { |
| 45 |
321 |
} |
| 46 |
|
|
| 47 |
|
public DeadLetterChannelBuilder(Processor processor) { |
| 48 |
6 |
this(new ConstantProcessorBuilder(processor)); |
| 49 |
6 |
} |
| 50 |
|
|
| 51 |
6 |
public DeadLetterChannelBuilder(ProcessorFactory deadLetterFactory) { |
| 52 |
6 |
this.deadLetterFactory = deadLetterFactory; |
| 53 |
6 |
} |
| 54 |
|
|
| 55 |
|
public ErrorHandlerBuilder copy() { |
| 56 |
0 |
DeadLetterChannelBuilder answer = new DeadLetterChannelBuilder(deadLetterFactory); |
| 57 |
0 |
answer.setRedeliveryPolicy(getRedeliveryPolicy().copy()); |
| 58 |
0 |
return answer; |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public Processor createErrorHandler(Processor processor) throws Exception { |
| 62 |
291 |
Processor deadLetter = getDeadLetterFactory().createProcessor(); |
| 63 |
291 |
DeadLetterChannel answer = new DeadLetterChannel(processor, deadLetter, getRedeliveryPolicy(), getLogger()); |
| 64 |
291 |
configure(answer); |
| 65 |
291 |
return answer; |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
public DeadLetterChannelBuilder backOffMultiplier(double backOffMultiplier) { |
| 71 |
0 |
getRedeliveryPolicy().backOffMultiplier(backOffMultiplier); |
| 72 |
0 |
return this; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
public DeadLetterChannelBuilder collisionAvoidancePercent(short collisionAvoidancePercent) { |
| 76 |
0 |
getRedeliveryPolicy().collisionAvoidancePercent(collisionAvoidancePercent); |
| 77 |
0 |
return this; |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
public DeadLetterChannelBuilder initialRedeliveryDelay(long initialRedeliveryDelay) { |
| 81 |
6 |
getRedeliveryPolicy().initialRedeliveryDelay(initialRedeliveryDelay); |
| 82 |
6 |
return this; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
public DeadLetterChannelBuilder maximumRedeliveries(int maximumRedeliveries) { |
| 86 |
6 |
getRedeliveryPolicy().maximumRedeliveries(maximumRedeliveries); |
| 87 |
6 |
return this; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
public DeadLetterChannelBuilder useCollisionAvoidance() { |
| 91 |
0 |
getRedeliveryPolicy().useCollisionAvoidance(); |
| 92 |
0 |
return this; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
public DeadLetterChannelBuilder useExponentialBackOff() { |
| 96 |
0 |
getRedeliveryPolicy().useExponentialBackOff(); |
| 97 |
0 |
return this; |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
public DeadLetterChannelBuilder logger(Logger logger) { |
| 104 |
0 |
setLogger(logger); |
| 105 |
0 |
return this; |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
public DeadLetterChannelBuilder loggingLevel(LoggingLevel level) { |
| 112 |
6 |
getLogger().setLevel(level); |
| 113 |
6 |
return this; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
public DeadLetterChannelBuilder log(Log log) { |
| 120 |
0 |
getLogger().setLog(log); |
| 121 |
0 |
return this; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
public DeadLetterChannelBuilder log(String log) { |
| 128 |
0 |
return log(LogFactory.getLog(log)); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
public DeadLetterChannelBuilder log(Class log) { |
| 135 |
0 |
return log(LogFactory.getLog(log)); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
public RedeliveryPolicy getRedeliveryPolicy() { |
| 141 |
303 |
return redeliveryPolicy; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy) { |
| 148 |
0 |
this.redeliveryPolicy = redeliveryPolicy; |
| 149 |
0 |
} |
| 150 |
|
|
| 151 |
|
public ProcessorFactory getDeadLetterFactory() { |
| 152 |
291 |
if (deadLetterFactory == null) { |
| 153 |
249 |
deadLetterFactory = new ProcessorFactory() { |
| 154 |
249 |
public Processor createProcessor() { |
| 155 |
285 |
return getDefaultDeadLetterEndpoint(); |
| 156 |
|
} |
| 157 |
|
}; |
| 158 |
|
} |
| 159 |
291 |
return deadLetterFactory; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
public void setDeadLetterFactory(ProcessorFactory deadLetterFactory) { |
| 166 |
0 |
this.deadLetterFactory = deadLetterFactory; |
| 167 |
0 |
} |
| 168 |
|
|
| 169 |
|
public Processor getDefaultDeadLetterEndpoint() { |
| 170 |
285 |
if (defaultDeadLetterEndpoint == null) { |
| 171 |
249 |
defaultDeadLetterEndpoint = new RecipientList(getDefaultDeadLetterEndpointExpression()); |
| 172 |
|
} |
| 173 |
285 |
return defaultDeadLetterEndpoint; |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
public void setDefaultDeadLetterEndpoint(Processor defaultDeadLetterEndpoint) { |
| 180 |
0 |
this.defaultDeadLetterEndpoint = defaultDeadLetterEndpoint; |
| 181 |
0 |
} |
| 182 |
|
|
| 183 |
|
public Expression getDefaultDeadLetterEndpointExpression() { |
| 184 |
249 |
if (defaultDeadLetterEndpointExpression == null) { |
| 185 |
249 |
defaultDeadLetterEndpointExpression = ExpressionBuilder |
| 186 |
|
.constantExpression(getDefaultDeadLetterEndpointUri()); |
| 187 |
|
} |
| 188 |
249 |
return defaultDeadLetterEndpointExpression; |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
public void setDefaultDeadLetterEndpointExpression(Expression defaultDeadLetterEndpointExpression) { |
| 197 |
0 |
this.defaultDeadLetterEndpointExpression = defaultDeadLetterEndpointExpression; |
| 198 |
0 |
} |
| 199 |
|
|
| 200 |
|
public String getDefaultDeadLetterEndpointUri() { |
| 201 |
249 |
return defaultDeadLetterEndpointUri; |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
public void setDefaultDeadLetterEndpointUri(String defaultDeadLetterEndpointUri) { |
| 213 |
0 |
this.defaultDeadLetterEndpointUri = defaultDeadLetterEndpointUri; |
| 214 |
0 |
} |
| 215 |
|
|
| 216 |
|
public Logger getLogger() { |
| 217 |
297 |
return logger; |
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
public void setLogger(Logger logger) { |
| 221 |
0 |
this.logger = logger; |
| 222 |
0 |
} |
| 223 |
|
} |