Search in sources :

Example 1 with APICaller

use of com.arm.mbed.cloud.sdk.testutils.APICaller in project mbed-cloud-sdk-java by ARMmbed.

the class Engine method stopInstanceDaemons.

private void stopInstanceDaemons(String instanceId) throws ServerCacheException, MissingInstanceException {
    APIModule module = cache.fetchModuleFromInstance(instanceId);
    if (module != null) {
        if (module.hasDaemonControlMethods()) {
            ModuleInstance instance = retrieveInstance(instanceId);
            APICaller caller = createAnApiCaller();
            logger.logInfo("Stopping SDK module instance [" + instanceId + "] daemon threads");
            List<APIMethod> stoppingMethods = module.getStopDaemonMethods();
            if (stoppingMethods != null) {
                stoppingMethods.forEach(m -> {
                    try {
                        caller.callAPIOnModuleInstance(instance, m.getName(), null);
                    } catch (UnknownAPIException | APICallException e) {
                        e.printStackTrace();
                    }
                });
            }
            logger.logInfo("Shutting down SDK module instance [" + instanceId + "] daemon executor service");
            List<APIMethod> shuttingdownMethods = module.getShutdownDaemonMethods();
            if (shuttingdownMethods != null) {
                shuttingdownMethods.forEach(m -> {
                    try {
                        caller.callAPIOnModuleInstance(instance, m.getName(), null);
                    } catch (UnknownAPIException | APICallException e) {
                        e.printStackTrace();
                    }
                });
            }
        }
    }
}
Also used : UnknownAPIException(com.arm.mbed.cloud.sdk.testserver.internal.model.UnknownAPIException) APIModule(com.arm.mbed.cloud.sdk.testserver.internal.model.APIModule) APIMethod(com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethod) APICaller(com.arm.mbed.cloud.sdk.testutils.APICaller) APICallException(com.arm.mbed.cloud.sdk.testutils.APICallException) ModuleInstance(com.arm.mbed.cloud.sdk.testserver.internal.model.ModuleInstance)

Aggregations

APIMethod (com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethod)1 APIModule (com.arm.mbed.cloud.sdk.testserver.internal.model.APIModule)1 ModuleInstance (com.arm.mbed.cloud.sdk.testserver.internal.model.ModuleInstance)1 UnknownAPIException (com.arm.mbed.cloud.sdk.testserver.internal.model.UnknownAPIException)1 APICallException (com.arm.mbed.cloud.sdk.testutils.APICallException)1 APICaller (com.arm.mbed.cloud.sdk.testutils.APICaller)1