本文整理匯總了Java中com.google.common.collect.Lists.newCopyOnWriteArrayList方法的典型用法代碼示例。如果您正苦於以下問題:Java Lists.newCopyOnWriteArrayList方法的具體用法?Java Lists.newCopyOnWriteArrayList怎麽用?Java Lists.newCopyOnWriteArrayList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Lists
的用法示例。
在下文中一共展示了Lists.newCopyOnWriteArrayList方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: kills
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public TaskKill kills(long taskId) {
JuiceTask task = daoUtils.queryTask(taskId);
if (null == task) {
throw new RestException(CommonStatusCode.QUERY_RECORD_EMPTY.getStatus(), "task not exist to kill!");
}
if (task.getTaskStatus() > TaskResult.Result.RUNNING.getType()) {
return new TaskKill(false, task.getTaskStatus(), task.getMessage());
}
TaskManagement taskManagement = new TaskManagement(Lists.newCopyOnWriteArrayList(), KILL);
log.info("task id-> " + task.getTaskId() + "task name-> " + task.getTaskName() + "retry-> " + task.getRetry() + "agent id-> " + task.getAgentId());
TaskManagement.TaskAgentRel taskAgentRel = new TaskManagement.TaskAgentRel(task.getTaskId(), task.getTaskName(), task.getRetry(), task.getAgentId());
taskManagement.getTaskAgentRels().add(taskAgentRel);
log.info("push q start");
cacheUtils.pushToQueue(cachesBizConfig.getManagementQueue(), gson.toJson(taskManagement));
log.info("push q fin");
return new TaskKill(true, task.getTaskStatus(), "juice accept kill task command");
}
示例2: testRegisterThreadSafety
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public void testRegisterThreadSafety() throws Exception {
List<StringCatcher> catchers = Lists.newCopyOnWriteArrayList();
List<Future<?>> futures = Lists.newArrayList();
ExecutorService executor = Executors.newFixedThreadPool(10);
int numberOfCatchers = 10000;
for (int i = 0; i < numberOfCatchers; i++) {
futures.add(executor.submit(new Registrator(bus, catchers)));
}
for (int i = 0; i < numberOfCatchers; i++) {
futures.get(i).get();
}
assertEquals("Unexpected number of catchers in the list",
numberOfCatchers, catchers.size());
bus.post(EVENT);
List<String> expectedEvents = ImmutableList.of(EVENT);
for (StringCatcher catcher : catchers) {
assertEquals("One of the registered catchers did not receive an event.",
expectedEvents, catcher.getEvents());
}
}
示例3: CountDownLatchHelper
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public CountDownLatchHelper() {
executes = Lists.newCopyOnWriteArrayList();
data = Lists.newCopyOnWriteArrayList();
threadPool= new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(),
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
}
示例4: reconciles
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public TaskReconcile reconciles(List<Long> taskIds) {
List<JuiceTask> tasks = daoUtils.queryTasks(taskIds);
Map<Long, TaskReconcile.Reconcile> reconcileMap = getTaskReconcile(taskIds);
TaskManagement taskManagement = new TaskManagement(Lists.newCopyOnWriteArrayList(), RECONCILE);
tasks.stream().parallel().forEach(t -> {
String value = t.getAgentId();
boolean isReconciled = false;
String message = "";
TaskReconcile.Reconcile reconcile = reconcileMap.get(t.getTaskId());
if (null == reconcile) {
String error = "taskId not matched with database record, taskId: " + t.getTaskId();
log.warn(error);
throw new RestException(ErrorCode.OBJECT_NOT_EQUAL_ERROR.getCode(), error);
} else if (!t.getTaskStatus().equals(TaskResult.Result.RUNNING.getType())) {
message = "not reconcile due to terminal task status : " + TaskResult.Result.getName(t.getTaskStatus());
} else if (StringUtils.isBlank(value)) {
reconcile.setReconciled(false);
daoUtils.finishTaskWithSource(t.getTaskId(), TaskResult.Result.EXPIRED.getType(), "task expired", "");
message = "not reconcile due to terminal task status : " + TaskResult.Result.EXPIRED.name();
} else {
TaskManagement.TaskAgentRel taskAgentRel = new TaskManagement.TaskAgentRel(t.getTaskId(), t.getTaskName(), t.getRetry(), value);
taskManagement.getTaskAgentRels().add(taskAgentRel);
isReconciled = true;
message = "reconcile task";
}
reconcile.setTaskId(t.getTaskId());
reconcile.setReconciled(isReconciled);
reconcile.setMessage(message);
});
int reconcileCount = taskManagement.getTaskAgentRels().size();
if (reconcileCount > 0) {
cacheUtils.pushToQueue(cachesBizConfig.getManagementQueue(), gson.toJson(taskManagement));
}
return new TaskReconcile(taskIds.size(), reconcileCount, mapsToLists(reconcileMap));
}
示例5: mapsToLists
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private List<TaskReconcile.Reconcile> mapsToLists(Map<Long, TaskReconcile.Reconcile> map) {
final List<TaskReconcile.Reconcile> reconciles = Lists.newCopyOnWriteArrayList();
map.entrySet().parallelStream().forEach(
v -> {
reconciles.add(v.getValue());
}
);
return reconciles;
}
示例6: TccTransaction
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public TccTransaction() {
this.transId = IdWorkerUtils.getInstance().createUUID();
this.createTime = new Date();
this.lastTime = new Date();
participants = Lists.newCopyOnWriteArrayList();
}
示例7: MythTransaction
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public MythTransaction() {
this.transId = IdWorkerUtils.getInstance().createUUID();
this.createTime = new Date();
this.lastTime = new Date();
mythParticipants = Lists.newCopyOnWriteArrayList();
}
示例8: handleMessage
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
public void handleMessage(Dpid dpid, OFMessage msg) {
if (isDisabled) {
return;
}
try {
switch (msg.getType()) {
case STATS_REPLY:
if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) {
OFPortStatsReply portStatsReply = (OFPortStatsReply) msg;
List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid);
if (portStatsReplyList == null) {
portStatsReplyList = Lists.newCopyOnWriteArrayList();
}
portStatsReplyList.addAll(portStatsReply.getEntries());
portStatsReplies.put(dpid, portStatsReplyList);
if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid);
if (statsEntries != null) {
pushPortMetrics(dpid, statsEntries);
statsEntries.clear();
}
}
}
break;
case ERROR:
if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) {
LOG.error("port mod failed");
}
default:
break;
}
} catch (IllegalStateException e) {
// system is shutting down and the providerService is no longer
// valid. Messages cannot be processed.
}
}
示例9: values
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
public CompletableFuture<Collection<Versioned<V>>> values() {
List<Versioned<V>> allValues = Lists.newCopyOnWriteArrayList();
return CompletableFuture.allOf(getMaps().stream()
.map(map -> map.values().thenAccept(allValues::addAll))
.toArray(CompletableFuture[]::new))
.thenApply(v -> allValues);
}
示例10: allAlgorithmUnitList
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public static synchronized List<AlgorithmHolder> allAlgorithmUnitList() {
return Lists.newCopyOnWriteArrayList(allOperators);
}
示例11: ReleaseMessageScanner
import com.google.common.collect.Lists; //導入方法依賴的package包/類
public ReleaseMessageScanner() {
listeners = Lists.newCopyOnWriteArrayList();
executorService = Executors.newScheduledThreadPool(1, ApolloThreadFactory
.create("ReleaseMessageScanner", true));
}