Example usage for java.util.concurrent LinkedBlockingQueue put

List of usage examples for java.util.concurrent LinkedBlockingQueue put

Introduction

In this page you can find the example usage for java.util.concurrent LinkedBlockingQueue put.

Prototype

public void put(E e) throws InterruptedException 

Source Link

Document

Inserts the specified element at the tail of this queue, waiting if necessary for space to become available.

Usage

From source file:org.apache.bookkeeper.metadata.etcd.testing.EtcdTestBase.java

protected static <T> Consumer<Versioned<Set<T>>> consumeVersionedKeySet(
        LinkedBlockingQueue<Versioned<Set<T>>> notifications) {
    return versionedKeys -> {
        log.info("Received new keyset : {}", versionedKeys);
        try {//from w w w. j av a2s .c o  m
            notifications.put(versionedKeys);
        } catch (InterruptedException e) {
            log.error("Interrupted at enqueuing updated key set", e);
        }
    };
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

private static void updateBbox() {

    try {//from w  w w. j a v a  2 s. c o m
        Connection conn = getConnection();
        String sql = "SELECT pid from objects where bbox is null limit 200000;";
        logger.info("loading bbox ...");
        Statement s1 = conn.createStatement();
        ResultSet rs1 = s1.executeQuery(sql);

        LinkedBlockingQueue<String[]> data = new LinkedBlockingQueue<String[]>();
        while (rs1.next()) {
            data.put(new String[] { rs1.getString("pid") });
        }

        CountDownLatch cdl = new CountDownLatch(data.size());

        BboxThread[] threads = new BboxThread[CONCURRENT_THREADS];
        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j] = new BboxThread(data, cdl, getConnection().createStatement());
            threads[j].start();
        }

        cdl.await();

        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j].s.close();
            threads[j].interrupt();
        }
        return;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return;
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

private static void updateArea(String fid) {

    try {/*from  w ww  . j  a v a 2s  .  c  o m*/
        Connection conn = getConnection();
        String sql = "SELECT pid from objects where area_km is null and st_geometrytype(the_geom) <> 'Point'";
        if (fid != null) {
            sql = sql + " and fid = '" + fid + "'";
        }

        sql = sql + " limit 200000;";

        System.out.println("loading area_km ...");
        Statement s1 = conn.createStatement();
        ResultSet rs1 = s1.executeQuery(sql);

        LinkedBlockingQueue<String> data = new LinkedBlockingQueue<String>();
        while (rs1.next()) {
            data.put(rs1.getString("pid"));
        }

        CountDownLatch cdl = new CountDownLatch(data.size());

        AreaThread[] threads = new AreaThread[CONCURRENT_THREADS];
        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j] = new AreaThread(data, cdl, getConnection().createStatement());
            threads[j].start();
        }

        cdl.await();

        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j].s.close();
            threads[j].interrupt();
        }
        rs1.close();
        s1.close();
        conn.close();
        return;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return;
}

From source file:org.apache.hadoop.hbase.trigger.WritePrepared.java

public static void addElement(int k, WriteUnit v) throws InterruptedException {
    LinkedBlockingQueue<WriteUnit> curr = cachedElements.get(k);
    if (curr == null) {
        curr = new LinkedBlockingQueue<WriteUnit>();
        cachedElements.put(k, curr);/* w w w  . j  av  a  2  s .c o  m*/
    }
    curr.put(v);
    if (!flags.containsKey(k)) {
        AtomicBoolean n = new AtomicBoolean(false);
        flags.put(k, n);
    }

}

From source file:org.apache.bookkeeper.metadata.etcd.EtcdRegistrationTest.java

protected static RegistrationListener newRegistrationListener(
        LinkedBlockingQueue<Versioned<Set<BookieSocketAddress>>> notifications) {
    return bookies -> {
        log.info("Received new bookies: {}", bookies);
        try {/*  w w w.  ja v  a2  s  .  com*/
            notifications.put(bookies);
        } catch (InterruptedException e) {
            log.error("Interrupted at enqueuing updated key set", e);
        }
    };
}

