Coverage Report - co.stateful.retry.ReSttc
 
Classes in this File Line Coverage Branch Coverage Complexity
ReSttc
0%
0/8
0%
0/12
1
ReSttc$AjcClosure1
0%
0/1
N/A
1
ReSttc$AjcClosure3
0%
0/1
N/A
1
ReSttc$AjcClosure5
0%
0/1
N/A
1
ReSttc$AjcClosure7
0%
0/1
N/A
1
 
 1  0
 /**
 2  
  * Copyright (c) 2014-2016, stateful.co
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the stateful.co nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package co.stateful.retry;
 31  
 
 32  
 import co.stateful.Counters;
 33  
 import co.stateful.Locks;
 34  
 import co.stateful.Sttc;
 35  
 import com.jcabi.aspects.Immutable;
 36  
 import com.jcabi.aspects.Loggable;
 37  
 import com.jcabi.aspects.RetryOnFailure;
 38  
 import com.jcabi.aspects.Tv;
 39  
 import java.io.IOException;
 40  
 import java.util.concurrent.TimeUnit;
 41  
 import lombok.EqualsAndHashCode;
 42  
 import lombok.ToString;
 43  
 
 44  
 /**
 45  
  * Retriable Sttc.
 46  
  *
 47  
  * <p>Just wrap your original {@link Sttc} object with this
 48  
  * decorator and all requests to stateful.co server will be
 49  
  * retried a few times before giving up and throwing a runtime
 50  
  * exception. It is highly recommended to use this decorator
 51  
  * in production environment. The Internet is not a stable environment,
 52  
  * and connection failures is a regular event.
 53  
  *
 54  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 55  
  * @version $Id$
 56  
  * @since 0.5
 57  
  */
 58  
 @Immutable
 59  
 @Loggable(Loggable.DEBUG)
 60  0
 @ToString(includeFieldNames = false)
 61  0
 @EqualsAndHashCode(of = "origin")
 62  
 public final class ReSttc implements Sttc {
 63  
 
 64  
     /**
 65  
      * Original object.
 66  
      */
 67  
     private final transient Sttc origin;
 68  
 
 69  
     /**
 70  
      * Ctor.
 71  
      * @param orgn Original object
 72  
      */
 73  0
     public ReSttc(final Sttc orgn) {
 74  0
         this.origin = orgn;
 75  0
     }
 76  
 
 77  
     @Override
 78  
     @RetryOnFailure
 79  
         (
 80  
             verbose = false, attempts = Tv.TWENTY,
 81  
             delay = Tv.TWENTY, unit = TimeUnit.SECONDS
 82  
         )
 83  
     public Counters counters() throws IOException {
 84  0
         return new ReCounters(this.origin.counters());
 85  
     }
 86  
 
 87  
     @Override
 88  
     @RetryOnFailure
 89  
         (
 90  
             verbose = false, attempts = Tv.TWENTY,
 91  
             delay = Tv.TWENTY, unit = TimeUnit.SECONDS
 92  
         )
 93  
     public Locks locks() throws IOException {
 94  0
         return new ReLocks(this.origin.locks());
 95  
     }
 96  
 }