use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.
the class AsyncPagination method useThirdPartySubscriber_Reactor.
private static void useThirdPartySubscriber_Reactor() {
System.out.println("running AutoPagination - using third party subscriber...\n");
DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create();
ListTablesPublisher publisher = asyncClient.listTablesPaginator(ListTablesRequest.builder().build());
// The Flux class has many helper methods that work with any reactive streams compatible publisher implementation
List<String> tables = Flux.from(publisher).flatMapIterable(ListTablesResponse::tableNames).collectList().block();
System.out.println(tables);
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBAsyncCreateTable method main.
public static void main(String[] args) throws InterruptedException {
final String USAGE = "\n" + "Usage:\n" + " DynamoDBAsyncCreateTable <table> <key >\n\n" + "Where:\n" + " table - the table to create (i.e., Music3)\n\n" + " key - the key for the table (i.e., Artist)\n" + "Example:\n" + " Music3 Artist \n";
if (args.length < 2) {
System.out.println(USAGE);
System.exit(1);
}
/* Read the name from command args */
String tableName = args[0];
String key = args[1];
// Create the DynamoDbAsyncClient object
Region region = Region.US_EAST_1;
DynamoDbAsyncClient client = DynamoDbAsyncClient.builder().region(region).build();
createTable(client, tableName, key);
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBAsyncListTables method main.
public static void main(String[] args) throws InterruptedException {
// Create the DynamoDbAsyncClient object
Region region = Region.US_EAST_1;
DynamoDbAsyncClient client = DynamoDbAsyncClient.builder().region(region).build();
listTables(client);
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project openhab-addons by openhab.
the class DynamoDBPersistenceService method store.
@Override
public void store(Item item, @Nullable String alias) {
// Timestamp and capture state immediately as rest of the store is asynchronous (state might change in between)
ZonedDateTime time = ZonedDateTime.now();
logIfManyQueuedTasks();
if (!(item instanceof GenericItem)) {
return;
}
if (item.getState() instanceof UnDefType) {
logger.debug("Undefined item state received. Not storing item {}.", item.getName());
return;
}
if (!isReadyToStore()) {
logger.warn("Not ready to store (config error?), not storing item {}.", item.getName());
return;
}
// Get Item describing the real type of data
// With non-group items this is same as the argument item. With Group items, this is item describing the type of
// state stored in the group.
final Item itemTemplate;
try {
itemTemplate = getEffectiveItem(item);
} catch (IllegalStateException e) {
// Logged already
return;
}
String effectiveName = (alias != null) ? alias : item.getName();
// We do not want to rely item.state since async context below can execute much later.
// We 'copy' the item for local use. copyItem also normalizes the unit with NumberItems.
final GenericItem copiedItem = copyItem(itemTemplate, item, effectiveName, null);
resolveTableSchema().thenAcceptAsync(resolved -> {
if (!resolved) {
logger.warn("Table schema not resolved, not storing item {}.", copiedItem.getName());
return;
}
DynamoDbEnhancedAsyncClient localClient = client;
DynamoDbAsyncClient localLowlevelClient = lowLevelClient;
DynamoDBConfig localConfig = dbConfig;
DynamoDBTableNameResolver localTableNameResolver = tableNameResolver;
if (!isProperlyConfigured || localClient == null || localLowlevelClient == null || localConfig == null || localTableNameResolver == null) {
logger.warn("Not ready to store (config error?), not storing item {}.", item.getName());
return;
}
Integer expireDays = localConfig.getExpireDays();
final DynamoDBItem<?> dto;
switch(localTableNameResolver.getTableSchema()) {
case NEW:
dto = AbstractDynamoDBItem.fromStateNew(copiedItem, time, expireDays);
break;
case LEGACY:
dto = AbstractDynamoDBItem.fromStateLegacy(copiedItem, time);
break;
default:
throw new IllegalStateException("Unexpected. Bug");
}
logger.trace("store() called with item {} {} '{}', which was converted to DTO {}", copiedItem.getClass().getSimpleName(), effectiveName, copiedItem.getState(), dto);
dto.accept(new DynamoDBItemVisitor<TableCreatingPutItem<? extends DynamoDBItem<?>>>() {
@Override
public TableCreatingPutItem<? extends DynamoDBItem<?>> visit(DynamoDBBigDecimalItem dynamoBigDecimalItem) {
return new TableCreatingPutItem<DynamoDBBigDecimalItem>(DynamoDBPersistenceService.this, dynamoBigDecimalItem, getTable(DynamoDBBigDecimalItem.class));
}
@Override
public TableCreatingPutItem<? extends DynamoDBItem<?>> visit(DynamoDBStringItem dynamoStringItem) {
return new TableCreatingPutItem<DynamoDBStringItem>(DynamoDBPersistenceService.this, dynamoStringItem, getTable(DynamoDBStringItem.class));
}
}).putItemAsync();
}, executor).exceptionally(e -> {
logger.error("Unexcepted error", e);
return null;
});
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project openhab-addons by openhab.
the class DynamoDBPersistenceService method disconnect.
private void disconnect() {
DynamoDbAsyncClient localLowLevelClient = lowLevelClient;
if (client == null || localLowLevelClient == null) {
return;
}
localLowLevelClient.close();
lowLevelClient = null;
client = null;
dbConfig = null;
tableNameResolver = null;
isProperlyConfigured = false;
tableCache.clear();
}
Aggregations