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("InventoryRequest"))
                        .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);
    }
}

@@ -970,17 +970,23 @@
 y.asKey(
-%22
+TimeOut
 Inventor
@@ -997,9 +997,37 @@
 uest
-%22
+Command.class.getSimpleName()
 ))%0A 

Set Hystrix group key to command class name