List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList
public CopyOnWriteArrayList(E[] toCopyIn)
From source file:org.apache.slider.providers.agent.AgentProviderService.java
/** Publish component instance specific data if the component demands it */ protected void processAndPublishComponentSpecificExports(Map<String, String> ports, String containerId, String hostFqdn, String compName) { String portVarFormat = "${site.%s}"; String hostNamePattern = "${" + compName + "_HOST}"; List<ExportGroup> appExportGroups = getMetainfo().getApplication().getExportGroups(); Component component = getMetainfo().getApplicationComponent(compName); if (component != null && SliderUtils.isSet(component.getCompExports()) && appExportGroups != null && appExportGroups.size() > 0) { Set<String> compExports = new HashSet(); String compExportsStr = component.getCompExports(); for (String compExport : compExportsStr.split(",")) { if (compExport.trim().length() > 0) { compExports.add(compExport.trim()); }/*from w w w. jav a 2 s . co m*/ } Date now = new Date(); Set<String> modifiedGroups = new HashSet<String>(); for (ExportGroup exportGroup : appExportGroups) { List<Export> exports = exportGroup.getExports(); if (exports != null && !exports.isEmpty()) { String exportGroupName = exportGroup.getName(); ConcurrentHashMap<String, List<ExportEntry>> map = (ConcurrentHashMap<String, List<ExportEntry>>) getCurrentExports( exportGroupName); for (Export export : exports) { if (canBeExported(exportGroupName, export.getName(), compExports)) { log.info("Attempting to publish {} of group {} for component type {}", export.getName(), exportGroupName, compName); String templateToExport = export.getValue(); for (String portName : ports.keySet()) { boolean publishData = false; String portValPattern = String.format(portVarFormat, portName); if (templateToExport.contains(portValPattern)) { templateToExport = templateToExport.replace(portValPattern, ports.get(portName)); publishData = true; } if (templateToExport.contains(hostNamePattern)) { templateToExport = templateToExport.replace(hostNamePattern, hostFqdn); publishData = true; } if (publishData) { ExportEntry entryToAdd = new ExportEntry(); entryToAdd.setLevel(COMPONENT_TAG); entryToAdd.setValue(templateToExport); entryToAdd.setUpdatedTime(now.toString()); entryToAdd.setContainerId(containerId); entryToAdd.setTag(tags.getTag(compName, containerId)); List<ExportEntry> existingList = map.putIfAbsent(export.getName(), new CopyOnWriteArrayList(Arrays.asList(entryToAdd))); // in-place edit, no lock needed if (existingList != null) { boolean updatedInPlace = false; for (ExportEntry entry : existingList) { if (containerId.equalsIgnoreCase(entry.getContainerId())) { entryToAdd.setValue(templateToExport); entryToAdd.setUpdatedTime(now.toString()); updatedInPlace = true; } } if (!updatedInPlace) { existingList.add(entryToAdd); } } log.info("Publishing {} for name {} and container {}", templateToExport, export.getName(), containerId); modifiedGroups.add(exportGroupName); synchronized (containerExportsMap) { if (!containerExportsMap.containsKey(containerId)) { containerExportsMap.put(containerId, new HashSet<String>()); } Set<String> containerExportMaps = containerExportsMap.get(containerId); containerExportMaps .add(String.format("%s:%s", exportGroupName, export.getName())); } } } } } } } publishModifiedExportGroups(modifiedGroups); } }
From source file:de.danoeh.antennapod.core.cast.CastManager.java
private void onQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) { Log.d(TAG, "onQueueUpdated() reached"); Log.d(TAG, String.format("Queue Items size: %d, Item: %s, Repeat Mode: %d, Shuffle: %s", queueItems == null ? 0 : queueItems.size(), item, repeatMode, shuffle)); if (queueItems != null) { mediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(queueItems), item, shuffle, repeatMode); } else {//from w ww .j a v a2 s. co m mediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(), null, false, MediaStatus.REPEAT_MODE_REPEAT_OFF); } for (CastConsumer consumer : castConsumers) { consumer.onMediaQueueUpdated(queueItems, item, repeatMode, shuffle); } }
From source file:net.countercraft.movecraft.async.AsyncManager.java
public void processFadingBlocks() { if (Settings.FadeWrecksAfter == 0) return;/*from ww w.j a v a 2 s.c o m*/ long ticksElapsed = (System.currentTimeMillis() - lastFadeCheck) / 50; if (ticksElapsed > 20) { for (World w : Bukkit.getWorlds()) { if (w != null) { ArrayList<MapUpdateCommand> updateCommands = new ArrayList<MapUpdateCommand>(); CopyOnWriteArrayList<MovecraftLocation> locations = null; // I know this is horrible, but I honestly don't see another // way to do this... int numTries = 0; while ((locations == null) && (numTries < 100)) { try { locations = new CopyOnWriteArrayList<MovecraftLocation>( Movecraft.getInstance().blockFadeTimeMap.keySet()); } catch (java.util.ConcurrentModificationException e) { numTries++; } catch (java.lang.NegativeArraySizeException e) { Movecraft.getInstance().blockFadeTimeMap = new HashMap<MovecraftLocation, Long>(); Movecraft.getInstance().blockFadeTypeMap = new HashMap<MovecraftLocation, Integer>(); Movecraft.getInstance().blockFadeWaterMap = new HashMap<MovecraftLocation, Boolean>(); Movecraft.getInstance().blockFadeWorldMap = new HashMap<MovecraftLocation, World>(); locations = new CopyOnWriteArrayList<MovecraftLocation>( Movecraft.getInstance().blockFadeTimeMap.keySet()); } } for (MovecraftLocation loc : locations) { if (Movecraft.getInstance().blockFadeWorldMap.get(loc) == w) { Long time = Movecraft.getInstance().blockFadeTimeMap.get(loc); Integer type = Movecraft.getInstance().blockFadeTypeMap.get(loc); Boolean water = Movecraft.getInstance().blockFadeWaterMap.get(loc); if (time != null && type != null && water != null) { long secsElapsed = (System.currentTimeMillis() - Movecraft.getInstance().blockFadeTimeMap.get(loc)) / 1000; // has enough time passed to fade the block? boolean timeElapsed = false; // make containers take longer to fade so their loot can be recovered if (w.getBlockTypeIdAt(loc.getX(), loc.getY(), loc.getZ()) == 54) { timeElapsed = secsElapsed > Settings.FadeWrecksAfter * 5; } else if (w.getBlockTypeIdAt(loc.getX(), loc.getY(), loc.getZ()) == 146) { timeElapsed = secsElapsed > Settings.FadeWrecksAfter * 5; } else if (w.getBlockTypeIdAt(loc.getX(), loc.getY(), loc.getZ()) == 158) { timeElapsed = secsElapsed > Settings.FadeWrecksAfter * 5; } else if (w.getBlockTypeIdAt(loc.getX(), loc.getY(), loc.getZ()) == 23) { timeElapsed = secsElapsed > Settings.FadeWrecksAfter * 5; } else { timeElapsed = secsElapsed > Settings.FadeWrecksAfter; } if (timeElapsed) { // load the chunk if it hasn't been already int cx = loc.getX() >> 4; int cz = loc.getZ() >> 4; if (w.isChunkLoaded(cx, cz) == false) { w.loadChunk(cx, cz); } // check to see if the block type has // changed, if so don't fade it if (w.getBlockTypeIdAt(loc.getX(), loc.getY(), loc.getZ()) == Movecraft.getInstance().blockFadeTypeMap.get(loc)) { // should it become water? if not, then // air if (Movecraft.getInstance().blockFadeWaterMap.get(loc) == true) { MapUpdateCommand updateCom = new MapUpdateCommand(loc, 9, (byte) 0, null); updateCommands.add(updateCom); } else { MapUpdateCommand updateCom = new MapUpdateCommand(loc, 0, (byte) 0, null); updateCommands.add(updateCom); } } Movecraft.getInstance().blockFadeTimeMap.remove(loc); Movecraft.getInstance().blockFadeTypeMap.remove(loc); Movecraft.getInstance().blockFadeWorldMap.remove(loc); Movecraft.getInstance().blockFadeWaterMap.remove(loc); } } } } if (updateCommands.size() > 0) { MapUpdateManager.getInstance().addWorldUpdate(w, updateCommands.toArray(new MapUpdateCommand[1]), null, null); } } } lastFadeCheck = System.currentTimeMillis(); } }
From source file:com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.java
private void onQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) { LOGD(TAG, "onQueueUpdated() reached"); LOGD(TAG, String.format("Queue Items size: %d, Item: %s, Repeat Mode: %d, Shuffle: %s", queueItems == null ? 0 : queueItems.size(), item, repeatMode, shuffle)); if (queueItems != null) { mMediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(queueItems), item, shuffle, repeatMode); } else {//from w w w.j av a2 s. co m mMediaQueue = new MediaQueue(new CopyOnWriteArrayList<MediaQueueItem>(), null, false, MediaStatus.REPEAT_MODE_REPEAT_OFF); } for (VideoCastConsumer consumer : mVideoConsumers) { consumer.onMediaQueueUpdated(queueItems, item, repeatMode, shuffle); } }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIComponent.java
/*********************************************************************************************** * Notify all listeners of DatasetChangedEvents. * * @param eventsource/* w w w . j a v a 2s . c om*/ * @param seriescount * @param itemcount0 */ public final void notifyDatasetChangedEvent(final Object eventsource, final int seriescount, final int itemcount0) { List<DatasetChangedListener> listeners; final DatasetChangedEvent changeEvent; // Create a Thread-safe List of Listeners listeners = new CopyOnWriteArrayList<DatasetChangedListener>(getDatasetChangedListeners()); // Create an DatasetChangedEvent changeEvent = new DatasetChangedEvent(eventsource, seriescount, itemcount0); // Fire the event to every listener synchronized (listeners) { for (int i = 0; i < listeners.size(); i++) { final DatasetChangedListener changeListener; changeListener = listeners.get(i); changeListener.datasetChanged(changeEvent); } } // Help the GC? listeners = null; }