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

com.metaring.framework.rpc.auth.CallReservedFunctionality Maven / Gradle / Ivy

There is a newer version: 1.5.9
Show newest version
package com.metaring.framework.rpc.auth;

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

abstract class CallReservedFunctionality extends AbstractFunctionality implements GeneratedFunctionality {

    static final FunctionalityInfo INFO = FunctionalityInfo.create("com.metaring.framework.rpc.auth.callReserved", true, false, false, "com.metaring.framework.rpc.RpcRequest", "com.metaring.framework.rpc.RpcResponse");

    static final CallReservedFunctionality INSTANCE = new CallReservedFunctionalityImpl();

    protected CallReservedFunctionality() {
        super(INFO, RpcResponse.class);
    }

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

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

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

    protected abstract CompletableFuture preConditionCheck(RpcRequest input) throws Exception;

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

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

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

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

    @Override
    protected final CompletableFuture call(Object input) throws Exception {
        CompletableFuture call = call((RpcRequest) input);
        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(RpcRequest input) throws Exception;

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

    protected CompletableFuture afterCall(RpcRequest input, RpcResponse output) throws Exception {
        return end;
    }

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

    protected CompletableFuture beforePostConditionCheck(RpcRequest input, RpcResponse output) throws Exception {
        return end;
    }

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

    protected abstract CompletableFuture postConditionCheck(RpcRequest input, RpcResponse output) throws Exception;

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

    protected CompletableFuture afterPostConditionCheck(RpcRequest input, RpcResponse output) throws Exception {
        return end;
    }

    @Override
    protected final Object getInputFromJsonWork(String inputJson) {
        return RpcRequest.fromJson(inputJson);
    }
}