List of usage examples for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet
public ConcurrentSkipListSet()
From source file:org.apdplat.superword.extract.ChineseSynonymAntonymExtractor.java
public static void parseSynonymAntonym(List<String> words) { LOGGER.info("??" + words.size()); Set<String> SKIP_WORDS = new ConcurrentSkipListSet<>(); try {/*from w ww .ja va2 s . co m*/ if (Files.notExists(CHECKED_WORDS_PATH)) { CHECKED_WORDS_PATH.toFile().createNewFile(); } SKIP_WORDS.addAll(Files.readAllLines(CHECKED_WORDS_PATH)); } catch (Exception e) { LOGGER.error("?", e); } int total = words.size() - SKIP_WORDS.size(); LOGGER.info("????" + SKIP_WORDS.size()); LOGGER.info("??" + total); String url = "http://www.iciba.com/"; AtomicInteger i = new AtomicInteger(); EXECUTOR_SERVICE.submit(() -> { while (true) { try { Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); } save(); } }); words.parallelStream().forEach(word -> { if (SKIP_WORDS.contains(word)) { return; } LOGGER.info( "" + total + "/" + i.incrementAndGet() + " ?" + Thread.currentThread()); try { word = word.trim(); if ("".equals(word) || isNotChineseChar(word) || word.length() < 2) { return; } String html = getContent(url + word); int times = 1; while (StringUtils.isBlank(html) && times < 3) { times++; //IP? ProxyIp.toNewIp(); html = getContent(url + word); } if (StringUtils.isBlank(html)) { LOGGER.error("??" + url + word); return; } times = 1; //LOGGER.debug("?HTML" +html); while (html.contains("??ip?") && times < 3) { times++; //IP? ProxyIp.toNewIp(); html = getContent(url + word); } SynonymAntonym synonymAntonym = parseSynonymAntonym(html, word); if (!synonymAntonym.getSynonym().isEmpty()) { SYNONYM_MAP.put(synonymAntonym.getWord(), synonymAntonym.getSynonym()); } if (!synonymAntonym.getAntonym().isEmpty()) { StringBuilder str = new StringBuilder(); synonymAntonym.getAntonym().forEach(w -> str.append(w.getWord()).append(" ")); ANTONYM.put(word, str.toString().trim()); } CHECKED_WORDS.add(word); } catch (Exception e) { LOGGER.error("", e); } }); save(); filterSameRecord(CHINESE_SYNONYM); filterSameRecord(CHINESE_ANTONYM); }
From source file:org.apache.qpid.server.security.group.FileGroupDatabase.java
private synchronized void readGroupFile(String groupFile) throws IOException { _groupFile = groupFile;/*from w w w.j a va 2s . c om*/ _groupToUserMap.clear(); _userToGroupMap.clear(); Properties propertiesFile = new Properties(); FileInputStream fileInputStream = new FileInputStream(groupFile); try { propertiesFile.load(fileInputStream); } finally { if (fileInputStream != null) { fileInputStream.close(); } } for (String propertyName : propertiesFile.stringPropertyNames()) { validatePropertyNameIsGroupName(propertyName); String groupName = propertyName.replaceAll("\\.users$", ""); String userString = propertiesFile.getProperty(propertyName); final Set<String> userSet = buildUserSetFromCommaSeparateValue(userString); _groupToUserMap.put(groupName, userSet); for (String userName : userSet) { Set<String> groupsForThisUser = _userToGroupMap.get(userName); if (groupsForThisUser == null) { groupsForThisUser = new ConcurrentSkipListSet<String>(); _userToGroupMap.put(userName, groupsForThisUser); } groupsForThisUser.add(groupName); } } }
From source file:io.hops.ha.common.RMNodeInfo.java
public void toRemoveNodeUpdateQueue( org.apache.hadoop.yarn.server.resourcemanager.rmnode.UpdatedContainerInfo uci) { if (this.nodeUpdateQueueToRemove == null) { this.nodeUpdateQueueToRemove = new ConcurrentSkipListSet<org.apache.hadoop.yarn.server.resourcemanager.rmnode.UpdatedContainerInfo>(); }/* ww w . j a v a 2 s . c o m*/ this.nodeUpdateQueueToRemove.add(uci); }
From source file:io.hops.ha.common.RMNodeInfo.java
public void toRemoveNodeUpdateQueue( ConcurrentLinkedQueue<org.apache.hadoop.yarn.server.resourcemanager.rmnode.UpdatedContainerInfo> uci) { if (this.nodeUpdateQueueToRemove == null) { this.nodeUpdateQueueToRemove = new ConcurrentSkipListSet<org.apache.hadoop.yarn.server.resourcemanager.rmnode.UpdatedContainerInfo>(); }//from w w w .j av a 2 s. c o m this.nodeUpdateQueueToRemove.addAll(uci); }
From source file:org.springframework.kafka.listener.ConcurrentMessageListenerContainerTests.java
@Test public void testAutoCommitWithRebalanceListener() throws Exception { this.logger.info("Start auto"); Map<String, Object> props = KafkaTestUtils.consumerProps("test10", "true", embeddedKafka); DefaultKafkaConsumerFactory<Integer, String> cf = new DefaultKafkaConsumerFactory<>(props); ContainerProperties containerProps = new ContainerProperties(topic1); final CountDownLatch latch = new CountDownLatch(4); final Set<String> listenerThreadNames = new ConcurrentSkipListSet<>(); containerProps.setMessageListener((MessageListener<Integer, String>) message -> { ConcurrentMessageListenerContainerTests.this.logger.info("auto: " + message); listenerThreadNames.add(Thread.currentThread().getName()); latch.countDown();// www . j a v a 2s. c om }); final CountDownLatch rebalancePartitionsAssignedLatch = new CountDownLatch(2); final CountDownLatch rebalancePartitionsRevokedLatch = new CountDownLatch(2); containerProps.setConsumerRebalanceListener(new ConsumerRebalanceListener() { @Override public void onPartitionsRevoked(Collection<TopicPartition> partitions) { ConcurrentMessageListenerContainerTests.this.logger .info("In test, partitions revoked:" + partitions); rebalancePartitionsRevokedLatch.countDown(); } @Override public void onPartitionsAssigned(Collection<TopicPartition> partitions) { ConcurrentMessageListenerContainerTests.this.logger .info("In test, partitions assigned:" + partitions); rebalancePartitionsAssignedLatch.countDown(); } }); ConcurrentMessageListenerContainer<Integer, String> container = new ConcurrentMessageListenerContainer<>(cf, containerProps); container.setConcurrency(2); container.setBeanName("testAuto"); container.start(); ContainerTestUtils.waitForAssignment(container, embeddedKafka.getPartitionsPerTopic()); Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka); ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<>(senderProps); KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf); template.setDefaultTopic(topic1); template.sendDefault(0, "foo"); template.sendDefault(2, "bar"); template.sendDefault(0, "baz"); template.sendDefault(2, "qux"); template.flush(); assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue(); assertThat(rebalancePartitionsAssignedLatch.await(60, TimeUnit.SECONDS)).isTrue(); assertThat(rebalancePartitionsRevokedLatch.await(60, TimeUnit.SECONDS)).isTrue(); assertThat(listenerThreadNames).allMatch(threadName -> threadName.contains("-consumer-")); container.stop(); this.logger.info("Stop auto"); }
From source file:gemlite.core.internal.view.GemliteViewContext.java
private void registerRegionToView(String regionName, String viewName) { if (StringUtils.isEmpty(regionName)) return;//from w ww .j a va 2 s . c o m Set<String> viewSet = regionToView.get(regionName); if (viewSet == null) { viewSet = new ConcurrentSkipListSet<String>(); viewSet.add(viewName); regionToView.put(regionName, viewSet); } else { if (!viewSet.contains(viewName)) viewSet.add(viewName); } }
From source file:org.opennms.features.newts.converter.rrd.converter.JRobinConverter.java
public void execute(final String[] args) throws ParseException, ConverterException, RrdException { if (args.length == 0) { LogUtils.errorf(this, "no files or directories specified!"); System.exit(1);/*from www .jav a 2 s. c om*/ } final Options options = new Options(); options.addOption("h", "help", false, "This help."); options.addOption("f", "factory", true, "The JRobin factory to use. (Default: " + DEFAULT_JROBIN_FACTORY + ")"); options.addOption("l", "log", true, "The log level to use. (Default: " + DEFAULT_LOG_LEVEL + ")"); options.addOption("t", "threads", true, "Number of threads to start. (Default: " + DEFAULT_NUMBER_OF_THREADS + ")"); options.addOption("c", "clean", false, "Remove old single-metric JRBs and temporal files. (Use it only after migrating all your files)"); options.addOption("v", "validate", false, "Validate current JRBs ffiles."); final CommandLineParser parser = new GnuParser(); final CommandLine cmd = parser.parse(options, args); LogUtils.setLevel(Level.valueOf(cmd.getOptionValue("l", DEFAULT_LOG_LEVEL))); RrdBackendFactory.setDefaultFactory(cmd.getOptionValue("f", DEFAULT_JROBIN_FACTORY)); final Set<File> rrds = new ConcurrentSkipListSet<File>(); if (cmd.hasOption("h")) { new HelpFormatter().printHelp("jrobin-converter [options] [file-or-directory1] [...file-or-directoryN]", options); System.exit(1); } if (cmd.getArgList().size() == 0) { LogUtils.infof(this, "No files or directories specified! Exiting."); System.exit(0); } if (cmd.hasOption("c")) { new RrdCleaner().execute(cmd); System.exit(1); } if (cmd.hasOption("v")) { new RrdValidator().execute(cmd); System.exit(1); } int threads = DEFAULT_NUMBER_OF_THREADS; if (cmd.hasOption("t")) { try { threads = Integer.valueOf(cmd.getOptionValue("t")); } catch (final NumberFormatException e) { LogUtils.warnf(JRobinConverter.class, e, "failed to format -t %s to a number", cmd.getOptionValue("t")); } } final ExecutorService executor = Executors.newFixedThreadPool(threads); for (final Object arg : cmd.getArgList()) { LogUtils.infof(this, "Scanning %s for storeByGroup data.", arg); final File f = new File((String) arg); if (f.exists()) { if (f.isDirectory()) { rrds.addAll(findGroupRrds(f)); for (final File rrdFile : findGroupRrds(f)) { consolidateRrd(executor, rrdFile); } } else { consolidateRrd(executor, f); } } } LogUtils.infof(this, "Finished scanning for storeByGroup RRDs. (Total RRD count: %d)", m_total.get()); executor.shutdown(); }
From source file:org.apache.qpid.server.security.group.FileGroupDatabase.java
private ConcurrentSkipListSet<String> buildUserSetFromCommaSeparateValue(String userString) { String[] users = userString.split(","); final ConcurrentSkipListSet<String> userSet = new ConcurrentSkipListSet<String>(); for (String user : users) { final String trimmed = user.trim(); if (!trimmed.isEmpty()) { userSet.add(trimmed);/*from w w w . j a v a2 s .co m*/ } } return userSet; }
From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java
public CertificateMaterializer() { materializedCerts = new HashMap<>(); materialCache = new HashMap<>(); fileRemovers = new HashMap<>(); projectsWithOpenInterpreters = new ConcurrentSkipListSet<>(); }
From source file:net.cellcloud.talk.TalkService.java
/** * ???/* w ww. ja va 2 s.c o m*/ * @return ?? true? false */ @Override public boolean startup() { if (null == this.unidentifiedSessions) { this.unidentifiedSessions = new ConcurrentHashMap<Long, Certificate>(); } if (null == this.sessionTagMap) { this.sessionTagMap = new ConcurrentHashMap<Long, String>(); } if (null == this.tagContexts) { this.tagContexts = new ConcurrentHashMap<String, TalkSessionContext>(); } if (null == this.suspendedTrackers) { this.suspendedTrackers = new ConcurrentHashMap<String, SuspendedTracker>(); } if (null == this.tagList) { this.tagList = new ConcurrentSkipListSet<String>(); } if (null == this.acceptor) { // ? this.acceptor = new NonblockingAcceptor(); this.acceptor.setBlockSize(this.block); // byte[] head = { 0x20, 0x10, 0x11, 0x10 }; byte[] tail = { 0x19, 0x78, 0x10, 0x04 }; this.acceptor.defineDataMark(head, tail); // ? this.talkHandler = new TalkAcceptorHandler(this); this.acceptor.setHandler(this.talkHandler); } // this.acceptor.setMaxConnectNum(this.maxConnections); boolean succeeded = this.acceptor.bind(this.port); if (succeeded) { startDaemon(); } if (succeeded && this.httpEnabled) { // ? HTTP ? startHttpService(); } return succeeded; }