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

com.aliyun.datahub.model.InitOffsetContextResult Maven / Gradle / Ivy

There is a newer version: 2.25.6
Show newest version
package com.aliyun.datahub.model;

import com.aliyun.datahub.client.model.OpenSubscriptionSessionResult;
import com.aliyun.datahub.client.model.SubscriptionOffset;
import com.aliyun.datahub.utils.ModelConvertToNew;
import com.aliyun.datahub.utils.ModelConvertToOld;

import java.util.HashMap;
import java.util.Map;

public class InitOffsetContextResult extends Result {
    private OpenSubscriptionSessionResult proxyResult;
    private String projectName;
    private String topicName;
    private String subId;

    public InitOffsetContextResult(String project, String topic, String subId, OpenSubscriptionSessionResult proxyResult) {
        this.projectName = project;
        this.topicName = topic;
        this.subId = subId;
        this.proxyResult = proxyResult;
        setRequestId(proxyResult.getRequestId());
    }

    public InitOffsetContextResult() {
        proxyResult = new OpenSubscriptionSessionResult();
    }

    public Map getOffsets() {
        Map offsetContextMap = new HashMap<>();
        if (proxyResult.getOffsets() != null) {
            for (Map.Entry entry : proxyResult.getOffsets().entrySet()) {
                OffsetContext offsetContext = ModelConvertToOld.convertOffsetContext(projectName, topicName, subId, entry.getKey(), entry.getValue());
                offsetContextMap.put(entry.getKey(), offsetContext);
            }
        }

        return offsetContextMap;
    }

    public void setOffsets(Map offsets) {

        if (offsets != null) {
            Map subscriptionOffsetMap = new HashMap<>();

            for (Map.Entry entry : offsets.entrySet()) {
                SubscriptionOffset subOffset = ModelConvertToNew.convertOffsetContext(entry.getValue());
                subscriptionOffsetMap.put(entry.getKey(), subOffset);
            }

            proxyResult.setOffsets(subscriptionOffsetMap);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy