001
002package io.vrap.rmf.base.client;
003
004import java.io.Closeable;
005import java.util.concurrent.Executor;
006import java.util.concurrent.ExecutorService;
007import java.util.concurrent.ForkJoinPool;
008
009import io.vrap.rmf.base.client.error.BaseException;
010
011public abstract class HttpClientBase implements VrapHttpClient, Closeable {
012    private final ExecutorService executorService;
013
014    protected HttpClientBase() {
015        this.executorService = new ForkJoinPool();
016    }
017
018    protected HttpClientBase(ExecutorService executorService) {
019        this.executorService = executorService;
020    }
021
022    @Override
023    public final void close() {
024        try {
025            executorService.shutdown();
026            closeDelegate();
027        }
028        catch (final Throwable e) {
029            throw new BaseException(e);
030        }
031    }
032
033    protected abstract void closeDelegate() throws Throwable;
034
035    protected final Executor executor() {
036        return executorService;
037    }
038}