List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList
public CopyOnWriteArrayList()
From source file:events.TeamVsTeam.TeamVsTeam.java
public static void checkLive() { List<Long> new_live_list1 = new CopyOnWriteArrayList<>(); List<Long> new_live_list2 = new CopyOnWriteArrayList<>(); for (Long storeId : live_list1) { Player player = GameObjectsStorage.getAsPlayer(storeId); if (player != null) { new_live_list1.add(storeId); }/*from www .j a v a 2s. c o m*/ } for (Long storeId : live_list2) { Player player = GameObjectsStorage.getAsPlayer(storeId); if (player != null) { new_live_list2.add(storeId); } } live_list1 = new_live_list1; live_list2 = new_live_list2; for (Player player : getPlayers(live_list1)) { if (!player.isDead() && !player.isLogoutStarted()) { player.setTeam(TeamType.RED); } else { removePlayer(player); } } for (Player player : getPlayers(live_list2)) { if (!player.isDead() && !player.isLogoutStarted()) { player.setTeam(TeamType.BLUE); } else { removePlayer(player); } } if ((live_list1.size() < 1) || (live_list2.size() < 1)) { endBattle(); } }
From source file:net.ymate.platform.commons.lang.TreeObject.java
/** * - TreeObject//from ww w . j a va2 s.c o m * * @param tObject */ public TreeObject add(TreeObject tObject) { if (tObject != null) { if (_mode != MODE_MAP) { if (_mode == MODE_VALUE) { _type = TYPE_TREE_OBJECT; _mode = MODE_ARRAY; } if (_object == null) { // ? _object = new CopyOnWriteArrayList<TreeObject>(); } ((List<TreeObject>) _object).add(tObject); } else { throw new IllegalStateException(); } } return this; }
From source file:com.l2jfree.gameserver.model.entity.events.VIP.java
public static void clean() { _time = _winners = _endNPC = _joinNPC = _delay = _endX = _endY = _endZ = _startX = _startY = _startZ = _joinX = _joinY = _joinZ = _team = 0; _vipReward = _vipRewardAmount = _notVipReward = _notVipRewardAmount = _theVipReward = _theVipRewardAmount = 0; _started = _joining = _sitForced = false; _teamName = _joinArea = _theVIPName = ""; for (L2Player player : _playersVIP) { final VIPPlayerInfo info = player.as(VIPPlayerInfo.class); info._nameColourVIP = -1;//from w ww.j a v a 2 s . c o m player.setKarma(info._originalKarmaVIP); player.broadcastUserInfo(); player.setPlayerInfo(null); info._isTheVIP = false; info._isNotVIP = false; info._isVIP = false; } for (L2Player player : _playersNotVIP) { final VIPPlayerInfo info = player.as(VIPPlayerInfo.class); info._nameColourVIP = -1; player.setKarma(info._originalKarmaVIP); player.broadcastUserInfo(); player.setPlayerInfo(null); info._isTheVIP = false; info._isNotVIP = false; info._isVIP = false; } _savePlayers = new CopyOnWriteArrayList<String>(); _playersVIP = new CopyOnWriteArrayList<L2Player>(); _playersNotVIP = new CopyOnWriteArrayList<L2Player>(); }
From source file:com.auditbucket.engine.service.TrackService.java
public Iterable<TrackResultBean> createHeaders(Iterable<MetaInputBean> inputBeans, Company company, Fortress fortress) {/* w w w .ja va 2s .co m*/ Collection<TrackResultBean> arb = new CopyOnWriteArrayList<>(); for (MetaInputBean inputBean : inputBeans) { logger.trace("Batch Processing callerRef=[{}], documentType=[{}]", inputBean.getCallerRef(), inputBean.getDocumentType()); arb.add(createHeader(company, fortress, inputBean)); } return arb; }
From source file:org.kie.server.services.impl.KieServerImpl.java
public ServiceResponse<Void> disposeContainer(String containerId) { List<Message> messages = new CopyOnWriteArrayList<Message>(); try {//from ww w .j a va2s. c om KieContainerInstanceImpl kci = context.unregisterContainer(containerId); if (kci != null) { synchronized (kci) { eventSupport.fireBeforeContainerStopped(this, kci); kci.setStatus(KieContainerStatus.DISPOSING); // just in case if (kci.getKieContainer() != null) { org.kie.api.builder.ReleaseId releaseId = kci.getKieContainer().getReleaseId(); List<KieServerExtension> disposedExtensions = new ArrayList<KieServerExtension>(); try { // first attempt to dispose container on all extensions logger.debug("Container {} (for release id {}) shutdown: In Progress", containerId, kci.getResource().getReleaseId()); // process server extensions List<KieServerExtension> extensions = context.getServerExtensions(); for (KieServerExtension extension : extensions) { extension.disposeContainer(containerId, kci, new HashMap<String, Object>()); logger.debug("Container {} (for release id {}) {} shutdown: DONE", containerId, kci.getResource().getReleaseId(), extension); disposedExtensions.add(extension); } } catch (Exception e) { logger.warn( "Dispose of container {} failed, putting it back to started state by recreating container on {}", containerId, disposedExtensions); // since the dispose fail rollback must take place to put it back to running state Map<String, Object> parameters = getContainerParameters(releaseId, messages); for (KieServerExtension extension : disposedExtensions) { extension.createContainer(containerId, kci, parameters); logger.debug("Container {} (for release id {}) {} restart: DONE", containerId, kci.getResource().getReleaseId(), extension); } kci.setStatus(KieContainerStatus.STARTED); context.registerContainer(containerId, kci); logger.info("Container {} (for release id {}) STARTED after failed dispose", containerId, kci.getResource().getReleaseId()); messages.add(new Message(Severity.WARN, "Error disposing container '" + containerId + "' due to " + e.getMessage() + ", container is running")); return new ServiceResponse<Void>(ResponseType.FAILURE, "Container " + containerId + " failed to dispose, exception was raised: " + e.getClass().getName() + ": " + e.getMessage()); } if (kci.getScanner() != null && kci.getScanner().getStatus() != Status.SHUTDOWN) { kci.stopScanner(); } InternalKieContainer kieContainer = kci.getKieContainer(); kci.setKieContainer(null); // helps reduce concurrent access issues // this may fail, but we already removed the container from the registry kieContainer.dispose(); ks.getRepository().removeKieModule(releaseId); logger.info("Container {} (for release id {}) successfully stopped", containerId, kci.getResource().getReleaseId()); // store the current state of the server storeServerState(currentState -> { List<KieContainerResource> containers = new ArrayList<>(); currentState.getContainers().forEach(containerResource -> { if (!containerId.equals(containerResource.getContainerId())) { containers.add(containerResource); } }); currentState.setContainers(new HashSet<KieContainerResource>(containers)); }); messages.add( new Message(Severity.INFO, "Container " + containerId + " successfully stopped.")); eventSupport.fireAfterContainerStopped(this, kci); return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully disposed."); } else { messages.add( new Message(Severity.INFO, "Container " + containerId + " was not instantiated.")); return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated."); } } } else { messages.add(new Message(Severity.INFO, "Container " + containerId + " was not instantiated.")); return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated."); } } catch (Exception e) { messages.add(new Message(Severity.ERROR, "Error disposing container '" + containerId + "' due to " + e.getMessage())); logger.error("Error disposing Container '" + containerId + "'", e); return new ServiceResponse<Void>(ServiceResponse.ResponseType.FAILURE, "Error disposing container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage()); } finally { this.containerMessages.put(containerId, messages); } }
From source file:org.jahia.bundles.extender.jahiamodules.Activator.java
private void addToBeResolved(Bundle bundle, String missingDependency) { List<Bundle> bundlesWaitingForDepend = toBeResolved.get(missingDependency); if (bundlesWaitingForDepend == null) { bundlesWaitingForDepend = new CopyOnWriteArrayList<Bundle>(); toBeResolved.put(missingDependency, bundlesWaitingForDepend); }/*from www . j a v a 2 s . com*/ bundlesWaitingForDepend.add(bundle); }
From source file:org.geoserver.catalog.impl.DefaultCatalogFacade.java
public void resolve() { //JD creation checks are done here b/c when xstream depersists // some members may be left null //workspaces/*w w w . j a v a 2s .c o m*/ if (workspaces == null) { workspaces = new HashMap<String, WorkspaceInfo>(); } for (WorkspaceInfo ws : workspaces.values()) { resolve(ws); } //namespaces if (namespaces == null) { namespaces = new HashMap<String, NamespaceInfo>(); } for (NamespaceInfo ns : namespaces.values()) { resolve(ns); } //stores if (stores == null) { stores = new MultiHashMap(); } for (Object o : stores.values()) { resolve((StoreInfoImpl) o); } //styles if (styles == null) { styles = new ArrayList<StyleInfo>(); } for (StyleInfo s : styles) { resolve(s); } //resources if (resources == null) { resources = new MultiHashMap(); } for (Object o : resources.values()) { resolve((ResourceInfo) o); } //layers if (layers == null) { layers = new CopyOnWriteArrayList<LayerInfo>(); } for (LayerInfo l : layers) { resolve(l); } //layer groups if (layerGroups == null) { layerGroups = new ArrayList<LayerGroupInfo>(); } for (LayerGroupInfo lg : layerGroups) { resolve(lg); } //maps if (maps == null) { maps = new ArrayList<MapInfo>(); } for (MapInfo m : maps) { resolve(m); } }
From source file:sx.blah.discord.api.internal.DiscordUtils.java
/** * Converts an array of json {@link MessageObject.ReactionObject}s to a list of {@link IReaction}s. * * @param message The message the reactions belong to. * @param json The json objects representing the reactions. * @return The converted reaction objects. *//*from w w w. j a va 2 s . c om*/ public static List<IReaction> getReactionsFromJSON(IMessage message, MessageObject.ReactionObject[] json) { List<IReaction> reactions = new CopyOnWriteArrayList<>(); if (json != null) for (MessageObject.ReactionObject object : json) { long id = object.emoji.id == null ? 0 : Long.parseUnsignedLong(object.emoji.id); ReactionEmoji emoji = ReactionEmoji.of(object.emoji.name, id, object.emoji.animated); reactions.add(new Reaction(message, object.count, emoji)); } return reactions; }
From source file:io.milton.http.annotated.AnnotationResourceFactory.java
/** * Create an in-memory resource with the given timeout. The resource will * not be persisted, but may be distributed among the cluster if configured * as such.//from w w w .ja v a 2s .co m * * The resource may be flushed from the in-memory list after the given * timeout if not-null * * The type of the object returned is not intended to have any significance * and does not contain any meaningful content * * @param parentCollection * @param name * @param timeout - optional. The resource will be removed after this * timeout expires * @param lockInfo * @return - a temporary (not persistent) resource of an indeterminate type */ public LockHolder createLockHolder(AnnoCollectionResource parentCollection, String name, LockTimeout timeout, LockInfo lockInfo) { String parentKey = parentCollection.getUniqueId(); if (parentKey == null) { throw new RuntimeException( "Cant create temp resource because parent's uniqueID is null. Please add the @UniqueID for class: " + parentCollection.getSource().getClass()); } LockHolder r = new LockHolder(UUID.randomUUID()); r.setParentCollectionId(parentKey); r.setName(name); r.setLockTimeout(timeout); r.setLockInfo(lockInfo); synchronized (this) { List<LockHolder> list = mapOfTempResources.get(parentKey); if (list == null) { list = new CopyOnWriteArrayList<LockHolder>(); mapOfTempResources.put(parentKey, list); } list.add(r); } return r; }
From source file:com.l2jfree.gameserver.model.entity.events.TvT.java
public static void loadData() { _eventName = ""; _eventDesc = ""; _topTeam = ""; _joiningLocationName = ""; _teams = new CopyOnWriteArrayList<String>(); _savePlayers = new CopyOnWriteArrayList<String>(); _savePlayerTeams = new CopyOnWriteArrayList<String>(); _players = new CopyOnWriteArrayList<L2Player>(); _playersShuffle = new CopyOnWriteArrayList<L2Player>(); _teamPlayersCount = new CopyOnWriteArrayList<Integer>(); _teamKillsCount = new CopyOnWriteArrayList<Integer>(); _teamColors = new CopyOnWriteArrayList<Integer>(); _teamsX = new CopyOnWriteArrayList<Integer>(); _teamsY = new CopyOnWriteArrayList<Integer>(); _teamsZ = new CopyOnWriteArrayList<Integer>(); _joining = false;//from ww w. jav a 2 s .c o m _teleport = false; _started = false; _sitForced = false; _npcId = 0; _npcX = 0; _npcY = 0; _npcZ = 0; _npcHeading = 0; _rewardId = 0; _rewardAmount = 0; _topKills = 0; _minlvl = 0; _maxlvl = 0; _joinTime = 0; _eventTime = 0; _minPlayers = 0; _maxPlayers = 0; Connection con = null; try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("Select * from tvt"); rs = statement.executeQuery(); int teams = 0; while (rs.next()) { _eventName = rs.getString("eventName"); _eventDesc = rs.getString("eventDesc"); _joiningLocationName = rs.getString("joiningLocation"); _minlvl = rs.getInt("minlvl"); _maxlvl = rs.getInt("maxlvl"); _npcId = rs.getInt("npcId"); _npcX = rs.getInt("npcX"); _npcY = rs.getInt("npcY"); _npcZ = rs.getInt("npcZ"); _npcHeading = rs.getInt("npcHeading"); _rewardId = rs.getInt("rewardId"); _rewardAmount = rs.getInt("rewardAmount"); teams = rs.getInt("teamsCount"); _joinTime = rs.getInt("joinTime"); _eventTime = rs.getInt("eventTime"); _minPlayers = rs.getInt("minPlayers"); _maxPlayers = rs.getInt("maxPlayers"); } statement.close(); int index = -1; if (teams > 0) index = 0; while (index < teams && index > -1) { statement = con.prepareStatement("Select * from tvt_teams where teamId = ?"); statement.setInt(1, index); rs = statement.executeQuery(); while (rs.next()) { _teams.add(rs.getString("teamName")); _teamPlayersCount.add(0); _teamKillsCount.add(0); _teamColors.add(0); _teamsX.add(0); _teamsY.add(0); _teamsZ.add(0); _teamsX.set(index, rs.getInt("teamX")); _teamsY.set(index, rs.getInt("teamY")); _teamsZ.set(index, rs.getInt("teamZ")); _teamColors.set(index, rs.getInt("teamColor")); } index++; statement.close(); } } catch (Exception e) { _log.error("Exception: TvT.loadData(): ", e); } finally { L2DatabaseFactory.close(con); } }