Example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList.

Prototype

public CopyOnWriteArrayList() 

Source Link

Document

Creates an empty list.

Usage

From source file:com.frostwire.android.gui.transfers.TransferManager.java

private TransferManager() {
    onSharedPreferenceChangeListener = (sharedPreferences, key) -> onPreferenceChanged(key);
    registerPreferencesChangeListener();
    this.httpDownloads = new CopyOnWriteArrayList<>();
    this.bittorrentDownloadsList = new CopyOnWriteArrayList<>();
    this.bittorrentDownloadsMap = new HashMap<>(0);
    this.downloadsToReview = 0;
    async(this::loadTorrentsTask);
}

From source file:io.github.minecraftgui.models.network.UserConnection.java

public void addOnGuiOpenListener(OnGuiListener plugin, OnGuiListener.OnGuiOpen onGuiOpen) {
    CopyOnWriteArrayList<OnGuiListener.OnGuiOpen> onGuiOpens = onGuiOpenListeners.get(plugin);

    if (onGuiOpens == null) {
        onGuiOpens = new CopyOnWriteArrayList<>();
        onGuiOpenListeners.put(plugin, onGuiOpens);
    }/*w  w w  . j  a  v  a 2s .  c  o  m*/

    onGuiOpens.add(onGuiOpen);
}

From source file:de.taimos.httputils.HTTPRequest.java

/**
 * @param name the name of the query parameter
 * @param value the value of the query parameter
 * @return this//from   w  w  w .ja va  2  s  .c  om
 */
public HTTPRequest queryParam(final String name, final String value) {
    if (!this.queryParams.containsKey(name)) {
        this.queryParams.put(name, new CopyOnWriteArrayList<String>());
    }
    this.queryParams.get(name).add(value);
    return this;
}

From source file:org.wrml.runtime.format.application.schema.json.JsonSchema.java

JsonSchema(final JsonSchemaLoader loader, final ObjectNode rootNode) {

    _JsonSchemaLoader = loader;//from w w w  .  j ava 2 s .c  om
    _RootNode = rootNode;

    final SyntaxLoader syntaxLoader = _JsonSchemaLoader.getContext().getSyntaxLoader();
    _SchemaUri = Definitions.PropertyType.$Schema.getValue(_RootNode, syntaxLoader);

    _ExtendsSet = new CopyOnWriteArraySet<>();

    _Properties = new ConcurrentHashMap<>();
    _Dependencies = new ConcurrentHashMap<>();
    _Required = new CopyOnWriteArrayList<>();
    _Links = new CopyOnWriteArrayList<>();

    // TODO not pass the args...
    parseExtensions(rootNode, syntaxLoader);
    parseProperties();
    parseLinks();
    parseRequireds();
    parseDependencies();
}

From source file:Ternary.java

public Ternary() {
    super();
    trits = new CopyOnWriteArrayList<Trit>();
}

From source file:lineage2.gameserver.instancemanager.OlympiadHistoryManager.java

/**
 * Method addHistory0.// w w  w. j  a  v a  2s .  c  o  m
 * @param map IntObjectMap<List<OlympiadHistory>>
 * @param objectId int
 * @param history OlympiadHistory
 */
private void addHistory0(IntObjectMap<List<OlympiadHistory>> map, int objectId, OlympiadHistory history) {
    List<OlympiadHistory> historySet = map.get(objectId);
    if (historySet == null) {
        map.put(objectId, historySet = new CopyOnWriteArrayList<>());
    }
    historySet.add(history);
}

From source file:io.hops.ha.common.TransactionStateManager.java

