Coverage Report - org.apache.camel.builder.DeadLetterChannelBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
DeadLetterChannelBuilder
54% 
100% 
1.103
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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  
  * A builder of a <a
 31  
  * href="http://activemq.apache.org/camel/dead-letter-channel.html">Dead Letter
 32  
  * Channel</a>
 33  
  * 
 34  
  * @version $Revision: 564295 $
 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  
     // Builder methods
 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  
      * Sets the logger used for caught exceptions
 102  
      */
 103  
     public DeadLetterChannelBuilder logger(Logger logger) {
 104  0
         setLogger(logger);
 105  0
         return this;
 106  
     }
 107  
 
 108  
     /**
 109  
      * Sets the logging level of exceptions caught
 110  
      */
 111  
     public DeadLetterChannelBuilder loggingLevel(LoggingLevel level) {
 112  6
         getLogger().setLevel(level);
 113  6
         return this;
 114  
     }
 115  
 
 116  
     /**
 117  
      * Sets the log used for caught exceptions
 118  
      */
 119  
     public DeadLetterChannelBuilder log(Log log) {
 120  0
         getLogger().setLog(log);
 121  0
         return this;
 122  
     }
 123  
 
 124  
     /**
 125  
      * Sets the log used for caught exceptions
 126  
      */
 127  
     public DeadLetterChannelBuilder log(String log) {
 128  0
         return log(LogFactory.getLog(log));
 129  
     }
 130  
 
 131  
     /**
 132  
      * Sets the log used for caught exceptions
 133  
      */
 134  
     public DeadLetterChannelBuilder log(Class log) {
 135  0
         return log(LogFactory.getLog(log));
 136  
     }
 137  
 
 138  
     // Properties
 139  
     // -------------------------------------------------------------------------
 140  
     public RedeliveryPolicy getRedeliveryPolicy() {
 141  303
         return redeliveryPolicy;
 142  
     }
 143  
 
 144  
     /**
 145  
      * Sets the redelivery policy
 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  
      * Sets the default dead letter queue factory
 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  
      * Sets the default dead letter endpoint used
 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  
      * Sets the expression used to decide the dead letter channel endpoint for
 193  
      * an exchange if no factory is provided via
 194  
      * {@link #setDeadLetterFactory(ProcessorFactory)}
 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  
      * Sets the default dead letter endpoint URI used if no factory is provided
 206  
      * via {@link #setDeadLetterFactory(ProcessorFactory)} and no expression is
 207  
      * provided via {@link #setDefaultDeadLetterEndpointExpression(Expression)}
 208  
      * 
 209  
      * @param defaultDeadLetterEndpointUri the default URI if no deadletter
 210  
      *                factory or expression is provided
 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  
 }