List of usage examples for com.amazonaws.services.dynamodbv2.model StreamSpecification setStreamEnabled
public void setStreamEnabled(Boolean streamEnabled)
Indicates whether DynamoDB Streams is enabled (true) or disabled (false) on the table.
From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java
License:Open Source License
/** * @return StreamArn/* w ww . j a v a2s . c o 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:tr.com.serkanozal.samba.cache.impl.SambaGlobalCache.java
License:Open Source License
private Table ensureTableAvailable() { boolean tableExist = false; try {/* ww w .jav a 2 s . c om*/ 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); }