本文整理汇总了Java中java.util.concurrent.CopyOnWriteArrayList.get方法的典型用法代码示例。如果您正苦于以下问题:Java CopyOnWriteArrayList.get方法的具体用法?Java CopyOnWriteArrayList.get怎么用?Java CopyOnWriteArrayList.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CopyOnWriteArrayList
的用法示例。
在下文中一共展示了CopyOnWriteArrayList.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finishAndNotifyListener
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
logger.trace("{}: got all shard responses", actionName);
int successfulShards = 0;
int failedShards = 0;
int totalNumCopies = 0;
List<ShardOperationFailedException> shardFailures = null;
for (int i = 0; i < shardsResponses.size(); i++) {
ReplicationResponse shardResponse = shardsResponses.get(i);
if (shardResponse == null) {
// non active shard, ignore
} else {
failedShards += shardResponse.getShardInfo().getFailed();
successfulShards += shardResponse.getShardInfo().getSuccessful();
totalNumCopies += shardResponse.getShardInfo().getTotal();
if (shardFailures == null) {
shardFailures = new ArrayList<>();
}
for (ReplicationResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(failure.fullShardId(), failure.getCause())));
}
}
}
listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
示例2: finishAndNotifyListener
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
logger.trace("{}: got all shard responses", actionName);
int successfulShards = 0;
int failedShards = 0;
int totalNumCopies = 0;
List<ShardOperationFailedException> shardFailures = null;
for (int i = 0; i < shardsResponses.size(); i++) {
ActionWriteResponse shardResponse = shardsResponses.get(i);
if (shardResponse == null) {
// non active shard, ignore
} else {
failedShards += shardResponse.getShardInfo().getFailed();
successfulShards += shardResponse.getShardInfo().getSuccessful();
totalNumCopies += shardResponse.getShardInfo().getTotal();
if (shardFailures == null) {
shardFailures = new ArrayList<>();
}
for (ActionWriteResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(new ShardId(failure.index(), failure.shardId()), failure.getCause())));
}
}
}
listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
示例3: getContentByCourse
import java.util.concurrent.CopyOnWriteArrayList; //导入方法依赖的package包/类
/**
* Method to get all contents of a given course.
*/
@SuppressWarnings("unchecked")
private Response getContentByCourse(String userId, Map<String, Object> request) {
Response response = null;
Util.DbInfo dbInfo = Util.dbInfoMap.get(JsonKey.LEARNER_CONTENT_DB);
if (request.get(JsonKey.COURSE) != null) {
Map<String, Object> courseMap = (Map<String, Object>) request.get(JsonKey.COURSE);
String courseId = (String) courseMap.get(JsonKey.COURSE_ID);
CopyOnWriteArrayList<String> contentIds =
new CopyOnWriteArrayList<String>((List<String>) courseMap.get(JsonKey.CONTENT_IDS));
LinkedHashMap<String, Object> queryMap = new LinkedHashMap<String, Object>();
queryMap.put(JsonKey.USER_ID, userId);
queryMap.put(JsonKey.COURSE_ID, courseId);
response = cassandraOperation.getRecordsByProperties(dbInfo.getKeySpace(),
dbInfo.getTableName(), queryMap);
List<Map<String, Object>> modifiedContentList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> resultedList =
(List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE);
if (null != contentIds && !(contentIds.isEmpty())) {
for (Map<String, Object> map : resultedList) {
boolean flag = true;
for (int i = 0; i < contentIds.size() && flag; i++) {
String contentId = contentIds.get(i);
if (contentId.equals((String) map.get(JsonKey.CONTENT_ID))) {
modifiedContentList.add(map);
flag = false;
}
}
}
response.getResult().put(JsonKey.RESPONSE, modifiedContentList);
}
}
return response;
}