Search in sources :

Example 6 with Webhook

use of com.arm.mbed.cloud.sdk.connect.model.Webhook in project mbed-cloud-sdk-java by ARMmbed.

the class ConnectExamples method switchNotificationChannelWithForceClear.

/**
 * Switches between notification channels using forceClear.
 * <p>
 * forceClear parameter forces a notification channel to stop before a new one is started.
 */
@Example
public void switchNotificationChannelWithForceClear() {
    ConnectionOptions config = Configuration.get();
    Connect api = new Connect(config);
    try {
        // Setting forceClear to true
        api.setForceClear(true);
        // Using Notification pull channel.
        api.startNotifications();
        Thread.sleep(5000);
        // Starting a webhook channel.
        // Creating a webhook.
        Webhook webhook = new Webhook(new URL("http://mbedcloudjavawebhooktest.requestcatcher.com/test"));
        log("Webhook", webhook);
        // Setting up the webhook.
        api.updateWebhook(webhook);
        Thread.sleep(2000);
        // Using Notification pull channel again.
        api.startNotifications();
        Thread.sleep(5000);
        // Shutting down connect service.
        api.shutdownConnectService();
        Thread.sleep(100);
    } catch (Exception e) {
        e.printStackTrace();
        try {
            api.shutdownConnectService();
            Thread.sleep(100);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        deleteWebhook(api);
    }
}
Also used : Connect(com.arm.mbed.cloud.sdk.Connect) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) Webhook(com.arm.mbed.cloud.sdk.connect.model.Webhook) URL(java.net.URL) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Aggregations

Webhook (com.arm.mbed.cloud.sdk.connect.model.Webhook)6 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)4 Connect (com.arm.mbed.cloud.sdk.Connect)3 ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)3 URL (java.net.URL)3 AbstractExample (utils.AbstractExample)3 Example (utils.Example)3 API (com.arm.mbed.cloud.sdk.annotations.API)2 Daemon (com.arm.mbed.cloud.sdk.annotations.Daemon)1 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)1 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)1 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)1 Call (retrofit2.Call)1