package name.webdizz.fault.tolerance.inventory.client.command;

import name.webdizz.fault.tolerance.inventory.client.InventoryRequester;
import name.webdizz.fault.tolerance.inventory.domain.Inventory;
import name.webdizz.fault.tolerance.inventory.domain.Product;
import name.webdizz.fault.tolerance.inventory.domain.Store;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandProperties;

public class TimeOutInventoryRequestCommand extends HystrixCommand<Inventory> {

    private final InventoryRequester inventoryRequester;
    private final Store store;
    private final Product product;

    public TimeOutInventoryRequestCommand(final int timeoutInMillis, final InventoryRequester inventoryRequester, final Store store, final Product product) {
        super(Setter
                        .withGroupKey(HystrixCommandGroupKey.Factory.asKey(TimeOutInventoryRequestCommand.class.getSimpleName()))
                        .andCommandKey(HystrixCommandKey.Factory.asKey(TimeOutInventoryRequestCommand.class.getSimpleName()))
                        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                                .withCircuitBreakerForceClosed(true)
                                .withExecutionTimeoutInMilliseconds(timeoutInMillis))
        );
        this.inventoryRequester = inventoryRequester;
        this.store = store;
        this.product = product;
    }

    @Override
    protected Inventory run() throws Exception {
        return inventoryRequester.requestInventoryFor(store, product);
    }
}

@@ -1665,11 +1665,168 @@
 );%0A    %7D
+%0A%0A    @Override%0A    protected Inventory getFallback() %7B%0A        return new Inventory(new Store(%22fallback store%22), new Product(%22fallback product%22), 0L);%0A    %7D
 %0A%7D%0A

Add fallback method to time out command