// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/Composer.java
// public interface Composer {
// 
//     public Object compose(Map<String, Object> values) throws ComposerEvaluationException;
// 
//     public List<String> getDependencies();
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/exception/ComposerEvaluationException.java
// public class ComposerEvaluationException extends Exception {
// 
//     public ComposerEvaluationException() {
//         super();
//     }
// 
//     public ComposerEvaluationException(String message) {
//         super(message);
//     }
// 
//     public ComposerEvaluationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ComposerEvaluationException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/exception/BadCallableException.java
// public class BadCallableException extends Exception {
// 
//     public BadCallableException() {
//         super();
//     }
// 
//     public BadCallableException(String message) {
//         super(message);
//     }
// 
//     public BadCallableException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public BadCallableException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/helpers/ReflectionHelper.java
// public class ReflectionHelper {
// 
//     public static Constructor<? extends Callable> getFirstSingleArgConstructor(Class<? extends Callable> callableClass) throws NoSuchMethodException {
//         Constructor<?>[] declaredConstructors = callableClass.getDeclaredConstructors();
//         for (Constructor constructor : declaredConstructors) {
//             Class[] parameterTypes = constructor.getParameterTypes();
//             if (parameterTypes.length == 1) {
//                 return constructor;
//             }
//         }
// 
//         throw new NoSuchMethodException("Unable to find a single argument constructor.");
//     }
// }


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import com.flipkart.hydra.composer.Composer;
import com.flipkart.hydra.composer.exception.ComposerEvaluationException;
import com.flipkart.hydra.task.exception.BadCallableException;
import com.flipkart.hydra.task.helpers.ReflectionHelper;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * Copyright 2015 Flipkart Internet, pvt ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flipkart.hydra.task.entities;



public class WrapperCallable implements Callable<Object> {

    protected final ListeningExecutorService executorService;
    protected final Constructor<? extends Callable> constructor;
    protected final Object loopVar;
    protected final Composer composer;
    protected final Map<String, Object> values;

    public WrapperCallable(ExecutorService executor, Class<? extends Callable> callableClass, Composer loopComposer, Composer composer, Map<String, Object> values) throws NoSuchMethodException, ComposerEvaluationException {
        this(MoreExecutors.listeningDecorator(executor),
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/Composer.java
// public interface Composer {
// 
//     public Object compose(Map<String, Object> values) throws ComposerEvaluationException;
// 
//     public List<String> getDependencies();
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/exception/ComposerEvaluationException.java
// public class ComposerEvaluationException extends Exception {
// 
//     public ComposerEvaluationException() {
//         super();
//     }
// 
//     public ComposerEvaluationException(String message) {
//         super(message);
//     }
// 
//     public ComposerEvaluationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ComposerEvaluationException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/exception/BadCallableException.java
// public class BadCallableException extends Exception {
// 
//     public BadCallableException() {
//         super();
//     }
// 
//     public BadCallableException(String message) {
//         super(message);
//     }
// 
//     public BadCallableException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public BadCallableException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/helpers/ReflectionHelper.java
// public class ReflectionHelper {
// 
//     public static Constructor<? extends Callable> getFirstSingleArgConstructor(Class<? extends Callable> callableClass) throws NoSuchMethodException {
//         Constructor<?>[] declaredConstructors = callableClass.getDeclaredConstructors();
//         for (Constructor constructor : declaredConstructors) {
//             Class[] parameterTypes = constructor.getParameterTypes();
//             if (parameterTypes.length == 1) {
//                 return constructor;
//             }
//         }
// 
//         throw new NoSuchMethodException("Unable to find a single argument constructor.");
//     }
// }


// Path: hydra-task/src/main/java/com/flipkart/hydra/task/entities/WrapperCallable.java
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import com.flipkart.hydra.composer.Composer;
import com.flipkart.hydra.composer.exception.ComposerEvaluationException;
import com.flipkart.hydra.task.exception.BadCallableException;
import com.flipkart.hydra.task.helpers.ReflectionHelper;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Copyright 2015 Flipkart Internet, pvt ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flipkart.hydra.task.entities;



public class WrapperCallable implements Callable<Object> {

    protected final ListeningExecutorService executorService;
    protected final Constructor<? extends Callable> constructor;
    protected final Object loopVar;
    protected final Composer composer;
    protected final Map<String, Object> values;

    public WrapperCallable(ExecutorService executor, Class<? extends Callable> callableClass, Composer loopComposer, Composer composer, Map<String, Object> values) throws NoSuchMethodException, ComposerEvaluationException {
        this(MoreExecutors.listeningDecorator(executor),
                ReflectionHelper.getFirstSingleArgConstructor(callableClass),