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


Java WriteRequest类代码示例

本文整理汇总了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;
}
 
开发者ID:awslabs,项目名称:dynamodb-online-index-violation-detector,代码行数:18,代码来源:TableWriter.java

示例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);
}
 
开发者ID:aztecrex,项目名称:java-translatebot,代码行数:25,代码来源:OauthHandler.java

示例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);
	}
}
 
开发者ID:Erudika,项目名称:para,代码行数:26,代码来源:AWSDynamoUtils.java

示例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());
}
 
开发者ID:Erudika,项目名称:para,代码行数:18,代码来源:AWSDynamoDAO.java

示例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();
  }
 
开发者ID:QSFT,项目名称:Doradus,代码行数:21,代码来源:DynamoDBService2.java

示例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);
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:9,代码来源:AsyncDynamoDBExecutor.java

示例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;
}
 
开发者ID:awslabs,项目名称:emr-dynamodb-connector,代码行数:36,代码来源:DynamoDBClient.java

示例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;
  }
}
 
开发者ID:awslabs,项目名称:emr-dynamodb-connector,代码行数:36,代码来源:AbstractDynamoDBRecordWriter.java

示例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;
}
 
开发者ID:shikhar,项目名称:kafka-connect-dynamodb,代码行数:10,代码来源:DynamoDbSinkTask.java

示例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();
}
 
开发者ID:shikhar,项目名称:kafka-connect-dynamodb,代码行数:9,代码来源:UnprocessedItemsException.java

示例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));
        }
    }
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:34,代码来源:DdbIndex.java

示例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));
        }
    }
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:36,代码来源:DdbIndex.java

示例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();
        }
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:35,代码来源:AmazonDynamoDatabaseDocApi.java

示例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();
        }
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:34,代码来源:AmazonDynamoDatabaseDocApi.java

示例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));
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:15,代码来源:AmazonDynamoDatabaseDocApi.java


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