Runnable createThread(final TransactionStateManager tsm) {
    return new Runnable() {
        @Override/*from   www  . j  a v a  2s. c  o  m*/
        public void run() {
            lock.writeLock().lock();
            long commitDuration = 0;
            long startTime = System.currentTimeMillis();
            double accumulatedCycleDuration = 0;
            long nbCycles = 0;
            List<Long> duration = new ArrayList<Long>();
            List<Integer> rpcCount = new ArrayList<Integer>();
            double accumulatedRPCCount = 0;
            long t1 = 0;
            long t2 = 0;
            long t3 = 0;
            long t4 = 0;
            while (running) {
                try {
                    //create new transactionState
                    currentTransactionState = new TransactionStateImpl(TransactionState.TransactionType.RM, 0,
                            true, tsm);
                    curentRPCs = new CopyOnWriteArrayList<transactionStateWrapper>();
                    acceptedRPC.set(0);
                    //accept RPCs
                    lock.writeLock().unlock();
                    commitDuration = System.currentTimeMillis() - startTime;
                    t3 = commitDuration;
                    //        Thread.sleep(Math.max(0, 10-commitDuration));
                    waitForBatch(Math.max(0, batchMaxDuration - commitDuration));
                    t4 = System.currentTimeMillis() - startTime;
                    //stop acception RPCs
                    lock.writeLock().lock();

                    long cycleDuration = System.currentTimeMillis() - startTime;
                    if (cycleDuration > batchMaxDuration + 10) {
                        LOG.debug("Cycle too long: " + cycleDuration + "| " + t1 + ", " + t2 + ", " + t3 + ", "
                                + t4);
                    }
                    nbCycles++;
                    accumulatedCycleDuration += cycleDuration;
                    duration.add(cycleDuration);
                    rpcCount.add(acceptedRPC.get());
                    accumulatedRPCCount += acceptedRPC.get();
                    if (duration.size() > 39) {
                        double avgCycleDuration = accumulatedCycleDuration / nbCycles;
                        LOG.debug("cycle duration: " + avgCycleDuration + " " + duration.toString());
                        double avgRPCCount = accumulatedRPCCount / nbCycles;
                        LOG.debug("rpc count: " + avgRPCCount + " " + rpcCount.toString());
                        duration = new ArrayList<Long>();
                        rpcCount = new ArrayList<Integer>();
                    }

                    startTime = System.currentTimeMillis();
                    //wait for all the accepted RPCs to finish
                    int count = 0;
                    long startWaiting = System.currentTimeMillis();
                    while (currentTransactionState.getCounter() != 0 && running) {
                        if (System.currentTimeMillis() - startWaiting > 1000) {
                            startWaiting = System.currentTimeMillis();
                            count++;
                            LOG.error("waiting too long " + count + " counter: "
                                    + currentTransactionState.getCounter());
                            for (transactionStateWrapper w : curentRPCs) {
                                if (w.getRPCCounter() > 0) {
                                    LOG.error("rpc not finishing: " + w.getRPCID() + " type: " + w.getRPCType()
                                            + ", counter: " + w.getRPCCounter() + " running events: "
                                            + w.getRunningEvents());
                                }
                            }
                        }
                    }
                    if (!running) {
                        break;
                    }

                    t1 = System.currentTimeMillis() - startTime;
                    //commit the transactionState
                    currentTransactionState.commit(true);
                    t2 = System.currentTimeMillis() - startTime;
                } catch (IOException ex) {
                    //TODO we should probably do more than just print
                    LOG.error(ex, ex);
                } catch (InterruptedException ex) {
                    LOG.error(ex, ex);
                }
            }
            LOG.info("TransactionStateManager stoped");
        }
    };
}

From source file:com.exzogeni.dk.http.HttpTask.java

@NonNull
public HttpTask<V> addHeader(@NonNull String key, @NonNull String... values) {
    List<String> headers = mHeaders.get(key);
    if (headers == null) {
        headers = new CopyOnWriteArrayList<>();
        mHeaders.put(key, headers);/*from w  w  w  .  ja v a 2  s.co m*/
    }
    headers.clear();
    Collections.addAll(headers, values);
    return this;
}

From source file:edu.temple.cis3238.wiki.vo.TopicVO.java

/**
 * @param tagsCollection the tagsCollection to set
 *///from   ww  w .j a  v a 2 s .  c o  m
public void setTagsCollection(ArrayList<TagsVO> tagsCollection) {
    if (tagsCollection != null && !tagsCollection.isEmpty()) {
        this.tagsCollection = new CopyOnWriteArrayList<TagsVO>();
        Collections.sort(tagsCollection);
        this.tagsCollection.addAll(tagsCollection);
    }
}

From source file:org.apache.stratos.autoscaler.PartitionContext.java

public PartitionContext(Partition partition) {
    this.setPartition(partition);
    this.minimumMemberCount = partition.getPartitionMin();
    this.partitionId = partition.getId();
    this.pendingMembers = new ArrayList<MemberContext>();
    this.activeMembers = new ArrayList<MemberContext>();
    this.terminationPendingMembers = new ArrayList<MemberContext>();
    this.obsoletedMembers = new CopyOnWriteArrayList<String>();
    //        this.faultyMembers = new CopyOnWriteArrayList<String>();
    memberStatsContexts = new ConcurrentHashMap<String, MemberStatsContext>();

    // check if a different value has been set for expiryTime
    XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
    expiryTime = conf.getLong("autoscaler.member.expiryTimeout", 900000);
    if (log.isDebugEnabled()) {
        log.debug("Member expiry time is set to: " + expiryTime);
    }/*from   w  w  w. j  a v  a2s. c om*/

    Thread th = new Thread(new PendingMemberWatcher(this));
    th.start();
}