本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.WriteRequest类的典型用法代码示例。如果您正苦于以下问题:Java WriteRequest类的具体用法?Java WriteRequest怎么用?Java WriteRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WriteRequest类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了WriteRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendDeleteRequests
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
public int sendDeleteRequests() throws IllegalArgumentException {
if (batchDeleteRequests.isEmpty()) {
return 0;
}
BatchWriteItemRequest batchWriteItemRequest = genBatchWriteItemRequest();
BatchWriteItemResult bathWriteResult = sendBatchWriteRequest(batchWriteItemRequest);
int undeletedItemNum = countAndPrintUndeletedItems(bathWriteResult);
if(!isRunningOnDDBLocal) {
// DDB Local does not support rate limiting
tableWriteRateLimiter.adjustRateWithConsumedCapacity(bathWriteResult.getConsumedCapacity());
}
int deletedRequest = batchDeleteRequests.size() - undeletedItemNum;
totalNumOfItemsDeleted += deletedRequest;
PrintHelper.printDeleteProgressInfo(deletedRequest, totalNumOfItemsDeleted);
batchDeleteRequests = new ArrayList<WriteRequest>();
return deletedRequest;
}
示例2: storeResult
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
private void storeResult(final Map<String, Object> result) {
final String userId = (String) result.get("user_id");
final String userToken = (String) result.get("access_token");
final String teamId = (String) result.get("team_id");
@SuppressWarnings("unchecked")
final Map<String, Object> bot = (Map<String, Object>) result.get("bot");
final String botToken = (String) bot.get("bot_access_token");
final String botId = (String) bot.get("bot_user_id");
final ArrayList<PutRequest> putRequests = new ArrayList<>();
putRequests.add(item("user:" + userId + ":token", userToken));
putRequests.add(item("user:" + botId + ":token", botToken));
putRequests.add(item("team:" + teamId + ":botuser", botId));
final List<WriteRequest> writeRequests = putRequests.stream()
.map(WriteRequest::new)
.collect(Collectors.toList());
final HashMap<String, List<WriteRequest>> requestItems = new HashMap<>();
requestItems.put(TableName, writeRequests);
final BatchWriteItemRequest batchWriteItemRequest = new BatchWriteItemRequest().withRequestItems(requestItems);
ddb.batchWriteItem(batchWriteItemRequest);
}
示例3: batchWrite
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
/**
* Writes multiple items in batch.
* @param items a map of tables->write requests
*/
protected static void batchWrite(Map<String, List<WriteRequest>> items) {
if (items == null || items.isEmpty()) {
return;
}
try {
BatchWriteItemResult result = getClient().batchWriteItem(new BatchWriteItemRequest().
withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withRequestItems(items));
if (result == null) {
return;
}
logger.debug("batchWrite(): total {}, cc {}", items.size(), result.getConsumedCapacity());
if (result.getUnprocessedItems() != null && !result.getUnprocessedItems().isEmpty()) {
Thread.sleep(1000);
logger.warn("{} UNPROCESSED write requests!", result.getUnprocessedItems().size());
batchWrite(result.getUnprocessedItems());
}
} catch (Exception e) {
logger.error(null, e);
}
}
示例4: deleteAll
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
@Override
public <P extends ParaObject> void deleteAll(String appid, List<P> objects) {
if (objects == null || objects.isEmpty() || StringUtils.isBlank(appid)) {
return;
}
List<WriteRequest> reqs = new ArrayList<>(objects.size());
for (ParaObject object : objects) {
if (object != null) {
reqs.add(new WriteRequest().withDeleteRequest(new DeleteRequest().
withKey(Collections.singletonMap(Config._KEY,
new AttributeValue(getKeyForAppid(object.getId(), appid))))));
}
}
batchWrite(Collections.singletonMap(getTableNameForAppid(appid), reqs));
logger.debug("DAO.deleteAll() {}", objects.size());
}
示例5: commitPartial
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
private void commitPartial(List<WriteRequest> list) {
Timer t = new Timer();
Map<String, List<WriteRequest>> map = new HashMap<>();
map.put(getTenant().getName(), list);
BatchWriteItemResult result = m_client.batchWriteItem(new BatchWriteItemRequest(map));
int retry = 0;
while(result.getUnprocessedItems().size() > 0) {
if(retry == RETRY_SLEEPS.length) throw new RuntimeException("All retries failed");
m_logger.debug("Committing {} unprocessed items, retry: {}", result.getUnprocessedItems().size(), retry + 1);
try {
Thread.sleep(RETRY_SLEEPS[retry++]);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result = m_client.batchWriteItem(new BatchWriteItemRequest(result.getUnprocessedItems()));
}
m_logger.debug("Committed {} writes in {}", list.size(), t);
list.clear();
}
示例6: batchWriteItem
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
public CompletableFuture<BatchWriteItemResult> batchWriteItem(final Map<String, List<WriteRequest>> requestItems) {
return asyncExecutor.execute(new Callable<BatchWriteItemResult>() {
@Override
public BatchWriteItemResult call() throws Exception {
return dbExecutor.batchWriteItem(requestItems);
}
});
}
示例7: putBatch
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
public BatchWriteItemResult putBatch(String tableName, Map<String, AttributeValue> item,
long maxItemsPerBatch, Reporter reporter)
throws UnsupportedEncodingException {
int itemSizeBytes = DynamoDBUtil.getItemSizeBytes(item);
if (itemSizeBytes > maxItemByteSize) {
throw new RuntimeException("Cannot pass items with size greater than " + maxItemByteSize
+ ". Item with size of " + itemSizeBytes + " was given.");
}
maxItemsPerBatch = DynamoDBUtil.getBoundedBatchLimit(config, maxItemsPerBatch);
BatchWriteItemResult result = null;
if (writeBatchMap.containsKey(tableName)) {
boolean writeRequestsForTableAtLimit =
writeBatchMap.get(tableName).size() >= maxItemsPerBatch;
boolean totalSizeOfWriteBatchesOverLimit =
writeBatchMapSizeBytes + itemSizeBytes > maxBatchSize;
if (writeRequestsForTableAtLimit || totalSizeOfWriteBatchesOverLimit) {
result = writeBatch(reporter, itemSizeBytes);
}
}
// writeBatchMap could be cleared from writeBatch()
List<WriteRequest> writeBatchList;
if (!writeBatchMap.containsKey(tableName)) {
writeBatchList = new ArrayList<>((int) maxItemsPerBatch);
writeBatchMap.put(tableName, writeBatchList);
} else {
writeBatchList = writeBatchMap.get(tableName);
}
writeBatchList.add(new WriteRequest().withPutRequest(new PutRequest().withItem(item)));
writeBatchMapSizeBytes += itemSizeBytes;
return result;
}
示例8: write
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
@Override
public void write(K key, V value) throws IOException {
if (value == null) {
throw new RuntimeException("Null record encountered. At least the key columns must be "
+ "specified.");
}
verifyInterval();
if (progressable != null) {
progressable.progress();
}
DynamoDBItemWritable item = convertValueToDynamoDBItem(key, value);
BatchWriteItemResult result = client.putBatch(tableName, item.getItem(),
permissibleWritesPerSecond - writesPerSecond, reporter);
batchSize++;
totalItemsWritten++;
if (result != null) {
if (result.getConsumedCapacity() != null) {
for (ConsumedCapacity consumedCapacity : result.getConsumedCapacity()) {
double consumedUnits = consumedCapacity.getCapacityUnits();
totalIOPSConsumed += consumedUnits;
}
}
int unprocessedItems = 0;
for (List<WriteRequest> requests : result.getUnprocessedItems().values()) {
unprocessedItems += requests.size();
}
writesPerSecond += batchSize - unprocessedItems;
batchSize = unprocessedItems;
}
}
示例9: toWritesByTable
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
private Map<String, List<WriteRequest>> toWritesByTable(Iterator<SinkRecord> recordIterator) {
final Map<String, List<WriteRequest>> writesByTable = new HashMap<>();
for (int count = 0; recordIterator.hasNext() && count < config.batchSize; count++) {
final SinkRecord record = recordIterator.next();
final WriteRequest writeRequest = new WriteRequest(toPutRequest(record));
writesByTable.computeIfAbsent(tableName(record), k -> new ArrayList<>(config.batchSize)).add(writeRequest);
}
return writesByTable;
}
示例10: makeMessage
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
private static String makeMessage(Map<String, List<WriteRequest>> unprocessedItems) {
final StringBuilder msg = new StringBuilder("Unprocessed writes: {");
for (Map.Entry<String, List<WriteRequest>> e : unprocessedItems.entrySet()) {
msg.append(" ").append(e.getKey()).append("(").append(e.getValue().size()).append(")").append(" ");
}
msg.append("}");
return msg.toString();
}
示例11: putItems
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
@Override
public void putItems(T... items) {
if ( null == items || 0 == items.length ) return;
for ( int chunk=0; chunk < items.length; chunk += DDB_MAX_BATCH_WRITE_ITEM ) {
TableWriteItems request = new TableWriteItems(_tableName);
int max = Math.min(items.length-chunk, DDB_MAX_BATCH_WRITE_ITEM);
for ( int idx=0; idx < max; idx++ ) {
request.addItemToPut(_encryption.encrypt(toItem(items[chunk+idx])));
}
BatchWriteItemOutcome response = maybeBackoff(false, () ->
_dynamodb.batchWriteItem(request));
while ( true ) {
if ( null == response.getUnprocessedItems() ) break;
List<WriteRequest> unprocessed = response.getUnprocessedItems().get(_tableName);
if ( null == unprocessed || unprocessed.size() == 0 ) {
resetPTE(null);
break;
}
if(LOG.isDebugEnabled())
LOG.debug("putItems() unprocessed: "+unprocessed.size());
gotPTE(false);
try {
Thread.sleep(backoffSleep(false));
} catch ( InterruptedException ex ) {
Thread.currentThread().interrupt();
throw new AbortedException(ex);
}
Map<String,List<WriteRequest>> unproc = response.getUnprocessedItems();
response = maybeBackoff(false, () ->
_dynamodb.batchWriteItemUnprocessed(unproc));
}
}
}
示例12: deleteItems
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
@Override
public void deleteItems(IndexKey... keys) {
if ( null == keys || 0 == keys.length ) return;
for ( int chunk=0; chunk < keys.length; chunk += DDB_MAX_BATCH_WRITE_ITEM ) {
TableWriteItems request = new TableWriteItems(_tableName);
int max = Math.min(keys.length-chunk, DDB_MAX_BATCH_WRITE_ITEM);
for ( int idx=0; idx < max; idx++ ) {
IndexKey key = keys[chunk+idx];
if ( null == key ) continue;
request.addPrimaryKeyToDelete(toPrimaryKey(key));
}
BatchWriteItemOutcome response = maybeBackoff(false, () ->
_dynamodb.batchWriteItem(request));
while ( true ) {
if ( null == response.getUnprocessedItems() ) break;
List<WriteRequest> unprocessed = response.getUnprocessedItems().get(_tableName);
if ( null == unprocessed || unprocessed.size() == 0 ) {
resetPTE(null);
break;
}
if(LOG.isDebugEnabled())
LOG.debug("deleteItems() unprocessed: "+unprocessed.size());
gotPTE(false);
try {
Thread.sleep(backoffSleep(false));
} catch ( InterruptedException ex ) {
Thread.currentThread().interrupt();
throw new AbortedException(ex);
}
Map<String,List<WriteRequest>> unproc = response.getUnprocessedItems();
response = maybeBackoff(false, () ->
_dynamodb.batchWriteItemUnprocessed(unproc));
}
}
}
示例13: addTimingResults
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
/**
*
* @{inheritDoc
*/
@Override
public void addTimingResults(final @Nonnull String tableName, final @Nonnull List<TankResult> results,
boolean async) {
if (!results.isEmpty()) {
Runnable task = new Runnable() {
public void run() {
MethodTimer mt = new MethodTimer(logger, this.getClass(), "addTimingResults (" + results + ")");
List<WriteRequest> requests = new ArrayList<WriteRequest>();
try {
for (TankResult result : results) {
Map<String, AttributeValue> item = getTimingAttributes(result);
PutRequest putRequest = new PutRequest().withItem(item);
WriteRequest writeRequest = new WriteRequest().withPutRequest(putRequest);
requests.add(writeRequest);
}
sendBatch(tableName, requests);
} catch (Exception t) {
logger.error("Error adding results: " + t.getMessage(), t);
throw new RuntimeException(t);
}
mt.endAndLog();
}
};
if (async) {
EXECUTOR.execute(task);
} else {
task.run();
}
}
}
示例14: addItems
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
/**
* @{inheritDoc
*/
@Override
public void addItems(final String tableName, List<Item> itemList, final boolean asynch) {
if (!itemList.isEmpty()) {
final List<Item> items = new ArrayList<Item>(itemList);
Runnable task = new Runnable() {
public void run() {
MethodTimer mt = new MethodTimer(logger, this.getClass(), "addItems (" + items + ")");
List<WriteRequest> requests = new ArrayList<WriteRequest>();
try {
for (Item item : items) {
Map<String, AttributeValue> toInsert = itemToMap(item);
PutRequest putRequest = new PutRequest().withItem(toInsert);
WriteRequest writeRequest = new WriteRequest().withPutRequest(putRequest);
requests.add(writeRequest);
}
sendBatch(tableName, requests);
} catch (Exception t) {
logger.error("Error adding results: " + t.getMessage(), t);
throw new RuntimeException(t);
}
mt.endAndLog();
}
};
if (asynch) {
EXECUTOR.execute(task);
} else {
task.run();
}
}
}
示例15: sendBatch
import com.amazonaws.services.dynamodbv2.model.WriteRequest; //导入依赖的package包/类
/**
* @param tableName
* @param requests
*/
private void sendBatch(final String tableName, List<WriteRequest> requests) {
int numBatches = (int) Math.ceil(requests.size() / (BATCH_SIZE * 1D));
for (int i = 0; i < numBatches; i++) {
Map<String, List<WriteRequest>> requestItems = new HashMap<String, List<WriteRequest>>();
List<WriteRequest> batch = requests.subList(i * BATCH_SIZE,
Math.min(i * BATCH_SIZE + BATCH_SIZE, requests.size()));
requestItems.put(tableName, batch);
addItemsToTable(tableName, new BatchWriteItemRequest().withRequestItems(requestItems));
}
}