List of usage examples for java.util.concurrent BlockingQueue poll
E poll();
From source file:com.brienwheeler.svc.monitor.telemetry.impl.AsynchronousTelemetryInfoProcessor.java
@Override @GracefulShutdown/* w w w .ja v a 2 s . c om*/ public void process(TelemetryInfo telemetryInfo) { telemetryInfo.checkPublished(); BlockingQueue<TelemetryInfo> queue = this.queue.get(); switch (queueFullPolicy.get()) { case DISCARD_OFFERED: queue.offer(telemetryInfo); // return regardless of success return; case DISCARD_OLDEST: while (!queue.offer(telemetryInfo)) { // if offer failed, remove and discard one element from queue and try // again queue.poll(); } return; } }
From source file:ubic.gemma.core.loader.association.NCBIGene2GOAssociationLoader.java
private void load(BlockingQueue<Gene2GOAssociation> queue) { NCBIGene2GOAssociationLoader.log.debug("Entering 'load' "); long millis = System.currentTimeMillis(); int cpt = 0;//w w w . j a va 2s . com double secspt = 0.0; Collection<Gene2GOAssociation> itemsToPersist = new ArrayList<>(); try { while (!(producerDone.get() && queue.isEmpty())) { Gene2GOAssociation associations = queue.poll(); if (associations == null) { continue; } itemsToPersist.add(associations); if (++count % NCBIGene2GOAssociationLoader.BATCH_SIZE == 0) { persisterHelper.persist(itemsToPersist); itemsToPersist.clear(); } // just some timing information. if (count % 10000 == 0) { cpt++; double secsperthousand = (System.currentTimeMillis() - millis) / 1000.0; secspt += secsperthousand; double meanspt = secspt / cpt; String progString = "Processed and loaded " + count + " (" + secsperthousand + " seconds elapsed, average per thousand=" + String.format("%.2f", meanspt) + ")"; NCBIGene2GOAssociationLoader.log.info(progString); millis = System.currentTimeMillis(); } } } catch (Exception e) { consumerDone.set(true); NCBIGene2GOAssociationLoader.log.fatal(e, e); throw new RuntimeException(e); } // finish up. persisterHelper.persist(itemsToPersist); NCBIGene2GOAssociationLoader.log.info("Finished, loaded total of " + count + " GO associations"); consumerDone.set(true); }
From source file:ubic.gemma.loader.genome.gene.ncbi.NcbiGeneLoader.java
/** * @param geneQueue//from w w w. j a v a 2s. c om */ void doLoad(final BlockingQueue<Gene> geneQueue) { StopWatch timer = new StopWatch(); timer.start(); int skipped = 0; while (!(converterDone.get() && geneQueue.isEmpty())) { Gene gene = null; try { // the converted genes. gene = geneQueue.poll(); if (gene == null) { continue; } if (gene.getProducts().isEmpty()) { // // log.warn( gene + " has no products, skipping" ); // common!!! // skipped++; } persisterHelper.persistOrUpdate(gene); if (++loadedGeneCount % 1000 == 0 || timer.getTime() > 30 * 1000) { log.info("Processed " + loadedGeneCount + " genes. Queue has " + geneQueue.size() + " items; last gene: " + gene); if (skipped > 0) { log.info(skipped + " skipped because they had no gene products."); } timer.reset(); timer.start(); } } catch (Exception e) { log.error("Error while loading gene: " + gene + ": " + e.getMessage(), e); loaderDone.set(true); throw new RuntimeException(e); } } log.info("Loaded " + loadedGeneCount + " genes. "); loaderDone.set(true); }
From source file:ubic.gemma.loader.association.NCBIGene2GOAssociationLoader.java
/** * @param queue/*from w ww . j ava 2 s .c o m*/ */ protected void load(BlockingQueue<Gene2GOAssociation> queue) { log.debug("Entering 'load' "); long millis = System.currentTimeMillis(); int cpt = 0; double secspt = 0.0; Collection<Gene2GOAssociation> itemsToPersist = new ArrayList<Gene2GOAssociation>(); try { while (!(producerDone.get() && queue.isEmpty())) { Gene2GOAssociation associations = queue.poll(); if (associations == null) { continue; } itemsToPersist.add(associations); if (++count % BATCH_SIZE == 0) { persisterHelper.persist(itemsToPersist); itemsToPersist.clear(); } // just some timing information. if (count % 1000 == 0) { cpt++; double secsperthousand = (System.currentTimeMillis() - millis) / 1000.0; secspt += secsperthousand; double meanspt = secspt / cpt; String progString = "Processed and loaded " + count + " (" + secsperthousand + " seconds elapsed, average per thousand=" + String.format("%.2f", meanspt) + ")"; log.info(progString); millis = System.currentTimeMillis(); } } } catch (Exception e) { consumerDone.set(true); log.fatal(e, e); throw new RuntimeException(e); } // finish up. persisterHelper.persist(itemsToPersist); log.info("Finished, loaded total of " + count + " GO associations"); consumerDone.set(true); }
From source file:ubic.gemma.loader.protein.StringProteinInteractionLoader.java
/** * Poll the queue to see if any Gene2GeneProteinAssociation to load into database. If so firstly check to see if the * genes are in the gemma db as these identifiers came from biomart If both genes found load. * //from w ww . j a v a2s . c o m * @param geneQueue queue of Gene2GeneProteinAssociation to load */ void doLoad(final BlockingQueue<Gene2GeneProteinAssociation> gene2GeneProteinAssociationQueue) { log.info("starting processing "); while (!(converterDone.get() && gene2GeneProteinAssociationQueue.isEmpty())) { try { Gene2GeneProteinAssociation gene2GeneProteinAssociation = gene2GeneProteinAssociationQueue.poll(); if (gene2GeneProteinAssociation == null) { continue; } // check they are genes gemma knows about Gene geneOne = geneService.findByNCBIId(gene2GeneProteinAssociation.getFirstGene().getNcbiGeneId()); Gene geneTwo = geneService .findByNCBIId(gene2GeneProteinAssociation.getSecondGene().getNcbiGeneId()); if (geneOne == null) { log.warn("Gene with NCBI id=" + gene2GeneProteinAssociation.getFirstGene().getNcbiGeneId() + " not in Gemma"); continue; } if (geneTwo == null) { log.warn("Gene with NCBI id=" + gene2GeneProteinAssociation.getSecondGene().getNcbiGeneId() + " not in Gemma"); continue; } gene2GeneProteinAssociation.setFirstGene(geneOne); gene2GeneProteinAssociation.setSecondGene(geneTwo); persisterHelper.persist(gene2GeneProteinAssociation); if (++loadedGeneCount % 1000 == 0) { log.info("Proceesed " + loadedGeneCount + " protein protein interactions. " + "Current queue has " + gene2GeneProteinAssociationQueue.size() + " items."); } } catch (Exception e) { log.error(e, e); loaderDone.set(true); throw new RuntimeException(e); } } log.info("Loaded " + loadedGeneCount + " protein protein interactions. "); loaderDone.set(true); }
From source file:ubic.gemma.core.loader.protein.StringProteinInteractionLoader.java
/** * Poll the queue to see if any Gene2GeneProteinAssociation to load into database. If so firstly check to see if the * genes are in the gemma db as these identifiers came from biomart If both genes found load. * * @param gene2GeneProteinAssociationQueue queue of Gene2GeneProteinAssociation to load *///from www. j a v a2 s .co m private void doLoad(final BlockingQueue<Gene2GeneProteinAssociation> gene2GeneProteinAssociationQueue) { StringProteinInteractionLoader.log.info("starting processing "); while (!(converterDone.get() && gene2GeneProteinAssociationQueue.isEmpty())) { try { Gene2GeneProteinAssociation gene2GeneProteinAssociation = gene2GeneProteinAssociationQueue.poll(); if (gene2GeneProteinAssociation == null) { continue; } // check they are genes gemma knows about Gene geneOne = geneService.findByNCBIId(gene2GeneProteinAssociation.getFirstGene().getNcbiGeneId()); Gene geneTwo = geneService .findByNCBIId(gene2GeneProteinAssociation.getSecondGene().getNcbiGeneId()); if (geneOne == null) { StringProteinInteractionLoader.log.warn("Gene with NCBI id=" + gene2GeneProteinAssociation.getFirstGene().getNcbiGeneId() + " not in Gemma"); continue; } if (geneTwo == null) { StringProteinInteractionLoader.log.warn("Gene with NCBI id=" + gene2GeneProteinAssociation.getSecondGene().getNcbiGeneId() + " not in Gemma"); continue; } FieldUtils.writeField(gene2GeneProteinAssociation, "firstGene", geneOne, true); FieldUtils.writeField(gene2GeneProteinAssociation, "secondGene", geneTwo, true); persisterHelper.persist(gene2GeneProteinAssociation); if (++loadedGeneCount % 1000 == 0) { StringProteinInteractionLoader.log .info("Proceesed " + loadedGeneCount + " protein protein interactions. " + "Current queue has " + gene2GeneProteinAssociationQueue.size() + " items."); } } catch (Exception e) { StringProteinInteractionLoader.log.error(e, e); loaderDone.set(true); throw new RuntimeException(e); } } StringProteinInteractionLoader.log.info("Loaded " + loadedGeneCount + " protein protein interactions. "); loaderDone.set(true); }
From source file:ubic.gemma.loader.genome.goldenpath.GoldenPathBioSequenceLoader.java
/** * @param bioSequences//from w w w . j av a 2 s .com */ void load(BlockingQueue<BioSequence> queue) { log.debug("Entering 'load' "); StopWatch timer = new StopWatch(); timer.start(); int count = 0; int cpt = 0; double secspt = 0.0; Collection<BioSequence> bioSequencesToPersist = new ArrayList<BioSequence>(); try { while (!(producerDone && queue.isEmpty())) { BioSequence sequence = queue.poll(); if (sequence == null) { continue; } sequence.getSequenceDatabaseEntry().setExternalDatabase(genbank); sequence.setTaxon(taxon); bioSequencesToPersist.add(sequence); if (++count % BATCH_SIZE == 0) { bioSequenceService.create(bioSequencesToPersist); bioSequencesToPersist.clear(); } // just some timing information. if (count % 1000 == 0) { cpt++; timer.stop(); double secsperthousand = timer.getTime() / 1000.0; secspt += secsperthousand; double meanspt = secspt / cpt; String progString = "Processed and loaded " + count + " sequences, last one was " + sequence.getName() + " (" + secsperthousand + "s for last 1000, mean per 1000 =" + String.format("%.1f", meanspt) + "s)"; log.info(progString); timer.reset(); timer.start(); } } } catch (Exception e) { consumerDone = true; throw new RuntimeException(e); } // finish up. bioSequenceService.create(bioSequencesToPersist); log.info("Loaded total of " + count + " sequences"); consumerDone = true; }
From source file:ubic.gemma.loader.expression.arrayDesign.ArrayDesignProbeMapperServiceImpl.java
/** * @param queue/*from w w w .j ava 2s.c o m*/ * @param generatorDone * @param loaderDone */ void doLoad(final BlockingQueue<BlatAssociation> queue, AtomicBoolean generatorDone, AtomicBoolean loaderDone) { int loadedAssociationCount = 0; while (!(generatorDone.get() && queue.isEmpty())) { try { BlatAssociation ba = queue.poll(); if (ba == null) { continue; } GeneProduct geneProduct = ba.getGeneProduct(); if (geneProduct.getId() == null) { GeneProduct existing = geneProductService.find(geneProduct); if (existing == null) { existing = checkForAlias(geneProduct); if (existing == null) { /* * We have to be careful not to cruft up the gene table now that I so carefully cleaned it. * But this is a problem if we aren't adding some other association to the gene at least. * But generally the mRNAs that GP has that NCBI doesn't are "alternative" or "additional". */ if (log.isDebugEnabled()) log.debug("New gene product from GoldenPath is not in Gemma: " + geneProduct + " skipping association to " + ba.getBioSequence() + " [skipping policy in place]"); continue; } } ba.setGeneProduct(existing); } persisterHelper.persist(ba); if (++loadedAssociationCount % 1000 == 0) { log.info("Persisted " + loadedAssociationCount + " blat associations. " + "Current queue has " + queue.size() + " items."); } } catch (Exception e) { log.error(e, e); loaderDone.set(true); throw new RuntimeException(e); } } log.info("Load thread done: loaded " + loadedAssociationCount + " blat associations. "); loaderDone.set(true); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
private Session<FTPFile> spyOnSession() { Session<FTPFile> session = spy(this.ftpSessionFactory.getSession()); session.close();/*from w w w .ja v a 2 s . c o m*/ @SuppressWarnings("unchecked") BlockingQueue<Session<FTPFile>> cache = TestUtils.getPropertyValue(ftpSessionFactory, "pool.available", BlockingQueue.class); assertNotNull(cache.poll()); cache.offer(session); @SuppressWarnings("unchecked") Set<Session<FTPFile>> allocated = TestUtils.getPropertyValue(ftpSessionFactory, "pool.allocated", Set.class); allocated.clear(); allocated.add(session); return session; }
From source file:ubic.gemma.core.loader.expression.arrayDesign.ArrayDesignProbeMapperServiceImpl.java
private void doLoad(final BlockingQueue<BACS> queue, AtomicBoolean generatorDone, AtomicBoolean loaderDone, boolean persist) { int loadedAssociationCount = 0; while (!(generatorDone.get() && queue.isEmpty())) { try {//from w w w . j ava2 s. com BACS bacs = queue.poll(); if (bacs == null) { continue; } GeneProduct geneProduct = bacs.ba.getGeneProduct(); if (geneProduct.getId() == null) { GeneProduct existing = geneProductService.find(geneProduct); if (existing == null) { existing = this.checkForAlias(geneProduct); if (existing == null) { /* * We have to be careful not to cruft up the gene table now that I so carefully cleaned it. * But this is a problem if we aren't adding some other association to the gene at least. * But generally the mRNAs that GP has that NCBI doesn't are "alternative" or "additional". */ if (ArrayDesignProbeMapperServiceImpl.log.isDebugEnabled()) ArrayDesignProbeMapperServiceImpl.log .debug("New gene product from GoldenPath is not in Gemma: " + geneProduct + " skipping association to " + bacs.ba.getBioSequence() + " [skipping policy in place]"); continue; } } bacs.ba.setGeneProduct(existing); } if (persist) { persisterHelper.persist(bacs.ba); if (++loadedAssociationCount % 1000 == 0) { ArrayDesignProbeMapperServiceImpl.log.info("Persisted " + loadedAssociationCount + " blat associations. " + "Current queue has " + queue.size() + " items."); } } else { this.printResult(bacs.cs, bacs.ba); } } catch (Exception e) { ArrayDesignProbeMapperServiceImpl.log.error(e, e); loaderDone.set(true); throw new RuntimeException(e); } } ArrayDesignProbeMapperServiceImpl.log .info("Load thread done: loaded " + loadedAssociationCount + " blat associations. "); loaderDone.set(true); }