Example usage for com.amazonaws.services.dynamodbv2.model StreamSpecification setStreamViewType

List of usage examples for com.amazonaws.services.dynamodbv2.model StreamSpecification setStreamViewType

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model StreamSpecification setStreamViewType.

Prototype


public void setStreamViewType(StreamViewType streamViewType) 

Source Link

Document

When an item in the table is modified, StreamViewType determines what information is written to the stream for this table.

Usage

From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java

License:Open Source License

/**
 * @return StreamArn/*from w  ww . j ava2 s . 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 {/*w  w w. jav a2  s.  co  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);
}