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

com.metaring.framework.ReinitFunctionality Maven / Gradle / Ivy

package com.metaring.framework;

import java.util.concurrent.CompletableFuture;
import com.metaring.framework.functionality.AbstractFunctionality;
import com.metaring.framework.functionality.GeneratedFunctionality;
import com.metaring.framework.functionality.FunctionalityInfo;

abstract class ReinitFunctionality extends AbstractFunctionality implements GeneratedFunctionality {

    static final FunctionalityInfo INFO = FunctionalityInfo.create("com.metaring.framework.reinit", true, false, false, null, null);

    static final ReinitFunctionality INSTANCE = new ReinitFunctionalityImpl();

    protected ReinitFunctionality() {
        super(INFO, null);
    }

    @Override
    protected final CompletableFuture beforePreConditionCheck(Object input) throws Exception {
        CompletableFuture response = beforePreConditionCheck();
        return response == null ? end : response;
    }

    protected CompletableFuture beforePreConditionCheck() throws Exception {
        return end;
    }

    @Override
    protected final CompletableFuture preConditionCheck(Object input) throws Exception {
        CompletableFuture response = preConditionCheck();
        return response == null ? end : response;
    }

    protected abstract CompletableFuture preConditionCheck() throws Exception;

    @Override
    protected final CompletableFuture afterPreConditionCheck(Object input) throws Exception {
        CompletableFuture response = afterPreConditionCheck();
        return response == null ? end : response;
    }

    protected CompletableFuture afterPreConditionCheck() throws Exception {
        return end;
    }

    @Override
    protected final CompletableFuture beforeCall(Object input) throws Exception {
        CompletableFuture response = beforeCall();
        return response == null ? end : response;
    }

    protected CompletableFuture beforeCall() throws Exception {
        return end;
    }

    @Override
    protected final CompletableFuture call(Object input) throws Exception {
        CompletableFuture call = call();
        if(call == null) {
            return end(null);
        }
        final CompletableFuture response = new CompletableFuture<>();
        call.whenCompleteAsync((result, error) -> {
            if(error != null) {
                response.completeExceptionally(error);
                return;
            }
            response.complete(result);
        }, EXECUTOR);
        return response;
    }

    protected abstract CompletableFuture call() throws Exception;

    @Override
    protected final CompletableFuture afterCall(Object input, Object output) throws Exception {
        CompletableFuture response = afterCall();
        return response == null ? end : response;
    }

    protected CompletableFuture afterCall() throws Exception {
        return end;
    }

    @Override
    protected final CompletableFuture beforePostConditionCheck(Object input, Object output) throws Exception {
        CompletableFuture response = beforePostConditionCheck();
        return response == null ? end : response;
    }

    protected CompletableFuture beforePostConditionCheck() throws Exception {
        return end;
    }

    @Override
    protected final CompletableFuture postConditionCheck(Object input, Object output) throws Exception {
        CompletableFuture response = postConditionCheck();
        return response == null ? end : response;
    }

    protected abstract CompletableFuture postConditionCheck() throws Exception;

    @Override
    protected final CompletableFuture afterPostConditionCheck(Object input, Object output) throws Exception {
        CompletableFuture response = afterPostConditionCheck();
        return response == null ? end : response;
    }

    protected CompletableFuture afterPostConditionCheck() throws Exception {
        return end;
    }
}