List of usage examples for java.util Collections synchronizedSortedSet
public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
From source file:Main.java
public static void main(String[] args) { // create set SortedSet<String> set = new TreeSet<String>(); // populate the set set.add("from"); set.add("java2s.com"); set.add("tutorial"); set.add("java"); // create a synchronized sorted set SortedSet<String> sorset = Collections.synchronizedSortedSet(set); System.out.println("Sorted set is :" + sorset); }
From source file:Main.java
public static Collection narrowSynchronizedCollection(Collection c) { if (c instanceof SortedSet) return Collections.synchronizedSortedSet((SortedSet) c); else if (c instanceof Set) return Collections.synchronizedSet((Set) c); else if (c instanceof List) return Collections.synchronizedList((List) c); else//from www . j av a2 s .c o m return Collections.synchronizedCollection(c); }
From source file:com.juhnowski.sanskrvar.Main.java
public Main() { this.sl = new TreeSet<>(); searchList = Collections.synchronizedSortedSet(new TreeSet(sl)); this.ts = new TreeSet<>(); entrySet = Collections.synchronizedSortedSet(new TreeSet(ts)); }
From source file:simMPLS.scenario.TLink.java
/** * Este mtodo es el constructor de la clase. Crea una nueva instancia de * TEnlaceTopologia./* w w w. j a va2 s .com*/ * @param identificador Identificador nico del enlace. * @param il Generador de identificadores para los eventos emitidos por el enlace. * @param t Topologa a la que pertenece el enlace. * @since 1.0 */ public TLink(int identificador, TLongIDGenerator il, TTopology t) { super(TTopologyElement.LINK, il); id = identificador; extremo1 = null; extremo2 = null; mostrarNombre = false; nombre = ""; delay = 1; puertoExtremo1 = -1; puertoExtremo2 = -1; buffer = Collections.synchronizedSortedSet(new TreeSet()); bufferLlegadosADestino = new TreeSet(); cerrojo = new TMonitor(); cerrojoLlegados = new TMonitor(); topologia = t; enlaceCaido = false; }
From source file:kmi.taa.core.Crawler.java
public void crawlAll(TreeMap<Integer, String> targetUrls, String service, String proxy, String otfile) { SortedSet<Integer> results = Collections.synchronizedSortedSet(new TreeSet<Integer>()); ExecutorService pool = Executors.newFixedThreadPool(100); int howManyUrls = targetUrls.size(); System.out.println("total " + howManyUrls + " to be processed"); List<String> output = Collections.synchronizedList(new ArrayList<String>()); for (Integer targetId : targetUrls.navigableKeySet()) { String uri = targetUrls.get(targetId); pool.execute(new Explorer(targetId, uri, service, proxy, results, otfile, output)); }/*from www. ja v a 2s .co m*/ pool.shutdown(); while (results.size() < howManyUrls) { System.out.println("already processed " + results.size() + " subject links"); try { Thread.sleep(1000); } catch (InterruptedException e) { log.error("crawlAll error", e); } } resultToFile(output, otfile); System.out.println("already processed " + results.size() + " subject links"); }
From source file:edu.scripps.fl.pubchem.app.AssayDownloader.java
public void process(Collection<Long> aids) throws Exception { log.info(String.format("Processing %s AIDs", aids.size())); Set<Long> processAids = Collections.synchronizedSortedSet(new TreeSet<Long>(aids)); List<Pipeline> pipelines = new ArrayList(); pipelines.add(assayXML(processAids)); pipelines.add(assaySummaries(getAIDsfromLocalDB())); for (Pipeline pipeline : pipelines) new PipelineUtils().logErrors(pipeline); System.exit(0);//from w w w .j a v a 2 s .c o m }
From source file:com.inmobi.conduit.distcp.DistcpBaseService.java
@Override protected void prepareStreamHcatEnableMap() { Map<String, DestinationStream> destStreamMap = destCluster.getDestinationStreams(); for (String stream : streamsToProcess) { if (destStreamMap.containsKey(stream) && destStreamMap.get(stream).isHCatEnabled()) { updateStreamHCatEnabledMap(stream, true); Set<Path> paths = Collections.synchronizedSortedSet(new TreeSet<Path>()); pathsToBeregisteredPerTable.put(getTableName(stream), paths); } else {/*from w ww . jav a2 s .c o m*/ updateStreamHCatEnabledMap(stream, false); } } }
From source file:com.cyberway.issue.crawler.frontier.BdbFrontier.java
@Override protected void initQueuesOfQueues() { if (this.controller.isCheckpointRecover()) { // do not setup here; take/init from deserialized frontier return;/* www . j av a 2 s.c om*/ } // small risk of OutOfMemoryError: if 'hold-queues' is false, // readyClassQueues may grow in size without bound readyClassQueues = new LinkedBlockingQueue<String>(); try { Database inactiveQueuesDb = this.controller.getBdbEnvironment().openDatabase(null, "inactiveQueues", StoredQueue.databaseConfig()); inactiveQueues = new StoredQueue<String>(inactiveQueuesDb, String.class, null); Database retiredQueuesDb = this.controller.getBdbEnvironment().openDatabase(null, "retiredQueues", StoredQueue.databaseConfig()); retiredQueues = new StoredQueue<String>(retiredQueuesDb, String.class, null); } catch (DatabaseException e) { throw new RuntimeException(e); } // small risk of OutOfMemoryError: in large crawls with many // unresponsive queues, an unbounded number of snoozed queues // may exist snoozedClassQueues = Collections.synchronizedSortedSet(new TreeSet<WorkQueue>()); }
From source file:com.inmobi.conduit.local.LocalStreamService.java
@Override protected void prepareStreamHcatEnableMap() { Map<String, SourceStream> sourceStreamMap = config.getSourceStreams(); for (String stream : streamsToProcess) { if (sourceStreamMap.containsKey(stream) && sourceStreamMap.get(stream).isHCatEnabled()) { streamHcatEnableMap.put(stream, true); Set<Path> paths = Collections.synchronizedSortedSet(new TreeSet<Path>()); pathsToBeregisteredPerTable.put(getTableName(stream), paths); } else {/*from w w w . j ava 2s .c om*/ streamHcatEnableMap.put(stream, false); } } LOG.info("Hcat enable map for local stream : " + streamHcatEnableMap); }
From source file:com.bittorrent.mpetazzoni.client.SharedTorrent.java
/** * Create a new shared torrent from meta-info binary data. * * @param torrent The meta-info byte data. * @param parent The parent directory or location the torrent files. * @param seeder Whether we're a seeder for this torrent or not (disables * validation).//from w w w.ja v a 2s. co m * @throws FileNotFoundException If the torrent file location or * destination directory does not exist and can't be created. * @throws IOException If the torrent file cannot be read or decoded. */ public SharedTorrent(byte[] torrent, File parent, boolean seeder) throws FileNotFoundException, IOException { super(torrent, seeder); if (parent == null || !parent.isDirectory()) { throw new IllegalArgumentException("Invalid parent directory!"); } String parentPath = parent.getCanonicalPath(); try { this.pieceLength = this.decoded_info.get("piece length").getInt(); this.piecesHashes = ByteBuffer.wrap(this.decoded_info.get("pieces").getBytes()); if (this.piecesHashes.capacity() / Torrent.PIECE_HASH_SIZE * (long) this.pieceLength < this.getSize()) { throw new IllegalArgumentException( "Torrent size does not " + "match the number of pieces and the piece size!"); } } catch (InvalidBEncodingException ibee) { throw new IllegalArgumentException("Error reading torrent meta-info fields!"); } List<FileStorage> files = new LinkedList<FileStorage>(); long offset = 0L; for (Torrent.TorrentFile file : this.files) { File actual = new File(parent, file.file.getPath()); if (!actual.getCanonicalPath().startsWith(parentPath)) { throw new SecurityException("Torrent file path attempted " + "to break directory jail!"); } actual.getParentFile().mkdirs(); files.add(new FileStorage(actual, offset, file.size)); offset += file.size; } this.bucket = new FileCollectionStorage(files, this.getSize()); this.random = new Random(System.currentTimeMillis()); this.stop = false; this.uploaded = 0; this.downloaded = 0; this.left = this.getSize(); this.initialized = false; this.pieces = new Piece[0]; this.rarest = Collections.synchronizedSortedSet(new TreeSet<Piece>()); this.completedPieces = new BitSet(); this.requestedPieces = new BitSet(); }