List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList
public CopyOnWriteArrayList(E[] toCopyIn)
From source file:samples.websocket.jetty.snake.SnakeTimer.java
public static void broadcast(String message) throws Exception { Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); for (Snake snake : snakes) { try {// ww w .j av a2s .com snake.sendMessage(message); } catch (Throwable ex) { // if Snake#sendMessage fails the client is removed removeSnake(snake); } } }
From source file:net.cristcost.study.services.AnnotatedSecuredService.java
@Override @PostFilter("hasPermission(filterObject, 'please')") public List<String> serviceFive() { logger.info("serviceFive"); return new CopyOnWriteArrayList<>(Arrays.asList("one", "two", "three")); }
From source file:ijfx.ui.explorer.view.GroupExplorable.java
public void process() { List<Explorable> list1D = new CopyOnWriteArrayList<>(filterExplorableWithList(listItems, metaDataList)); sortListExplorable.setMetaData(metaDataList.get(0), metaDataList.get(1)); size = 0;//w ww.jav a 2 s.c o m list3D.clear(); SortExplorableUtils.sort(metaDataList.get(2), list1D); SortExplorableUtils.create2DList(metaDataList.get(2), list2D, list1D); list2D.stream().forEach((l2D) -> { sortListExplorable.setItems(l2D); sortListExplorable.process(); if (!sortListExplorable.getList2D().isEmpty()) { list3D.add(new CopyOnWriteArrayList<>(sortListExplorable.getList2D())); size = sortListExplorable.getSizeList2D() + size; } }); }
From source file:org.andstatus.app.account.AccountListFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.drag_list_layout, container, false); mDragListView = (DragListView) view.findViewById(R.id.drag_list_view); mDragListView.getRecyclerView().setVerticalScrollBarEnabled(true); mItems = new CopyOnWriteArrayList<>(MyContextHolder.get().persistentAccounts().list()); setupListRecyclerView();/* ww w . j a va 2s. c o m*/ return view; }
From source file:org.mariotaku.twidere.loader.support.Twitter4JActivitiesLoader.java
@Override public final List<ParcelableActivity> loadInBackground() { final File serializationFile = getSerializationFile(); if (mIsFirstLoad && mTabPosition >= 0 && serializationFile != null) { final List<ParcelableActivity> cached = getCachedData(serializationFile); if (cached != null) { Collections.sort(cached); return new CopyOnWriteArrayList<ParcelableActivity>(cached); }// w w w. j a v a 2 s.c o m } final SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); final List<Activity> activities; try { final Paging paging = new Paging(); paging.setCount(Math.min(100, loadItemLimit)); activities = getActivities(getTwitter(), paging); } catch (final TwitterException e) { e.printStackTrace(); final List<ParcelableActivity> cached = getCachedData(serializationFile); if (cached == null) return Collections.emptyList(); return new CopyOnWriteArrayList<ParcelableActivity>(cached); } if (activities == null) return new CopyOnWriteArrayList<ParcelableActivity>(mData); final List<ParcelableActivity> result = new ArrayList<ParcelableActivity>(); for (final Activity activity : activities) { result.add(new ParcelableActivity(activity, mAccountId)); } Collections.sort(result); saveCachedData(serializationFile, result); return new CopyOnWriteArrayList<ParcelableActivity>(result); }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAConnInstanceDAO.java
@Override public void delete(final String key) { ConnInstance connInstance = find(key); if (connInstance == null) { return;/*from w ww . ja v a 2 s. c o m*/ } IterableUtils.forEach(new CopyOnWriteArrayList<>(connInstance.getResources()), new Closure<ExternalResource>() { @Override public void execute(final ExternalResource input) { resourceDAO.delete(input.getKey()); } }); entityManager().remove(connInstance); connRegistry.unregisterConnector(key.toString()); }
From source file:ymanv.forex.websocket.RatesWebSocketHandler.java
@Subscribe public void send(RatesUpdatedEvent event) throws IOException { if (sessions.isEmpty()) { return;/* w ww .j ava 2s. c o m*/ } String txt = serializeRates(event.getRates()); for (WebSocketSession wss : new CopyOnWriteArrayList<>(sessions)) { wss.sendMessage(new TextMessage(txt)); } }
From source file:de.vanita5.twittnuker.loader.support.Twitter4JActivitiesLoader.java
@Override public final List<ParcelableActivity> loadInBackground() { if (mAccountIds == null) return Collections.emptyList(); final File serializationFile = getSerializationFile(); if (mIsFirstLoad && mUseCache && serializationFile != null) { final List<ParcelableActivity> cached = getCachedData(serializationFile); if (cached != null) { Collections.sort(cached); return new CopyOnWriteArrayList<ParcelableActivity>(cached); }//from w w w . j a v a 2 s . co m } final SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); final List<ParcelableActivity> result = new ArrayList<ParcelableActivity>(); for (final long accountId : mAccountIds) { final List<Activity> activities; try { final Paging paging = new Paging(); paging.setCount(Math.min(100, loadItemLimit)); activities = getActivities(getTwitter(accountId), paging); } catch (final TwitterException e) { e.printStackTrace(); final List<ParcelableActivity> cached = getCachedData(serializationFile); if (cached == null) return Collections.emptyList(); return new CopyOnWriteArrayList<ParcelableActivity>(cached); } if (activities == null) return new CopyOnWriteArrayList<ParcelableActivity>(mData); for (final Activity activity : activities) { result.add(new ParcelableActivity(activity, accountId)); } } Collections.sort(result); saveCachedData(serializationFile, result); return new CopyOnWriteArrayList<ParcelableActivity>(result); }
From source file:org.apache.hive.ptest.execution.HostExecutor.java
HostExecutor(Host host, String privateKey, ListeningExecutorService executor, SSHCommandExecutor sshCommandExecutor, RSyncCommandExecutor rsyncCommandExecutor, ImmutableMap<String, String> templateDefaults, File scratchDir, File succeededLogDir, File failedLogDir, long numPollSeconds, boolean fetchLogsForSuccessfulTests, Logger logger) { List<Drone> drones = Lists.newArrayList(); String[] localDirs = host.getLocalDirectories(); for (int index = 0; index < host.getThreads(); index++) { drones.add(new Drone(privateKey, host.getUser(), host.getName(), index, localDirs[index % localDirs.length])); }// w w w . j a va 2s . c o m mShutdown = false; mHost = host; mDrones = new CopyOnWriteArrayList<Drone>(drones); mExecutor = executor; mSSHCommandExecutor = sshCommandExecutor; mRSyncCommandExecutor = rsyncCommandExecutor; mTemplateDefaults = templateDefaults; mLocalScratchDirectory = scratchDir; mSuccessfulTestLogDir = succeededLogDir; mFailedTestLogDir = failedLogDir; mNumPollSeconds = numPollSeconds; this.fetchLogsForSuccessfulTests = fetchLogsForSuccessfulTests; mLogger = logger; }
From source file:org.dozer.propertydescriptor.PropertyDescriptorFactory.java
public DozerPropertyDescriptor getPropertyDescriptor(Class<?> clazz, String theGetMethod, String theSetMethod, String mapGetMethod, String mapSetMethod, boolean isAccessible, boolean isIndexed, int index, String name, String key, boolean isSelfReferencing, String oppositeFieldName, HintContainer srcDeepIndexHintContainer, HintContainer destDeepIndexHintContainer, String beanFactory, BeanContainer beanContainer, DestBeanCreator destBeanCreator) { DozerPropertyDescriptor desc = null; // Raw Map types or custom map-get-method/set specified boolean isMapProperty = MappingUtils.isSupportedMap(clazz); if (name.equals(DozerConstants.SELF_KEYWORD) && (mapSetMethod != null || mapGetMethod != null || isMapProperty)) { // If no mapSetMethod is defined, default to "put" String setMethod = StringUtils.isBlank(mapSetMethod) ? "put" : mapSetMethod; // If no mapGetMethod is defined, default to "get". String getMethod = StringUtils.isBlank(mapGetMethod) ? "get" : mapGetMethod; desc = new MapPropertyDescriptor(clazz, name, isIndexed, index, setMethod, getMethod, key != null ? key : oppositeFieldName, srcDeepIndexHintContainer, destDeepIndexHintContainer, beanContainer, destBeanCreator); // Copy by reference(Not mapped backed properties which also use 'this' // identifier for a different purpose) } else if (isSelfReferencing) { desc = new SelfPropertyDescriptor(clazz); // Access field directly and bypass getter/setters } else if (isAccessible) { desc = new FieldPropertyDescriptor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer, destBeanCreator); // Custom get-method/set specified } else if (theSetMethod != null || theGetMethod != null) { desc = new CustomGetSetPropertyDescriptor(clazz, name, isIndexed, index, theSetMethod, theGetMethod, srcDeepIndexHintContainer, destDeepIndexHintContainer, beanContainer, destBeanCreator); // If this object is an XML Bean - then use the XmlBeanPropertyDescriptor } else if (beanFactory != null && beanFactory.equals(DozerConstants.XML_BEAN_FACTORY)) { desc = new XmlBeanPropertyDescriptor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer, beanContainer, destBeanCreator); }// ww w . ja v a 2 s.co m if (desc != null) { return desc; } for (PropertyDescriptorCreationStrategy propertyDescriptorBuilder : new CopyOnWriteArrayList<PropertyDescriptorCreationStrategy>( pluggedDescriptorCreationStrategies)) { if (propertyDescriptorBuilder.isApplicable(clazz, name)) { desc = propertyDescriptorBuilder.buildFor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer); if (desc != null) { break; } } } if (desc == null) { // Everything else. It must be a normal bean with normal custom get/set methods desc = new JavaBeanPropertyDescriptor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer, beanContainer, destBeanCreator); } return desc; }