use of com.arm.mbed.cloud.sdk.common.TimePeriod in project mbed-cloud-sdk-java by ARMmbed.
the class AbstractMetricsListOptions method setDefault.
/*
* (non-Javadoc)
*
* @see
* com.arm.mbed.cloud.sdk.common.listing.ListOptions#setOptions(com.arm.mbed.cloud.sdk.common.listing.ListOptions)
*/
/*
* (non-Javadoc)
*
* @see com.arm.mbed.cloud.sdk.common.listing.ListOptions#setDefault()
*/
@Override
protected void setDefault() {
super.setDefault();
setInterval(new TimePeriod());
}
use of com.arm.mbed.cloud.sdk.common.TimePeriod in project mbed-cloud-sdk-java by ARMmbed.
the class MetricsPeriodListOptions method setDefault.
/*
* (non-Javadoc)
*
* @see
* com.arm.mbed.cloud.sdk.common.listing.ListOptions#setOptions(com.arm.mbed.cloud.sdk.common.listing.ListOptions)
*/
/*
* (non-Javadoc)
*
* @see com.arm.mbed.cloud.sdk.common.listing.ListOptions#setDefault()
*/
@Override
protected void setDefault() {
super.setDefault();
setPeriod(new TimePeriod());
}
use of com.arm.mbed.cloud.sdk.common.TimePeriod in project mbed-cloud-sdk-java by ARMmbed.
the class ConnectExamples method getResourceValue.
/**
* Gets a resource value.
*/
@SuppressWarnings("boxing")
@Example
public void getResourceValue() {
ConnectionOptions config = Configuration.get();
Connect api = new Connect(config);
// resource path to get value from
String resourcePath = "/5001/0/1";
try {
// Getting a connected device.
DeviceListOptions options = new DeviceListOptions();
options.setLimit(1);
Paginator<Device> deviceIterator = api.listAllConnectedDevices(options);
if (!deviceIterator.hasNext()) {
fail("No endpoints registered. Aborting.");
}
Device device = deviceIterator.first();
log("Device", device);
Resource resourceToConsider = api.getResource(device, resourcePath);
if (resourceToConsider == null) {
fail("The resource of interest does not exist on this device");
}
log("Resource of interest", resourceToConsider);
// Getting resource value
Object value = api.getResourceValue(resourceToConsider, new TimePeriod(10));
log("Resource value", value);
// Stopping potential daemons running
api.stopNotifications();
api.shutdownConnectService();
} catch (Exception e) {
e.printStackTrace();
logError("last API Metadata", api.getLastApiMetadata());
try {
api.stopNotifications();
} catch (MbedCloudException e1) {
e1.printStackTrace();
}
api.shutdownConnectService();
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.common.TimePeriod in project mbed-cloud-sdk-java by ARMmbed.
the class ConnectExamples method setResourceValue.
/**
* Sets a resource value.
*/
@SuppressWarnings("boxing")
@Example
public void setResourceValue() {
ConnectionOptions config = Configuration.get();
Connect api = new Connect(config);
// writable resource path to set a value to
String resourcePath = "/5001/0/1";
try {
// Getting a connected device.
DeviceListOptions options = new DeviceListOptions();
options.setLimit(1);
Paginator<Device> deviceIterator = api.listAllConnectedDevices(options);
if (!deviceIterator.hasNext()) {
fail("No endpoints registered. Aborting.");
}
Device device = deviceIterator.next();
log("Device", device);
Resource resourceToConsider = api.getResource(device, resourcePath);
log("Resource of interest", resourceToConsider);
if (resourceToConsider == null) {
fail("The resource of interest does not exist on this device");
}
// Getting resource value
Object value = api.getResourceValue(resourceToConsider, new TimePeriod(10));
log("Current resource value", value);
// Setting a new resource value
api.setResourceValue(resourceToConsider, "10", new TimePeriod(10));
// Getting the modified resource value
value = api.getResourceValue(resourceToConsider, new TimePeriod(10));
log("Newly set resource value", value);
// Stopping potential daemons running
api.stopNotifications();
api.shutdownConnectService();
} catch (Exception e) {
e.printStackTrace();
logError("last API Metadata", api.getLastApiMetadata());
try {
api.stopNotifications();
} catch (MbedCloudException e1) {
e1.printStackTrace();
}
api.shutdownConnectService();
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.common.TimePeriod in project mbed-cloud-sdk-java by ARMmbed.
the class TestAbstractObserver method testOne.
@Test
public void testOne() {
SubscriptionTestManagerFixedInput manager = new SubscriptionTestManagerFixedInput(true);
TestObserver obs = manager.createObserver(SubscriptionType.DEVICE_STATE_CHANGE, null, BackpressureStrategy.BUFFER);
try {
NotificationTestMessageValue value = obs.one(new TimePeriod(5));
// Value should be the first element received.
assertEquals(0, value.i);
// The observer should have been disposed
assertTrue(obs.isDisposed());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
// Checking that timeout works properly.
SubscriptionTestManagerNeverInput manager2 = new SubscriptionTestManagerNeverInput(true);
obs = manager2.createObserver(SubscriptionType.DEVICE_STATE_CHANGE, null, BackpressureStrategy.BUFFER);
long start = 0;
try {
start = System.currentTimeMillis();
NotificationTestMessageValue value = obs.one(new TimePeriod(2));
assertNull(value);
// Value should never be received.
} catch (MbedCloudException e) {
double time = (System.currentTimeMillis() - start) / 1000d;
assertNotNull(e);
assertEquals("The value could not be retrieved", e.getMessage());
// Check that at least 2 seconds elapsed before the exception was thrown.
assertTrue(time > 2);
// Check that the timeout was of the right order of magnitude.
assertTrue(time < 5);
}
}
Aggregations