View Javadoc

1   /*
2    * $Id: SimpleRetryPolicyTemplate.java 22088 2011-06-03 10:07:47Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.retry.policies;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.mule.api.retry.RetryPolicy;
16  
17  /**
18   * This policy allows the user to configure how many times a retry should be attempted and how long to wait between
19   * retries.
20   */
21  public class SimpleRetryPolicyTemplate extends AbstractPolicyTemplate
22  {
23  
24      /**
25       * logger used by this class
26       */
27      protected transient final Log logger = LogFactory.getLog(SimpleRetryPolicyTemplate.class);
28  
29      public static final int DEFAULT_FREQUENCY = 2000;
30      public static final int DEFAULT_RETRY_COUNT = 2;
31      public static final int RETRY_COUNT_FOREVER = -1;
32  
33      protected volatile int count = DEFAULT_RETRY_COUNT;
34      protected volatile long frequency = DEFAULT_FREQUENCY;
35  
36      public SimpleRetryPolicyTemplate()
37      {
38          super();
39      }
40  
41      public SimpleRetryPolicyTemplate(long frequency, int retryCount)
42      {
43          this.frequency = frequency;
44          this.count = retryCount;
45      }
46  
47      public long getFrequency()
48      {
49          return frequency;
50      }
51  
52      public int getCount()
53      {
54          return count;
55      }
56  
57      public void setFrequency(long frequency)
58      {
59          this.frequency = frequency;
60      }
61  
62      public void setCount(int count)
63      {
64          this.count = count;
65      }
66  
67      public RetryPolicy createRetryInstance()
68      {
69          return new SimpleRetryPolicy(frequency, count);
70      }
71  
72      @Override
73      public String toString()
74      {
75          final StringBuffer sb = new StringBuffer();
76          sb.append("SimpleRetryPolicy");
77          sb.append("{frequency=").append(frequency);
78          sb.append(", retryCount=").append(count);
79          sb.append('}');
80  
81          return sb.toString();
82      }
83  }