List of usage examples for com.amazonaws.services.dynamodbv2.model StreamSpecification StreamSpecification
StreamSpecification
From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java
License:Open Source License
/** * @return StreamArn//from w w w. java 2 s . co m */ public static String createTable(AmazonDynamoDB client, String tableName) { java.util.List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N")); java.util.List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); // Partition // key ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(2L) .withWriteCapacityUnits(2L); StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(StreamViewType.NEW_IMAGE); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withAttributeDefinitions(attributeDefinitions).withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput).withStreamSpecification(streamSpecification); try { System.out.println("Creating table " + tableName); CreateTableResult result = client.createTable(createTableRequest); return result.getTableDescription().getLatestStreamArn(); } catch (ResourceInUseException e) { System.out.println("Table already exists."); return describeTable(client, tableName).getTable().getLatestStreamArn(); } }
From source file:org.wildfly.camel.test.common.aws.DynamoDBUtils.java
License:Apache License
public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException { CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement("Id", KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N)) .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)) .withStreamSpecification(new StreamSpecification().withStreamEnabled(true) .withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES)); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.createTable(tableReq); return table.waitForActive(); }
From source file:tr.com.serkanozal.samba.cache.impl.SambaGlobalCache.java
License:Open Source License
private Table ensureTableAvailable() { boolean tableExist = false; try {//from w ww.j ava 2 s .c o m DYNAMO_DB.describeTable(DYNAMO_DB_TABLE_NAME); tableExist = true; } catch (ResourceNotFoundException e) { } if (!tableExist) { ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("id").withAttributeType("S")); ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH)); StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(DYNAMO_DB_TABLE_NAME) .withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions) .withStreamSpecification(streamSpecification) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits((long) DYNAMO_DB_TABLE_READ_CAPACITY_PER_SECOND) .withWriteCapacityUnits((long) DYNAMO_DB_TABLE_WRITE_CAPACITY_PER_SECOND)); try { LOGGER.info(String.format("Creating DynamoDB table (%s) creation, because it is not exist", DYNAMO_DB_TABLE_NAME)); DYNAMO_DB.createTable(createTableRequest); } catch (ResourceInUseException e) { LOGGER.info(String.format("Ignoring DynamoDB table (%s) creation, because it is already exist", DYNAMO_DB_TABLE_NAME)); } } else { LOGGER.info(String.format("Ignoring DynamoDB table (%s) creation, because it is already exist", DYNAMO_DB_TABLE_NAME)); } while (true) { DescribeTableResult describeTableResult = DYNAMO_DB.describeTable(DYNAMO_DB_TABLE_NAME); TableDescription tableDescription = describeTableResult.getTable(); if ("ACTIVE".equals(tableDescription.getTableStatus())) { break; } LOGGER.info(String.format("DynamoDB table (%s) is not active yet, waiting until it is active ...", DYNAMO_DB_TABLE_NAME)); try { Thread.sleep(1000); } catch (InterruptedException e) { } } SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate(new StreamListener(), 0, 1000, TimeUnit.MILLISECONDS); return new Table(DYNAMO_DB, DYNAMO_DB_TABLE_NAME); }