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;
}
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();
}
Aggregations