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

com.ziqni.admin.sdk.streaming.handlers.CallbackConsumer Maven / Gradle / Ivy

There is a newer version: 1.0.21
Show newest version
package com.ziqni.admin.sdk.streaming.handlers;

import com.fasterxml.jackson.databind.JavaType;
import com.ziqni.admin.sdk.ApiException;
import com.ziqni.admin.sdk.streaming.ApiCallbackResponse;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.springframework.messaging.simp.stomp.StompHeaders;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

public class CallbackConsumer {

    private boolean completed = false;

    public final JavaType javaType;

    private final String callback;

    private final Class tClass;

    private final BiConsumer onCallback;
    private final BiConsumer onApiException;

    public CallbackConsumer(Class tClass, String callback, BiConsumer onCallback, BiConsumer onApiException) {
        this.tClass = tClass;
        this.javaType = CallbackEventHandler.objectMapper.constructType(tClass);
        this.callback = callback;
        this.onCallback = onCallback;
        this.onApiException = onApiException;
    }

    public JavaType getJavaType() {
        return javaType;
    }

    public String getCallback() {
        return callback;
    }

    public Class gettClass() {
        return tClass;
    }

    public void consumeCallback(StompHeaders headers, Object response) {
        onCallback.accept(headers, (T) response);
    }

    public void consumeApiExceptionCallBack(StompHeaders headers, ApiException response) {
        onApiException.accept(headers, response);
    }

    public boolean isCompleted() {
        return completed;
    }

    public boolean isCompleted(boolean in) {
        completed = in;
        return completed;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy