本文整理匯總了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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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();
}
}