From source file:twitter4j.internal.json.z_T4JInternalParseUtil.java

public static Date getDate(String dateString, String format) throws TwitterException {
    LinkedBlockingQueue<SimpleDateFormat> simpleDateFormats = formatMapQueue.get(format);
    if (simpleDateFormats == null) {
        simpleDateFormats = new LinkedBlockingQueue<SimpleDateFormat>();
        formatMapQueue.put(format, simpleDateFormats);
    }/*w  w  w.  j av  a2  s . com*/
    SimpleDateFormat sdf = simpleDateFormats.poll();
    if (null == sdf) {
        sdf = new SimpleDateFormat(format, Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    }
    try {
        return sdf.parse(dateString);
    } catch (ParseException pe) {
        throw new TwitterException("Unexpected date format(" + dateString + ") returned from twitter.com", pe);
    } finally {
        try {
            simpleDateFormats.put(sdf);
        } catch (InterruptedException ignore) {
            // the size of LinkedBlockingQueue is Integer.MAX by default.
            // there is no need to concern about this situation
        }
    }
}

From source file:cn.wanghaomiao.seimi.def.DefaultLocalQueue.java

@Override
public boolean push(Request req) {
    try {//from   w ww.  j a v  a2  s . co m
        LinkedBlockingQueue<Request> queue = getQueue(req.getCrawlerName());
        queue.put(req);
        return true;
    } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
    }
    return false;
}

From source file:com.adaptris.http.HttpListener.java

/**
 * Add a request processor to the list/* w w w . j a  va  2  s . c om*/
 * 
 * @param rp the request processor.
 * @throws HttpException on error.
 */
public synchronized void addRequestProcessor(RequestProcessor rp) throws HttpException {
    try {

        String uri = rp.getUri();
        LinkedBlockingQueue list = (LinkedBlockingQueue) requestProcessors.get(uri);
        if (list == null) {
            list = new LinkedBlockingQueue();
        }
        list.put(rp);
        requestProcessors.put(uri, list);
    } catch (Exception e) {
        throw new HttpException(e);
    }
}

From source file:org.wso2.carbon.databridge.agent.thrift.internal.publisher.client.EventPublisher.java

private void notifyConnectionFailure(ArrayList<Event> tempEventBundleHolder) {
    if (null != receiverStateObserver) {
        ReceiverConfiguration conf = dataPublisherConfiguration.getReceiverConfiguration();
        StringBuilder url = new StringBuilder(conf.getDataReceiverProtocol().toString());
        url.append("://");
        url.append(conf.getDataReceiverIp());
        url.append(":");
        url.append(conf.getDataReceiverPort());
        receiverStateObserver.notifyConnectionFailure(url.toString(), conf.getUserName(), conf.getPassword());
        if (null != eventQueue) {
            LinkedBlockingQueue<Event> events = eventQueue.getAndResetQueue();
            if (null != tempEventBundleHolder) {
                for (Event event : tempEventBundleHolder) {
                    try {
                        events.put(event);
                    } catch (InterruptedException ignore) {
                        log.error("Error while populating resend events list", ignore);
                    }//  w  w  w .  j  a va  2s  . co m
                }
            }
            if (log.isDebugEnabled()) {
                log.debug("resending events size: " + events.size() + "in thread id :"
                        + Thread.currentThread().getId());
            }
            receiverStateObserver.resendEvents(events);
        }

    }
}

From source file:disko.flow.analyzers.FullRelexAnalyzer.java

protected void submitTask(EntityMaintainer input, LinkedBlockingQueue<Future<RelexTaskResult>> results)
        throws InterruptedException {
    RelexContext context = pool.take();/*from w  ww . j ava2 s.  com*/
    Callable<RelexTaskResult> callable = new RelexTask(count++,
            input.getOriginalSentence().replace('\n', ' ').replace('\r', ' '), input, sentenceAlgorithmApplier,
            null /* phraseMarkup */, context, pool);
    Future<RelexTaskResult> submit = exec.submit(callable);
    log.debug("LinkGrammarAnalyzer submitted " + callable);
    results.put(submit);
}