use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync in project aws-doc-sdk-examples by awsdocs.
the class DaxAsyncClientDemo method main.
public static void main(String[] args) throws Exception {
ClientConfig daxConfig = new ClientConfig().withCredentialsProvider(new ProfileCredentialsProvider()).withEndpoints("mydaxcluster.2cmrwl.clustercfg.dax.use1.cache.amazonaws.com:8111");
AmazonDynamoDBAsync client = new ClusterDaxAsyncClient(daxConfig);
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Artist", new AttributeValue().withS("No One You Know"));
key.put("SongTitle", new AttributeValue().withS("Scared of My Shadow"));
GetItemRequest request = new GetItemRequest().withTableName("Music").withKey(key);
// Java Futures
Future<GetItemResult> call = client.getItemAsync(request);
while (!call.isDone()) {
// Do other processing while you're waiting for the response
System.out.println("Doing something else for a few seconds...");
Thread.sleep(3000);
}
try {
call.get();
} catch (ExecutionException ee) {
// Futures always wrap errors as an ExecutionException.
// The *real* exception is stored as the cause of the
// ExecutionException
Throwable exception = ee.getCause();
System.out.println("Error getting item: " + exception.getMessage());
}
// Async callbacks
call = client.getItemAsync(request, new AsyncHandler<GetItemRequest, GetItemResult>() {
@Override
public void onSuccess(GetItemRequest request, GetItemResult getItemResult) {
System.out.println("Result: " + getItemResult);
}
@Override
public void onError(Exception e) {
System.out.println("Unable to read item");
System.err.println(e.getMessage());
// Callers can also test if exception is an instance of
// AmazonServiceException or AmazonClientException and cast
// it to get additional information
}
});
call.get();
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync in project spring-integration-aws by spring-projects.
the class DynamoDbMetadataStoreTests method setup.
@BeforeClass
public static void setup() throws Exception {
AmazonDynamoDBAsync dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB();
try {
dynamoDB.deleteTableAsync(TEST_TABLE);
Waiter<DescribeTableRequest> waiter = dynamoDB.waiters().tableNotExists();
waiter.run(new WaiterParameters<>(new DescribeTableRequest(TEST_TABLE)).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(1))));
} catch (Exception e) {
}
store = new DynamoDbMetaDataStore(dynamoDB, TEST_TABLE);
store.afterPropertiesSet();
}
Aggregations