Example usage for com.google.common.collect Lists newCopyOnWriteArrayList

List of usage examples for com.google.common.collect Lists newCopyOnWriteArrayList

Introduction

In this page you can find the example usage for com.google.common.collect Lists newCopyOnWriteArrayList.

Prototype

@GwtIncompatible("CopyOnWriteArrayList")
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() 

Source Link

Document

Creates an empty CopyOnWriteArrayList instance.

Usage

From source file:org.ldp4j.server.data.impl.CoreRuntimeDelegate.java

public CoreRuntimeDelegate() {
    this.mediaTypes = Sets.newLinkedHashSet();
    this.providers = Lists.newCopyOnWriteArrayList();
    populateMediaTypeProviders();
}

From source file:silentium.gameserver.utils.MinionList.java

public MinionList(L2MonsterInstance pMaster) {
    if (pMaster == null)
        throw new NullPointerException("MinionList: master is null");

    _master = pMaster;//from   www . j av a2s. c om
    _minionReferences = Lists.newCopyOnWriteArrayList();
}

From source file:com.davidbracewell.concurrent.Threads.java

/**
 * Execute list./*from w  w  w.ja  va2  s .co  m*/
 *
 * @param source          the source
 * @param processor       the processor
 * @param numberOfThreads the number of threads
 * @param queueSize       the queue size
 * @return the list
 */
public static <IN, OUT> List<OUT> execute(Iterable<IN> source, final Function<IN, OUT> processor,
        int numberOfThreads, int queueSize) {
    Preconditions.checkNotNull(source);
    Preconditions.checkNotNull(processor);
    Preconditions.checkArgument(numberOfThreads > 0, "Must specified at least 1 thread.");
    Preconditions.checkArgument(queueSize > 0, "Must specified a queue size of at least 1.");
    final List<OUT> out = Lists.newCopyOnWriteArrayList();
    BlockingThreadPoolExecutor executor = new BlockingThreadPoolExecutor(numberOfThreads, numberOfThreads,
            queueSize);
    for (final IN item : source) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                out.add(processor.apply(item));
            }
        });
    }
    executor.shutdown();
    try {
        executor.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.warn(e);
    }
    return out;
}

From source file:org.ros.android.view.visualization.layer.OccupancyGridLayer.java

public OccupancyGridLayer(GraphName topic) {
    super(topic, nav_msgs.OccupancyGrid._TYPE);
    tiles = Lists.newCopyOnWriteArrayList();
    ready = false;
}

From source file:silentium.gameserver.utils.MinionList.java

/**
 * Called on the master spawn Old minions (from previous spawn) are deleted. If master can respawn - enabled reuse of the killed minions.
 *///from  w  w  w.j  a v a  2 s.c om
public void onMasterSpawn() {
    deleteSpawnedMinions();

    // if master has spawn and can respawn - try to reuse minions
    if (_reusedMinionReferences == null && _master.getTemplate().getMinionData() != null
            && _master.getSpawn() != null && _master.getSpawn().isRespawnEnabled())
        _reusedMinionReferences = Lists.newCopyOnWriteArrayList();
}

From source file:com.chiorichan.session.FileSession.java

protected static List<Session> getActiveSessions() {
    List<Session> sessions = Lists.newCopyOnWriteArrayList();
    File[] files = getSessionsDirectory().listFiles();
    long start = System.currentTimeMillis();

    if (files == null)
        return sessions;

    for (File f : files)
        if (FileFilterUtils.and(FileFilterUtils.suffixFileFilter("yaml"), FileFilterUtils.fileFileFilter())
                .accept(f)) {/*  w w w .j  a va  2  s. c  o m*/
            try {
                sessions.add(new FileSession(f));
            } catch (SessionException e) {
                e.printStackTrace();
            }
        }

    PermissionManager.getLogger().info("FileSession loaded " + sessions.size()
            + " sessions from the data store in " + (System.currentTimeMillis() - start) + "ms!");

    return sessions;
}

