Example usage for java.util.concurrent BlockingQueue isEmpty

List of usage examples for java.util.concurrent BlockingQueue isEmpty

Introduction

In this page you can find the example usage for java.util.concurrent BlockingQueue isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:ubic.gemma.loader.expression.arrayDesign.ArrayDesignProbeMapperServiceImpl.java

/**
 * @param queue/*from  w  w  w.ja  v a 2s.  co 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:ubic.gemma.loader.genome.gene.ncbi.NcbiGeneConverter.java

public void convert(final BlockingQueue<NcbiGeneData> geneInfoQueue, final BlockingQueue<Gene> geneQueue) {
    // start up thread to convert a member of geneInfoQueue to a gene/geneproduct/databaseentry
    // then push the gene onto the geneQueue for loading

    if (!retainProteinInformation) {
        log.info("Note that protein information will be ignored; set " + RETAIN_PROTEIN_INFO_PARAM
                + " to true to change");
    }/*  w  w  w  . j a va 2s .  c  o  m*/

    Thread convertThread = new Thread(new Runnable() {
        @Override
        @SuppressWarnings("synthetic-access")
        public void run() {
            while (!(sourceDone.get() && geneInfoQueue.isEmpty())) {
                try {
                    NcbiGeneData data = geneInfoQueue.poll();
                    if (data == null) {
                        continue;
                    }
                    Gene converted = convert(data);

                    geneQueue.put(converted);

                } catch (InterruptedException e) {
                    log.warn("Interrupted");
                    break;
                } catch (Exception e) {
                    log.error(e, e);
                    break;
                }
            }
            producerDone.set(true);
        }
    }, "Converter");

    convertThread.start();
}

From source file:ubic.gemma.loader.genome.gene.ncbi.NcbiGeneLoader.java

/**
 * @param geneQueue/*from   w  w  w  .ja  va 2s  .  com*/
 */
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.genome.goldenpath.GoldenPathBioSequenceLoader.java

/**
 * @param bioSequences/*from   ww w  .j a v a  2s  .c o  m*/
 */
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.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 ww  w . j a v  a 2 s .com
 * @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);
}