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

com.arm.mbed.cloud.sdk.subscribe.NotificationCallback Maven / Gradle / Ivy

Go to download

The Pelion Cloud SDK (formerly known as Mbed Cloud SDK) provides a simplified interface to the Pelion Cloud APIs by exposing functionality using conventions and paradigms familiar to Java developers.

There is a newer version: 2.5.0
Show newest version
package com.arm.mbed.cloud.sdk.subscribe;

import com.arm.mbed.cloud.sdk.annotations.Preamble;
import com.arm.mbed.cloud.sdk.common.Callback;

@Preamble(description = "Notification callback")
public class NotificationCallback {
    private final Callback onSuccess;
    private final Callback onFailure;

    /**
     * Constructor.
     *
     * @param onSuccess
     *            callback when success.
     * @param onFailure
     *            callback when failure.
     */
    public NotificationCallback(Callback onSuccess, Callback onFailure) {
        super();
        this.onSuccess = onSuccess;
        this.onFailure = onFailure;
    }

    /**
     * Calls back when a notification message is received.
     *
     * @param message
     *            message triggering the callback.
     */
    public void callBack(NotificationMessage message) {
        if (message == null) {
            return;
        }
        callBack(message.getValue(), message.getException());
    }

    /**
     * Calls back when a notification message is received.
     *
     * @param value
     *            message payload.
     * @param throwable
     *            exception.
     */
    public void callBack(T value, Throwable throwable) {
        if (throwable == null) {
            if (onSuccess != null) {
                onSuccess.execute(value);
            }
        } else {
            if (onFailure != null) {
                onFailure.execute(throwable);
            }
        }
    }

    /**
     * Calls back when a notification message is received.
     *
     * @param value
     *            message payload.
     */
    public void callBack(T value) {
        callBack(value, null);
    }

    /**
     * Calls back when an exception is received.
     *
     * @param throwable
     *            exception received.
     */
    public void callBack(Throwable throwable) {
        callBack(null, throwable);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy