package com.elab.mq.msg.adptor;

import com.aliyun.openservices.ons.api.OnExceptionContext;
import com.aliyun.openservices.ons.api.SendCallback;
import com.aliyun.openservices.ons.api.SendResult;
import com.elab.mq.model.OnExceptionContextModel;
import com.elab.mq.model.SendResultModel;

/**
 * 异步消息回调适配器
 *
 * @author Liukx
 * @create 2018-04-10 19:33
 * @email liukx@elab-plus.com
 **/
public abstract class SendCallbackAdaptor implements SendCallback {

    @Override
    public final void onSuccess(SendResult sendResult) {
        SendResultModel sendResultModel = new SendResultModel(sendResult);
        success(sendResultModel);
    }

    /**
     * 异步消息回调成功处理方法
     *
     * @param sendResultModel
     */
    public abstract void success(SendResultModel sendResultModel);

    /**
     * 异步消息异常处理方法
     *
     * @param onExceptionContextModel
     */
    public abstract void exception(OnExceptionContextModel onExceptionContextModel);

    @Override
    public final void onException(OnExceptionContext onExceptionContext) {
        OnExceptionContextModel model = new OnExceptionContextModel(onExceptionContext);
        exception(model);
    }
}
