List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList
public CopyOnWriteArrayList()
From source file:de.digiway.rapidbreeze.server.model.download.DownloadManager.java
public DownloadManager(DownloadRepository downloadRepository, StorageProviderRepository storageProviderRepository, ServerConfiguration applicationConfiguration) { this.downloadRepository = downloadRepository; this.storageProviderRepository = storageProviderRepository; this.applicationConfiguration = applicationConfiguration; this.downloadTargetFolder = applicationConfiguration.getDownloadTargetFolder(); this.listeners = new CopyOnWriteArrayList<>(); this.downloadCacheIdentifiers = new HashMap<>(); this.downloadCache = new ArrayList<>(); this.listenerHandler = new DownloadListenerHandler(); this.actionExecutor = new DownloadManagerActionExecutor(); this.actionExecutor.start(); this.throttleSupport = new ThrottleSupport(this); for (Download download : downloadRepository.getDownloads()) { downloadCacheIdentifiers.put(download.getIdentifier(), download); downloadCache.add(download);//w w w .j ava 2 s . c o m download.addListener(listenerHandler); } checkTargetFolder(); threadExecutor.execute(new DownloadHandlingThread()); }
From source file:org.eclipse.ecr.core.storage.sql.RepositoryImpl.java
public RepositoryImpl(RepositoryDescriptor repositoryDescriptor) throws StorageException { this.repositoryDescriptor = repositoryDescriptor; sessions = new CopyOnWriteArrayList<SessionImpl>(); cachePropagator = new InvalidationsPropagator(); eventPropagator = new InvalidationsPropagator(); repositoryEventQueue = new InvalidationsQueue("repo-" + repositoryDescriptor.name); try {/*from w w w . jav a 2s . c o m*/ schemaManager = Framework.getService(SchemaManager.class); } catch (Exception e) { throw new StorageException(e); } try { eventService = Framework.getService(EventService.class); } catch (Exception e) { throw new StorageException(e); } connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setDefaultMaxConnectionsPerHost(20); params.setMaxTotalConnections(20); httpClient = new HttpClient(connectionManager); binaryManager = createBinaryManager(); backend = createBackend(); createServer(); }
From source file:io.github.minecraftgui.models.network.UserConnection.java
public void addOnGuiCloseListener(OnGuiListener plugin, OnGuiListener.OnGuiClose onGuiClose) { CopyOnWriteArrayList<OnGuiListener.OnGuiClose> onGuiCloses = onGuiCloseListeners.get(plugin); if (onGuiCloses == null) { onGuiCloses = new CopyOnWriteArrayList<>(); onGuiCloseListeners.put(plugin, onGuiCloses); }//from ww w . ja va 2 s . c om onGuiCloses.add(onGuiClose); }
From source file:org.nuxeo.ecm.core.storage.sql.RepositoryImpl.java
public RepositoryImpl(RepositoryDescriptor repositoryDescriptor) throws StorageException { this.repositoryDescriptor = repositoryDescriptor; sessions = new CopyOnWriteArrayList<SessionImpl>(); cachePropagator = new InvalidationsPropagator("cache-" + this); eventPropagator = new InvalidationsPropagator("event-" + this); repositoryEventQueue = new InvalidationsQueue("repo-" + repositoryDescriptor.name); try {/*ww w .j a va 2 s . co m*/ eventService = Framework.getService(EventService.class); } catch (Exception e) { throw new StorageException(e); } String className = repositoryDescriptor.fulltextParser; if (StringUtils.isBlank(className)) { className = DefaultFulltextParser.class.getName(); } Class<?> klass; try { klass = Thread.currentThread().getContextClassLoader().loadClass(className); } catch (ClassNotFoundException e) { throw new StorageException("Unknown fulltext parser class: " + className, e); } if (!FulltextParser.class.isAssignableFrom(klass)) { throw new StorageException("Invalid fulltext parser class: " + className); } fulltextParserClass = (Class<? extends FulltextParser>) klass; binaryManager = createBinaryManager(); backend = createBackend(); repositoryUp = registry .counter(MetricRegistry.name("nuxeo", "repositories", repositoryDescriptor.name, "instance-up")); repositoryUp.inc(); sessionCount = registry .counter(MetricRegistry.name("nuxeo", "repositories", repositoryDescriptor.name, "sessions")); createMetricsGauges(); }
From source file:org.examproject.task.core.Facade.java
@Override public void run() { LOG.debug("called."); try {//from w w w . j a va2s.c om LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> facade begin."); LOG.info("processing at " + new Date()); StopWatch stopWatch = new StopWatch(); stopWatch.start(); // initialize the content object for this run. init(); // set the param for the worker object of the list. List<Runnable> workerList = new CopyOnWriteArrayList<Runnable>(); for (int i = 0; i < contentList.size(); i++) { // create the beans of result for the worker. DynaBean result = (DynaBean) resultBeanFactory.create(); // create the beans of state for the worker. DynaBean state = (DynaBean) stateBeanFactory.create(); // create the beans of argument for the worker. DynaBean argument = (DynaBean) argumentBeanFactory.create(); // build the parameter for the worker. state.set("result", result); state.set("param", getParam()); argument.set("job", jobClosure); argument.set("state", state); argument.set("count", counter.incrementAndGet()); // set the argument object for the worker. Runnable worker = (Runnable) context.getBean(workerBeanId, argument); // add the worker to the list. workerList.add(worker); } // run the all of the worker object. for (int i = 0; i < workerList.size(); i++) { executor.execute(workerList.get(i)); } stopWatch.stop(); LOG.info("execute time: " + stopWatch.getTime() + " msec"); LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade end."); } catch (Exception e) { LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade error."); LOG.error("exception occurred. " + e.getMessage()); // TODO: final strategy of the error! throw new RuntimeException(e); } }
From source file:org.hawkular.listener.cache.InventoryHelperTest.java
@Test public void shouldListTenantsForFeed() { // Data & mocks when(metricsService.getTenants())//from w w w . j a va 2 s . c o m .thenReturn(Observable.just(new Tenant("t1"), new Tenant("t2"), new Tenant("t3"))); when(metricsService.findMetricsWithFilters(anyString(), anyObject(), anyString())) .thenAnswer(invocationOnMock -> { String tenantId = invocationOnMock.getArgumentAt(0, String.class); switch (tenantId) { case "t1": return Observable.just(new Metric<>("metric1", null, 7, MetricType.STRING, null)); case "t3": return Observable.just(new Metric<>("metric2", null, 7, MetricType.STRING, null), new Metric<>("metric3", null, 7, MetricType.STRING, null)); default: return Observable.empty(); } }); // Test & assertions List<String> collectedTenants = new CopyOnWriteArrayList<>(); InventoryHelper.listTenantsForFeed(metricsService, "some_feed").toList() .subscribe(tenants -> tenants.forEach(t -> collectedTenants.add(t.getId())), Throwables::propagate); Assert.assertEquals(2, collectedTenants.size()); Assert.assertEquals("t1", collectedTenants.get(0)); Assert.assertEquals("t3", collectedTenants.get(1)); }
From source file:org.tinymediamanager.core.tvshow.TvShowList.java
/** * Instantiates a new TvShowList./* w w w. j a v a 2 s . c om*/ */ private TvShowList() { // create the lists tvShowTagsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); episodeTagsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); videoCodecsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); audioCodecsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); // the tag listener: its used to always have a full list of all tags used in tmm propertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { // listen to changes of tags if ("tag".equals(evt.getPropertyName()) && evt.getSource() instanceof TvShow) { TvShow tvShow = (TvShow) evt.getSource(); updateTvShowTags(tvShow); } if ("tag".equals(evt.getPropertyName()) && evt.getSource() instanceof TvShowEpisode) { TvShowEpisode episode = (TvShowEpisode) evt.getSource(); updateEpisodeTags(episode); } if ((MEDIA_FILES.equals(evt.getPropertyName()) || MEDIA_INFORMATION.equals(evt.getPropertyName())) && evt.getSource() instanceof TvShowEpisode) { TvShowEpisode episode = (TvShowEpisode) evt.getSource(); updateMediaInformationLists(episode); } if (EPISODE_COUNT.equals(evt.getPropertyName())) { firePropertyChange(EPISODE_COUNT, 0, 1); } } }; }
From source file:com.taobao.pushit.client.PushitClient.java
/** * Pushit/* w w w.j av a 2 s . com*/ * * @param servers * "host:port host:port..." * @param notifyListener * * @param connectTimeoutInMills * * @throws IOException * * @throws InterruptedException * */ public PushitClient(String servers, NotifyListener notifyListener, long connectTimeoutInMills) throws IOException, InterruptedException { super(); this.notifyListener = notifyListener; if (connectTimeoutInMills <= 0) { throw new IllegalArgumentException("connectTimeoutInMills must be great than zero"); } clientInterests = new CopyOnWriteArrayList<ClientInterest>(); initRemotingClient(connectTimeoutInMills); connect(servers); }
From source file:org.apache.stratos.autoscaler.TestObsoletedMemberRule.java
@Test public void testMoreThanOneObsoletedMemberCase() { // reset helper class TestDelegator.setObsoletedMembers(new ArrayList<String>()); if (kbase == null) { throw new IllegalArgumentException("Knowledge base is null."); }/*from w ww . j a va 2s. co m*/ ksession = kbase.newStatefulKnowledgeSession(); PartitionContext p = new PartitionContext(conf.getLong("autoscaler.member.expiryTimeout", 900000)); p.setObsoletedMembers(new CopyOnWriteArrayList<String>()); String memberId1 = "member1"; String memberId2 = "member2"; String memberId3 = "member3"; p.addObsoleteMember(memberId1); p.addObsoleteMember(memberId2); FactHandle handle = ksession.insert(p); ksession.fireAllRules(); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertEquals(2, TestDelegator.getObsoletedMembers().size()); assertEquals(0, p.getObsoletedMembers().size()); assertNotEquals(TestDelegator.getObsoletedMembers().get(0), TestDelegator.getObsoletedMembers().get(1)); boolean check0thPosition = memberId1.equals(TestDelegator.getObsoletedMembers().get(0)) || memberId2.equals(TestDelegator.getObsoletedMembers().get(0)); assertEquals(true, check0thPosition); boolean check1stPosition = memberId1.equals(TestDelegator.getObsoletedMembers().get(1)) || memberId2.equals(TestDelegator.getObsoletedMembers().get(2)); assertEquals(true, check1stPosition); // reset helper class TestDelegator.setObsoletedMembers(new ArrayList<String>()); p.addObsoleteMember(memberId3); ksession.update(handle, p); ksession.fireAllRules(); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertEquals(1, TestDelegator.getObsoletedMembers().size()); assertEquals(memberId3, TestDelegator.getObsoletedMembers().get(0)); }
From source file:com.bigdata.rdf.sparql.ast.service.ServiceRegistry.java
protected ServiceRegistry() { services = new ConcurrentHashMap<URI, ServiceFactory>(); customServices = new CopyOnWriteArrayList<CustomServiceFactory>(); aliases = new ConcurrentHashMap<URI, URI>(); defaultServiceFactoryRef = new AtomicReference<ServiceFactory>( new RemoteServiceFactoryImpl(SPARQLVersion.SPARQL_11)); // Add the Bigdata search service. add(BDS.SEARCH, new SearchServiceFactory()); // Add the Geospatial search service. add(GeoSpatial.SEARCH, new GeoSpatialServiceFactory()); // Add the external Solr search service add(FTS.SEARCH, new FulltextSearchServiceFactory()); // Add the Bigdata search in search service. add(BDS.SEARCH_IN_SEARCH, new SearchInSearchServiceFactory()); // Add the sample index service. add(SampleServiceFactory.SERVICE_KEY, new SampleServiceFactory()); // Add the slice index service. add(SliceServiceFactory.SERVICE_KEY, new SliceServiceFactory()); // Add the values service. add(ValuesServiceFactory.SERVICE_KEY, new ValuesServiceFactory()); if (QueryHints.DEFAULT_DESCRIBE_CACHE) { add(new URIImpl(BD.NAMESPACE + "describe"), new DescribeServiceFactory()); }//w w w .j a v a 2 s . c o m if (true) { /** * @see <a * href="https://sourceforge.net/apps/trac/bigdata/ticket/607"> * HISTORY SERVICE </a> */ add(new URIImpl(BD.NAMESPACE + "history"), new HistoryServiceFactory()); /** * Replacing with a history service using RDR instead of a custom * index. */ add(new URIImpl(BD.NAMESPACE + "rdrhistory"), new RDRHistoryServiceFactory()); } // The Gather-Apply-Scatter RDF Graph Mining service. add(GASService.Options.SERVICE_KEY, new GASService()); }