// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/AbstractSaveAccount.java
// public class AbstractSaveAccount {
// 
//     public void saveToDatabase(Account account) {
//         // NOP
//     }
// }
// 
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/Account.java
// @XmlRootElement
// public class Account {
//     private String iban;
//     private String bic;
// 
//     public String getIban() {
//         return iban;
//     }
// 
//     public void setIban(String iban) {
//         this.iban = iban;
//     }
// 
//     public String getBic() {
//         return bic;
//     }
// 
//     public void setBic(String bic) {
//         this.bic = bic;
//     }
// }
// 
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/IBANValidator.java
// public class IBANValidator {
// 
//     private static Logger LOG = LoggerFactory.getLogger(IBANValidator.class);
// 
//     // tag::dynprop[]
//     private static DynamicLongProperty timeToWait = DynamicPropertyFactory
//             .getInstance().getLongProperty("hystrixdemo.sleep", 100);
// 
//     // end::dynprop[]
// 
//     public static synchronized boolean isValid(Account account)
//             throws InterruptedException {
//         if (Thread.currentThread().isInterrupted()) {
//             throw new InterruptedException();
//         }
//         long t = timeToWait.get();
//         LOG.info("waiting {} ms", t);
//         if (t > 0) {
//             Thread.sleep(t);
//         }
//         return true;
//     }
// }
// 
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/ValidationException.java
// public class ValidationException extends Exception {
// 
//     public ValidationException(String string) {
//         super(string);
//     }
// 
// }


import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import de.ahus1.hystrix.base.AbstractSaveAccount;
import de.ahus1.hystrix.base.Account;
import de.ahus1.hystrix.base.IBANValidator;
import de.ahus1.hystrix.base.ValidationException;
package de.ahus1.hystrix.rest;





@Path("/hystrix")
@Api("/hystrix")
public class HystrixSaveAccount extends AbstractSaveAccount {

    private static Logger LOG = LoggerFactory
            .getLogger(HystrixSaveAccount.class);

    @GET
    @Produces("text/plain")
    @ApiOperation("simple hello")
    public Response hello() {
        return Response.status(Status.OK).entity("Hello world").build();
    }

    // tag::hystrix[]
    private static class IBANValidatorCommand extends HystrixCommand<Boolean> {
        private Account account;

        protected IBANValidatorCommand(Account account) {
            super(Setter.withGroupKey(HystrixCommandGroupKey.Factory
                    .asKey("iban")));
            this.account = account; // <2>
        }

        @Override
        protected Boolean run() throws Exception {
            return IBANValidator.isValid(account); // <3>
        }

    }

    @POST
    @ApiOperation("save account data")
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/AbstractSaveAccount.java
// public class AbstractSaveAccount {
// 
//     public void saveToDatabase(Account account) {
//         // NOP
//     }
// }
// 
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/Account.java
// @XmlRootElement
// public class Account {
//     private String iban;
//     private String bic;
// 
//     public String getIban() {
//         return iban;
//     }
// 
//     public void setIban(String iban) {
//         this.iban = iban;
//     }
// 
//     public String getBic() {
//         return bic;
//     }
// 
//     public void setBic(String bic) {
//         this.bic = bic;
//     }
// }
// 
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/IBANValidator.java
// public class IBANValidator {
// 
//     private static Logger LOG = LoggerFactory.getLogger(IBANValidator.class);
// 
//     // tag::dynprop[]
//     private static DynamicLongProperty timeToWait = DynamicPropertyFactory
//             .getInstance().getLongProperty("hystrixdemo.sleep", 100);
// 
//     // end::dynprop[]
// 
//     public static synchronized boolean isValid(Account account)
//             throws InterruptedException {
//         if (Thread.currentThread().isInterrupted()) {
//             throw new InterruptedException();
//         }
//         long t = timeToWait.get();
//         LOG.info("waiting {} ms", t);
//         if (t > 0) {
//             Thread.sleep(t);
//         }
//         return true;
//     }
// }
// 
// Path: hystrix-application/src/main/java/de/ahus1/hystrix/base/ValidationException.java
// public class ValidationException extends Exception {
// 
//     public ValidationException(String string) {
//         super(string);
//     }
// 
// }


// Path: hystrix-application/src/main/java/de/ahus1/hystrix/rest/HystrixSaveAccount.java
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import de.ahus1.hystrix.base.AbstractSaveAccount;
import de.ahus1.hystrix.base.Account;
import de.ahus1.hystrix.base.IBANValidator;
import de.ahus1.hystrix.base.ValidationException;

package de.ahus1.hystrix.rest;





@Path("/hystrix")
@Api("/hystrix")
public class HystrixSaveAccount extends AbstractSaveAccount {

    private static Logger LOG = LoggerFactory
            .getLogger(HystrixSaveAccount.class);

    @GET
    @Produces("text/plain")
    @ApiOperation("simple hello")
    public Response hello() {
        return Response.status(Status.OK).entity("Hello world").build();
    }

    // tag::hystrix[]
    private static class IBANValidatorCommand extends HystrixCommand<Boolean> {
        private Account account;

        protected IBANValidatorCommand(Account account) {
            super(Setter.withGroupKey(HystrixCommandGroupKey.Factory
                    .asKey("iban")));
            this.account = account; // <2>
        }

        @Override
        protected Boolean run() throws Exception {
            return IBANValidator.isValid(account); // <3>
        }

    }

    @POST
    @ApiOperation("save account data")
    public Response save(Account account) throws ValidationException,