From source file:org.lanternpowered.server.inject.impl.SimpleModule.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public SimpleModule(List<Binding<?>> bindings, Map<Class<?>, Supplier<?>> suppliers,
        List<MethodSpec<?>> methodBindings) {
    Map<Class<?>, List<Binding<?>>> map = Maps.newConcurrentMap();
    for (Binding<?> binding : bindings) {
        map.computeIfAbsent(binding.getParameterSpec().getType(), type -> Lists.newCopyOnWriteArrayList())
                .add(binding);//from  w w  w  .  j  a v  a2 s  .c  o m
    }
    this.methodBindings = ImmutableList.copyOf(methodBindings);
    this.bindings = (Map) ImmutableMap.copyOf(Maps.transformValues(map, ImmutableList::copyOf));
    this.suppliers = ImmutableMap.copyOf(suppliers);
}

From source file:com.chiorichan.session.SqlSession.java

protected static List<Session> getActiveSessions() {
    List<Session> sessionList = Lists.newCopyOnWriteArrayList();
    DatabaseEngine sql = Loader.getDatabase();
    long start = System.currentTimeMillis();

    try {/*from  ww  w.  jav a  2  s  . co  m*/
        ResultSet rs = sql.query("SELECT * FROM `sessions`;");

        if (sql.getRowCount(rs) > 0)
            do {
                try {
                    sessionList.add(new SqlSession(rs));
                } catch (SessionException e) {
                    if (e.getMessage().contains("expired"))
                        sql.queryUpdate(
                                "DELETE FROM `sessions` WHERE `sessionId` = '" + rs.getString("sessionId")
                                        + "' && `sessionName` = '" + rs.getString("sessionName") + "';");
                    else
                        e.printStackTrace();
                }
            } while (rs.next());
    } catch (SQLException e) {
        Loader.getLogger().warning("There was a problem reloading saved sessions.", e);
    }

    PermissionManager.getLogger().info("SqlSession loaded " + sessionList.size()
            + " sessions from the data store in " + (System.currentTimeMillis() - start) + "ms!");

    return sessionList;
}

From source file:io.macgyver.core.config.CoreSecurityConfig.java

@SuppressWarnings("rawtypes")
@Bean// w w  w .ja va2 s. co m
List<AccessDecisionVoter<? extends Object>> macAccessDecisionVoterList() {
    List<AccessDecisionVoter<? extends Object>> x = Lists.newCopyOnWriteArrayList();
    x.add(new LogOnlyAccessDecisionVoter());
    x.add(new RoleVoter());
    x.add(new WebExpressionVoter());
    x.add(new Jsr250Voter());
    return x;

}

From source file:silentium.gameserver.model.olympiad.OlympiadManager.java

public final boolean registerNoble(L2PcInstance player, CompetitionType type) {
    if (!Olympiad._inCompPeriod) {
        player.sendPacket(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
        return false;
    }//from  www . j  av a2 s  . c om

    if (Olympiad.getInstance().getMillisToCompEnd() < 600000) {
        player.sendPacket(SystemMessageId.GAME_REQUEST_CANNOT_BE_MADE);
        return false;
    }

    switch (type) {
    case CLASSED: {
        if (!checkNoble(player))
            return false;

        List<Integer> classed = _classBasedRegisters.get(player.getBaseClass());
        if (classed != null)
            classed.add(player.getObjectId());
        else {
            classed = Lists.newCopyOnWriteArrayList();
            classed.add(player.getObjectId());
            _classBasedRegisters.put(player.getBaseClass(), classed);
        }

        player.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_CLASSIFIED_GAMES);
        break;
    }

    case NON_CLASSED: {
        if (!checkNoble(player))
            return false;

        _nonClassBasedRegisters.add(player.getObjectId());
        player.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_NO_CLASS_GAMES);
        break;
    }
    }
    return true;
}