use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.
the class Connect method addResourceSubscription.
/**
* Subscribes to a resource.
* <p>
* Example:
*
* <pre>
* {@code
* try {
* String deviceId = "015f4ac587f500000000000100100249";
* String resourcePath = "/3200/0/5501";
* Resource buttonResource = new Resource(deviceId, resourcePath);
*
* connectApi.addResourceSubscription(buttonResource);
* } catch (MbedCloudException e) {
* e.printStackTrace();
* }
* }
* </pre>
*
* @param resource
* resource to subscribe to.
* @throws MbedCloudException
* if a problem occurred during request processing.
*/
@API
public void addResourceSubscription(@NonNull Resource resource) throws MbedCloudException {
checkNotNull(resource, TAG_RESOURCE);
checkModelValidity(resource, TAG_RESOURCE);
final Resource finalResource = resource;
CloudCaller.call(this, "addResourceSubscription()", null, new CloudCall<Void>() {
@Override
public Call<Void> call() {
return endpoint.getSubscriptions().v2SubscriptionsDeviceIdResourcePathPut(finalResource.getDeviceId(), ApiUtils.normalisePath(finalResource.getPath()));
}
});
}
use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.
the class Connect method getResourceSubscription.
/**
* Gets the status of a resource's subscription.
* <p>
* Example:
*
* <pre>
* {@code
* try {
* String deviceId = "015f4ac587f500000000000100100249";
* String resourcePath = "/3200/0/5501";
* Resource buttonResource = new Resource(deviceId, resourcePath);
*
* boolean subscribed = connectApi.getResourceSubscription(buttonResource);
* System.out.println("Is " + deviceId + " subscribed to: " + resourcePath + "? " + (subscribed ? "yes" : "no"));
* } catch (MbedCloudException e) {
* e.printStackTrace();
* }
* }
* </pre>
*
* @param resource
* resource
* @return true if resource is subscribed. false otherwise.
* @throws MbedCloudException
* if a parameter is incorrect
*/
@API
public boolean getResourceSubscription(@NonNull Resource resource) throws MbedCloudException {
checkNotNull(resource, TAG_RESOURCE);
checkModelValidity(resource, TAG_RESOURCE);
final Resource finalResource = resource;
try {
CloudCaller.call(this, "getResourceSubscription()", null, new CloudCall<Void>() {
@Override
public Call<Void> call() {
return endpoint.getSubscriptions().v2SubscriptionsDeviceIdResourcePathGet(finalResource.getDeviceId(), ApiUtils.normalisePath(finalResource.getPath()));
}
}, true);
return true;
} catch (MbedCloudException exception) {
return false;
}
}
use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.
the class Enrollment method addEnrollmentClaim.
/**
* Places an enrolment claim for one or several devices.
* <p>
* Example:
*
* <pre>
* {@code
* try {
* String claimId = "A-35:e7:72:8a:07:50:3b:3d:75:96:57:52:72:41:0d:78:cc:c6:e5:53:48:c6:65:58:5b:fa:af:4d:2d:73:95:c5";
* EnrollmentClaim claim = enrollmentApi.addEnrollmentClaim(claimId)
* System.out.println(claim);
*
* } catch (MbedCloudException e) {
* e.printStackTrace();
* }
* }
* </pre>
*
* @param claimId
* Claim Id. Pattern: '^[A-Z]{1}-[A-Za-z0-9:]{1, 256}' e.g.
* A-35:e7:72:8a:07:50:3b:3d:75:96:57:52:72:41:0d:78:cc:c6:e5:53:48:c6:65:58:5b:fa:af:4d:2d:73:95:c5
* @return enrollment claim.
* @throws MbedCloudException
* if a problem occurred during request processing.
*/
@API
@Nullable
public EnrollmentClaim addEnrollmentClaim(@NonNull String claimId) throws MbedCloudException {
checkNotNull(claimId, TAG_ENROLLMENT_ID);
final EnrollmentId finalEnrollmentId = new EnrollmentId().enrollmentIdentity(claimId);
return CloudCaller.call(this, "addEnrollmentClaim()", EnrollmentAdapter.getMapper(), new CloudCall<EnrollmentIdentity>() {
@Override
public Call<EnrollmentIdentity> call() {
return endpoint.getEnrollment().createDeviceEnrollment(finalEnrollmentId);
}
});
}
use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.
the class NotificationHandlersStore method createCachingSingleAction.
private Runnable createCachingSingleAction() {
return new Runnable() {
private final ExponentialBackoff backoffPolicy = new ExponentialBackoff(api.getLogger());
@Override
public void run() {
try {
final CallFeedback<NotificationMessage> feedback = CloudCaller.callWithFeedback(api, "NotificationPullGet()", getIdentityMapper(), new CloudCall<NotificationMessage>() {
@Override
public Call<NotificationMessage> call() {
return endpoint.getNotifications().v2NotificationPullGet();
}
}, false, true);
final NotificationMessage notificationMessage = feedback.getResult();
if (notificationMessage == null) {
api.getLogger().logInfo("Notification pull did not receive any notification during last call. Call information: " + feedback.getMetadata());
return;
}
storeResponses(notificationMessage.getAsyncResponses());
handleSubscriptions(notificationMessage.getNotifications());
handleDeviceStateChanges(notificationMessage);
} catch (MbedCloudException exception) {
backoffPolicy.backoff();
logPullError(exception);
}
}
};
}
Aggregations