Java Code Examples for com.google.common.collect.Lists.newCopyOnWriteArrayList()

The following are Jave code examples for showing how to use newCopyOnWriteArrayList() of the com.google.common.collect.Lists class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Juice   File: RestService.java   View Source Code Vote up 6 votes
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");

}
 
Example 2
Project: guava-mock   File: EventBusTest.java   View Source Code Vote up 6 votes
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());
  }
}
 
Example 3
Project: googles-monorepo-demo   File: EventBusTest.java   View Source Code Vote up 6 votes
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());
  }
}
 
Example 4
Project: happylifeplat-transaction   File: CountDownLatchHelper.java   View Source Code Vote up 5 votes
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());

}
 
Example 5
Project: Juice   File: RestService.java   View Source Code Vote up 5 votes
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));
}
 
Example 6
Project: Juice   File: RestService.java   View Source Code Vote up 5 votes
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;
}
 
Example 7
Project: happylifeplat-tcc   File: TccTransaction.java   View Source Code Vote up 5 votes
public TccTransaction() {
    this.transId = IdWorkerUtils.getInstance().createUUID();
    this.createTime = new Date();
    this.lastTime = new Date();
    participants = Lists.newCopyOnWriteArrayList();

}
 
Example 8
Project: myth   File: MythTransaction.java   View Source Code Vote up 5 votes
public MythTransaction() {
    this.transId = IdWorkerUtils.getInstance().createUUID();
    this.createTime = new Date();
    this.lastTime = new Date();
    mythParticipants = Lists.newCopyOnWriteArrayList();

}
 
Example 9
Project: athena   File: OpenFlowDeviceProvider.java   View Source Code Vote up 5 votes
@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.
    }
}
 
Example 10
Project: athena   File: PartitionedAsyncConsistentMap.java   View Source Code Vote up 5 votes
@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);
}
 
Example 11
Project: sipsoup   File: OperatorEnv.java   View Source Code Vote up 4 votes
public static synchronized List<AlgorithmHolder> allAlgorithmUnitList() {
    return Lists.newCopyOnWriteArrayList(allOperators);
}
 
Example 12
Project: happylifeplat-tcc   File: TccTransaction.java   View Source Code Vote up 4 votes
public TccTransaction(String transId) {
    this.transId = transId;
    this.createTime = new Date();
    this.lastTime = new Date();
    participants = Lists.newCopyOnWriteArrayList();
}
 
Example 13
Project: myth   File: MythTransaction.java   View Source Code Vote up 4 votes
public MythTransaction(String transId) {
    this.transId = transId;
    this.createTime = new Date();
    this.lastTime = new Date();
    mythParticipants = Lists.newCopyOnWriteArrayList();
}
 
Example 14
Project: apollo-custom   File: ReleaseMessageScanner.java   View Source Code Vote up 4 votes
public ReleaseMessageScanner() {
  listeners = Lists.newCopyOnWriteArrayList();
  executorService = Executors.newScheduledThreadPool(1, ApolloThreadFactory
      .create("ReleaseMessageScanner", true));
}