当前位置: 首页>>代码示例>>Java>>正文


Java AmazonDynamoDB.shutdown方法代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDB.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonDynamoDB.shutdown方法的具体用法?Java AmazonDynamoDB.shutdown怎么用?Java AmazonDynamoDB.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.dynamodbv2.AmazonDynamoDB的用法示例。


在下文中一共展示了AmazonDynamoDB.shutdown方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createItemIfNotExists

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
boolean createItemIfNotExists(String key, long currentTimeMillis, Context context) {

		LambdaLogger logger = context.getLogger();
		AmazonDynamoDB client = createDynamoDBClient(cc);
		String functionName = context.getFunctionName();

		try {
			// Create a record if it does not exist
			PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
					.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
					.addItemEntry(COL_KEY, new AttributeValue(key))
					.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
					.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
					.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
			client.putItem(req);
			return true;
		} catch (ConditionalCheckFailedException e) {
			logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
			return false;
		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:24,代码来源:LambdaLock.java

示例2: createTableTest

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Test
public void createTableTest() {
    AmazonDynamoDB ddb = DynamoDBEmbedded.create().amazonDynamoDB();
    try {
        String tableName = "Movies";
        String hashKeyName = "film_id";
        CreateTableResult res = createTable(ddb, tableName, hashKeyName);

        TableDescription tableDesc = res.getTableDescription();
        assertEquals(tableName, tableDesc.getTableName());
        assertEquals("[{AttributeName: " + hashKeyName + ",KeyType: HASH}]", tableDesc.getKeySchema().toString());
        assertEquals("[{AttributeName: " + hashKeyName + ",AttributeType: S}]",
            tableDesc.getAttributeDefinitions().toString());
        assertEquals(Long.valueOf(1000L), tableDesc.getProvisionedThroughput().getReadCapacityUnits());
        assertEquals(Long.valueOf(1000L), tableDesc.getProvisionedThroughput().getWriteCapacityUnits());
        assertEquals("ACTIVE", tableDesc.getTableStatus());
        assertEquals("arn:aws:dynamodb:ddblocal:000000000000:table/Movies", tableDesc.getTableArn());

        ListTablesResult tables = ddb.listTables();
        assertEquals(1, tables.getTableNames().size());
    } finally {
        ddb.shutdown();
    }
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:25,代码来源:DynamoDBEmbeddedTest.java

示例3: createInMemoryDb

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
public static AmazonDynamoDB createInMemoryDb() {
    AmazonDynamoDB dynamodb = null;
    try {
        // Create an in-memory and in-process instance of DynamoDB Local
        AmazonDynamoDBLocal amazonDynamoDBLocal = DynamoDBEmbedded.create();
        dynamodb = amazonDynamoDBLocal.amazonDynamoDB();
        return dynamodb;
    } catch (Exception e){
        if(dynamodb != null)
            dynamodb.shutdown();// Shutdown the thread pools in DynamoDB Local / Embedded
    }
    return dynamodb;
}
 
开发者ID:satr,项目名称:aws-amazon-shopping-bot-lambda-func,代码行数:14,代码来源:ObjectMother.java

示例4: updateItem

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {

		AmazonDynamoDB client = createDynamoDBClient(cc);

		String functionName = context.getFunctionName();
		try {
			long sec = currentTimeMillis - expiredIntervalMillis;

			DynamoDB dynamoDB = new DynamoDB(client);
			Table table = dynamoDB.getTable(TABLE_NAME);

			Map<String, String> expressionAttributeNames = new HashMap<>();
			expressionAttributeNames.put("#created_time", COL_CREATED_TIME);

			Map<String, Object> expressionAttributeValues = new HashMap<>();
			expressionAttributeValues.put(":now", currentTimeMillis);
			expressionAttributeValues.put(":expired", sec);

			table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
					"#created_time < :expired", // ConditionExpression
					expressionAttributeNames, expressionAttributeValues);

			return true;
		} catch (ConditionalCheckFailedException e) {
			return false;
		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:30,代码来源:LambdaLock.java

示例5: next

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Dosage next() {
    if (!this.hasNext()) {
        throw new IllegalStateException(
            "nothing left in the iterator"
        );
    }
    final AmazonDynamoDB aws = this.credentials.aws();
    try {
        final QueryRequest rqst =
            this.request.withExclusiveStartKey(
                this.result.getLastEvaluatedKey()
            );
        final long start = System.currentTimeMillis();
        final QueryResult rslt = aws.query(rqst);
        Logger.info(
            this,
            // @checkstyle LineLength (1 line)
            "#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
            rslt.getCount(), rqst.getTableName(),
            rqst.getKeyConditions(),
            new PrintableConsumedCapacity(
                rslt.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return new QueryValve.NextDosage(this.credentials, rqst, rslt);
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:32,代码来源:QueryValve.java

示例6: get

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public AttributeValue get(final String attr) throws IOException {
    final String attrib = String.format(Locale.ENGLISH, attr);
    AttributeValue value = this.attributes.get(attrib);
    if (value == null) {
        final AmazonDynamoDB aws = this.credentials.aws();
        try {
            final GetItemRequest request = this.makeItemRequestFor(attrib);
            final long start = System.currentTimeMillis();
            final GetItemResult result = aws.getItem(request);
            value = result.getItem().get(attrib);
            Logger.info(
                this,
                // @checkstyle LineLength (1 line)
                "#get('%s'): loaded '%[text]s' from DynamoDB, %s, in %[ms]s",
                attrib, value,
                new PrintableConsumedCapacity(
                    result.getConsumedCapacity()
                ).print(),
                System.currentTimeMillis() - start
            );
        } catch (final AmazonClientException ex) {
            throw new IOException(
                String.format(
                    "failed to get \"%s\" from \"%s\" by %s",
                    attr, this.name, this.keys
                ),
                ex
            );
        } finally {
            aws.shutdown();
        }
    }
    if (value == null) {
        throw new NoSuchElementException(
            String.format("attribute \"%s\" not found", attr)
        );
    }
    return value;
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:41,代码来源:AwsItem.java

示例7: put

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Map<String, AttributeValue> put(
    final Map<String, AttributeValueUpdate> attrs) throws IOException {
    final AmazonDynamoDB aws = this.credentials.aws();
    final Attributes expected = this.attributes.only(this.keys);
    try {
        final UpdateItemRequest request = new UpdateItemRequest()
            .withTableName(this.name)
            .withExpected(expected.asKeys())
            .withKey(expected)
            .withAttributeUpdates(attrs)
            .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
            .withReturnValues(ReturnValue.UPDATED_NEW);
        final long start = System.currentTimeMillis();
        final UpdateItemResult result = aws.updateItem(request);
        Logger.info(
            this, "#put('%s'): updated item to DynamoDB, %s, in %[ms]s",
            attrs,
            new PrintableConsumedCapacity(
                result.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return result.getAttributes();
    } catch (final AmazonClientException ex) {
        throw new IOException(
            String.format(
                "failed to put %s into \"%s\" with %s",
                attrs, this.name, this.keys
            ),
            ex
        );
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:37,代码来源:AwsItem.java

示例8: remove

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
@SuppressWarnings("PMD.UseConcurrentHashMap")
public void remove() {
    synchronized (this.dosage) {
        final AmazonDynamoDB aws = this.credentials.aws();
        try {
            final Dosage prev = this.dosage.get();
            final List<Map<String, AttributeValue>> items =
                new ArrayList<Map<String, AttributeValue>>(prev.items());
            final Map<String, AttributeValue> item =
                items.remove(this.position);
            final long start = System.currentTimeMillis();
            final DeleteItemResult res = aws.deleteItem(
                new DeleteItemRequest()
                    .withTableName(this.name)
                    .withKey(new Attributes(item).only(this.keys))
                    .withReturnConsumedCapacity(
                        ReturnConsumedCapacity.TOTAL
                    )
                    .withExpected(
                        new Attributes(item).only(this.keys).asKeys()
                    )
            );
            this.dosage.set(new AwsIterator.Fixed(prev, items));
            --this.position;
            Logger.info(
                this,
                "#remove(): item #%d removed from DynamoDB, %s, in %[ms]s",
                this.position,
                new PrintableConsumedCapacity(
                    res.getConsumedCapacity()
                ).print(),
                System.currentTimeMillis() - start
            );
        } finally {
            aws.shutdown();
        }
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:40,代码来源:AwsIterator.java

示例9: put

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Item put(final Map<String, AttributeValue> attributes)
    throws IOException {
    final AmazonDynamoDB aws = this.credentials.aws();
    try {
        final PutItemRequest request = new PutItemRequest();
        request.setTableName(this.self);
        request.setItem(attributes);
        request.setReturnValues(ReturnValue.NONE);
        request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
        final PutItemResult result = aws.putItem(request);
        final long start = System.currentTimeMillis();
        Logger.info(
            this, "#put('%[text]s'): created item in '%s', %s, in %[ms]s",
            attributes, this.self,
            new PrintableConsumedCapacity(
                result.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return new AwsItem(
            this.credentials,
            this.frame(),
            this.self,
            new Attributes(attributes).only(this.keys()),
            new Array<String>(this.keys())
        );
    } catch (final AmazonClientException ex) {
        throw new IOException(
            String.format(
                "failed to put into \"%s\" with %s",
                this.self, attributes
            ),
            ex
        );
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:40,代码来源:AwsTable.java

示例10: delete

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public void delete(final Map<String, AttributeValue> attributes)
    throws IOException {
    final AmazonDynamoDB aws = this.credentials.aws();
    try {
        final DeleteItemRequest request = new DeleteItemRequest();
        request.setTableName(this.self);
        request.setKey(attributes);
        request.setReturnValues(ReturnValue.NONE);
        request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
        final DeleteItemResult result = aws.deleteItem(request);
        final long start = System.currentTimeMillis();
        Logger.info(
            this,
            "#delete('%[text]s'): deleted item in '%s', %s, in %[ms]s",
            attributes, this.self,
            new PrintableConsumedCapacity(
                result.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
    } catch (final AmazonClientException ex) {
        throw new IOException(
            String.format(
                "failed to delete at \"%s\" by keys %s",
                this.self, attributes
            ),
            ex
        );
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:34,代码来源:AwsTable.java

示例11: fetch

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Dosage fetch(final Credentials credentials,
    final String table, final Map<String, Condition> conditions,
    final Collection<String> keys) throws IOException {
    final AmazonDynamoDB aws = credentials.aws();
    try {
        final Collection<String> attrs = new HashSet<String>(
            Arrays.asList(this.attributes)
        );
        attrs.addAll(keys);
        final ScanRequest request = new ScanRequest()
            .withTableName(table)
            .withAttributesToGet(attrs)
            .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
            .withScanFilter(conditions)
            .withLimit(this.limit);
        final long start = System.currentTimeMillis();
        final ScanResult result = aws.scan(request);
        Logger.info(
            this,
            "#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
            result.getCount(), table, conditions,
            new PrintableConsumedCapacity(
                result.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return new ScanValve.NextDosage(credentials, request, result);
    } catch (final AmazonClientException ex) {
        throw new IOException(
            String.format(
                "failed to fetch from \"%s\" by %s and %s",
                table, conditions, keys
            ),
            ex
        );
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:41,代码来源:ScanValve.java

示例12: next

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Dosage next() {
    if (!this.hasNext()) {
        throw new IllegalStateException(
            "nothing left in the iterator"
        );
    }
    final AmazonDynamoDB aws = this.credentials.aws();
    try {
        final ScanRequest rqst = this.request.withExclusiveStartKey(
            this.result.getLastEvaluatedKey()
        );
        final long start = System.currentTimeMillis();
        final ScanResult rslt = aws.scan(rqst);
        Logger.info(
            this,
            // @checkstyle LineLength (1 line)
            "#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
            rslt.getCount(), rqst.getTableName(), rqst.getScanFilter(),
            new PrintableConsumedCapacity(
                rslt.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return new ScanValve.NextDosage(this.credentials, rqst, rslt);
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:30,代码来源:ScanValve.java

示例13: open

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
private void open(boolean batchLoading)
{
    if(type == GraphDatabaseType.TITAN_DYNAMODB && config.getDynamodbPrecreateTables()) {
        List<CreateTableRequest> requests = new LinkedList<>();
        long wcu = config.getDynamodbTps();
        long rcu = Math.max(1, config.dynamodbConsistentRead() ? wcu : (wcu / 2));
        for(String store : Constants.REQUIRED_BACKEND_STORES) {
            final String tableName = config.getDynamodbTablePrefix() + "_" + store;
            if(BackendDataModel.MULTI == config.getDynamodbDataModel()) {
                requests.add(DynamoDBStore.createTableRequest(tableName,
                    rcu, wcu));
            } else if(BackendDataModel.SINGLE == config.getDynamodbDataModel()) {
                requests.add(DynamoDBSingleRowStore.createTableRequest(tableName, rcu, wcu));
            }
        }
        //TODO is this autocloseable?
        final AmazonDynamoDB client =
            new AmazonDynamoDBClient(Client.createAWSCredentialsProvider(config.getDynamodbCredentialsFqClassName(),
                config.getDynamodbCredentialsCtorArguments() == null ? null : config.getDynamodbCredentialsCtorArguments().split(",")));
        client.setEndpoint(config.getDynamodbEndpoint());
        for(CreateTableRequest request : requests) {
            try {
                client.createTable(request);
            } catch(ResourceInUseException ignore) {
                //already created, good
            }
        }
        client.shutdown();
    }
    titanGraph = buildTitanGraph(type, dbStorageDirectory, config, batchLoading);
}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:32,代码来源:TitanGraphDatabase.java

示例14: fetch

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Dosage fetch(final Credentials credentials, final String table,
    final Map<String, Condition> conditions, final Collection<String> keys)
    throws IOException {
    final AmazonDynamoDB aws = credentials.aws();
    try {
        final Collection<String> attrs = new HashSet<String>(
            Arrays.asList(this.attributes)
        );
        attrs.addAll(keys);
        QueryRequest request = new QueryRequest()
            .withTableName(table)
            .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
            .withKeyConditions(conditions)
            .withConsistentRead(this.consistent)
            .withScanIndexForward(this.forward)
            .withSelect(this.select)
            .withLimit(this.limit);
        if (this.select.equals(Select.SPECIFIC_ATTRIBUTES.toString())) {
            request = request.withAttributesToGet(attrs);
        }
        if (!this.index.isEmpty()) {
            request = request.withIndexName(this.index);
        }
        final long start = System.currentTimeMillis();
        final QueryResult result = aws.query(request);
        Logger.info(
            this,
            "#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
            result.getCount(), table, conditions,
            new PrintableConsumedCapacity(
                result.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return new QueryValve.NextDosage(credentials, request, result);
    } catch (final AmazonClientException ex) {
        throw new IOException(
            String.format(
                "failed to fetch from \"%s\" by %s and %s",
                table, conditions, keys
            ),
            ex
        );
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:49,代码来源:QueryValve.java


注:本文中的com.amazonaws.services.dynamodbv2.AmazonDynamoDB.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。