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