Search in sources :

Example 1 with Daemon

use of com.arm.mbed.cloud.sdk.annotations.Daemon in project mbed-cloud-sdk-java by ARMmbed.

the class APIMappingGenerator method recordAPIMethod.

private APIMethod recordAPIMethod(Method method) {
    if (method == null || !method.isAnnotationPresent(API.class)) {
        return null;
    }
    APIMethod m = new APIMethod(method.getName());
    if (method.isAnnotationPresent(Daemon.class)) {
        Daemon daemonControl = method.getAnnotation(Daemon.class);
        if (daemonControl.start()) {
            m.setDaemonControl(DaemonControl.START);
        }
        if (daemonControl.stop()) {
            m.setDaemonControl(DaemonControl.STOP);
        }
        if (daemonControl.shutdown()) {
            m.setDaemonControl(DaemonControl.SHUTDOWN);
        }
    }
    if (method.getParameterCount() > 0) {
        Parameter[] parameters = method.getParameters();
        for (Parameter parameter : parameters) {
            String defaultValue = determineParameterDefaultValue(parameter);
            determineContentType(parameter);
            APIMethodArgument arg = new APIMethodArgument(parameter.getName(), parameter.getType(), determineContentType(parameter), defaultValue);
            m.addArgument(arg);
        }
    }
    APIMethodArgument returnArg = new APIMethodArgument(method.getReturnType(), null);
    m.setReturnArgument(returnArg);
    return m;
}
Also used : APIMethod(com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethod) Daemon(com.arm.mbed.cloud.sdk.annotations.Daemon) Parameter(java.lang.reflect.Parameter) APIMethodArgument(com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethodArgument)

Example 2 with Daemon

use of com.arm.mbed.cloud.sdk.annotations.Daemon in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method startNotifications.

/**
 * Starts notification pull.
 * <p>
 * If an external callback is not set up (using `update_webhook`) then calling this function is mandatory to get or
 * set resources. Unless {@link ConnectionOptions#setAutostartDaemon(boolean)} has been set to true or left as
 * default.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * connectApi.startNotifications();
 * }
 * </pre>
 *
 * @throws MbedCloudException
 *             if a problem occurred during the process.
 */
@API
@Daemon(task = "Notification pull", start = true)
public void startNotifications() throws MbedCloudException {
    Webhook webhook = null;
    try {
        if (isForceClear()) {
            deleteWebhook();
        }
    } catch (MbedCloudException exception) {
    // Nothing to do
    }
    try {
        webhook = getWebhook();
    } catch (MbedCloudException exception) {
    // Nothing to do
    }
    if (webhook != null) {
        logger.throwSdkException("A webhook is currently set up [" + webhook + "]. Notification pull cannot be used at the same time. Please remove the webhook if you want to use this mechanism instead.");
    }
    handlersStore.startNotificationPull();
}
Also used : MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) Webhook(com.arm.mbed.cloud.sdk.connect.model.Webhook) Daemon(com.arm.mbed.cloud.sdk.annotations.Daemon) API(com.arm.mbed.cloud.sdk.annotations.API)

Aggregations

Daemon (com.arm.mbed.cloud.sdk.annotations.Daemon)2 API (com.arm.mbed.cloud.sdk.annotations.API)1 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)1 Webhook (com.arm.mbed.cloud.sdk.connect.model.Webhook)1 APIMethod (com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethod)1 APIMethodArgument (com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethodArgument)1 Parameter (java.lang.reflect.Parameter)1