All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.saro.sap.jco.SapFunctionTemplate Maven / Gradle / Ivy

There is a newer version: 3.0.14.7
Show newest version
package me.saro.sap.jco;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoFunctionTemplate;

import me.saro.commons.Utils;
import me.saro.commons.function.ThrowableBiFunction;

/**
 * Sap Function Template
 * @author      PARK Yong Seo
 * @since       0.1
 */
public class SapFunctionTemplate {

    final JCoDestination destination;
    final JCoFunctionTemplate jCoFunctionTemplate;

    /**
     * use SapManagerBuilder
     * @param jCoFunctionTemplate
     */
    SapFunctionTemplate(JCoDestination destination, JCoFunctionTemplate jCoFunctionTemplate) {
        this.destination = destination;
        this.jCoFunctionTemplate = jCoFunctionTemplate;
    }

    /**
     * get function
     * @return
     */
    public SapFunction getFunction() {
        JCoFunction jCoFunction = jCoFunctionTemplate.getFunction();
        if (jCoFunction == null) {
            throw new RuntimeException("function `"+jCoFunctionTemplate.getName()+"` not found");
        }
        return new SapFunction(destination, jCoFunction);
    }

    /**
     * execute all functions with threads
     * @param nThreads
     * @param list
     * @param forEach
     * @return
     */
    public  List executeAllThreads(int nThreads, List list, ThrowableBiFunction forEach) {
        return executeAllThreads(Executors.newFixedThreadPool(nThreads), list, forEach);
    }

    /**
     * execute all functions with threads
     * @param executorService
     * @param list
     * @param forEach
     * @return
     */
    public  List executeAllThreads(ExecutorService executorService, List list, ThrowableBiFunction forEach) {
        return Utils.executeAllThreads(executorService, list, e -> forEach.apply(getFunction(), e));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy