Example usage for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue

List of usage examples for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue

Introduction

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

Prototype

public ArrayBlockingQueue(int capacity) 

Source Link

Document

Creates an ArrayBlockingQueue with the given (fixed) capacity and default access policy.

Usage

From source file:edu.cornell.mannlib.ld4lindexing.ThreadPool.java

public ThreadPool(Settings settings) {
    int poolSize = settings.getThreadPoolSize();
    int queueSize = settings.getTaskQueueSize();
    this.service = new ThreadPoolExecutor(poolSize, poolSize, 10, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(queueSize), new ThreadPoolExecutor.CallerRunsPolicy());
}

From source file:com.offbynull.voip.ui.SingleSupplier.java

public SingleSupplier(Supplier<T> backingSupplier) {
    Validate.notNull(backingSupplier);// w w  w  . j a v  a2 s  . c  o m
    this.reference = new ArrayBlockingQueue<>(1);
    this.backingSupplier = backingSupplier;
}

From source file:ai.susi.json.JsonStreamReader.java

public JsonStreamReader(InputStream inputStream, String name, int concurrency) {
    this.jsonline = new ArrayBlockingQueue<>(1000);
    this.inputStream = inputStream;
    this.name = name;
    this.concurrency = concurrency;
}

From source file:com.tyndalehouse.step.tools.modules.ConvertXmlToOSISModule.java

private void convert() throws Exception {
    final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(1024);
    final ExecutorService executorService = new ThreadPoolExecutor(3, 3, 1, TimeUnit.DAYS, queue);

    final File[] files = SOURCE_DIRECTORY.listFiles();
    for (final File f : files) {
        if (f.isDirectory()) {
            final File[] unzippedFiles = f.listFiles();
            for (final File unzipped : unzippedFiles) {
                if (unzipped.getName().endsWith(".xml")) {
                    executorService.submit(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                convertToXml(f.getName(), unzipped);
                                LOGGER.debug("Finished [{}], [{}] remaining", f.getName(), queue.size());
                            } catch (Exception e) {
                                LOGGER.error("Failed to convert [{}]", f.getName(), e);
                            }/* w  ww.  j a  v a 2 s  .c o m*/
                        }
                    });
                    break;
                }
            }
            //                break;
        }
    }
    executorService.shutdown();
}

From source file:org.paxle.core.queue.AQueue.java

public AQueue(int length, final boolean limited) {
    this.queue = (limited) ? new ArrayBlockingQueue<Data>(length) : new LinkedBlockingQueue<Data>(length);
}

From source file:org.apache.kylin.storage.hbase.cube.v2.ExpectedSizeIterator.java

public ExpectedSizeIterator(int expectedSize, int coprocessorTimeout) {
    this.expectedSize = expectedSize;
    this.queue = new ArrayBlockingQueue<byte[]>(expectedSize);

    this.coprocessorTimeout = coprocessorTimeout;
    //longer timeout than coprocessor so that query thread will not timeout faster than coprocessor
    this.deadline = System.currentTimeMillis() + coprocessorTimeout * 10;
}

From source file:com.simplymeasured.prognosticator.HiveJDBCQueryImpl.java

@Override
public Iterator<Map<String, Object>> runQuery(String resultTable, String queryStatement,
        Map<String, Object> parameters) {
    final ArrayBlockingQueue<Map<String, Object>> rowQueue = new ArrayBlockingQueue<Map<String, Object>>(1000);

    ThreadedQueryRunnable runnable = new ThreadedQueryRunnable(dataSource, queryStatement, parameters,
            rowQueue);//from w ww . ja  v  a 2s  . co  m

    executorService.submit(runnable);

    return new Iterator<Map<String, Object>>() {
        private boolean done = false;
        private Map<String, Object> cachedRow = null;
        private final Map<String, Object> emptyMap = Collections.emptyMap();

        @Override
        public boolean hasNext() {
            try {
                if (done)
                    return false;

                cachedRow = rowQueue.take();

                if (cachedRow == null || cachedRow == emptyMap) {
                    done = true;
                    return false;
                }

                return true;
            } catch (InterruptedException ie) {
                throw new RuntimeException("Iterator thread killed!", ie);
            }
        }

        @Override
        public Map<String, Object> next() {
            if (done || cachedRow == emptyMap) {
                throw new IllegalStateException("End of iterator reached");
            } else if (cachedRow == null) {
                boolean hasMore = hasNext();

                if (!hasMore) {
                    done = true;
                    throw new IllegalStateException("End of iterator reached");
                }
            }

            return cachedRow;
        }

        @Override
        public void remove() {
            // intentionally non-op
        }
    };
}

From source file:com.kurento.kmf.media.AbstractAsyncBaseTest.java

@Before
public void abstractSetup() throws InterruptedException {
    final BlockingQueue<MediaPipeline> events = new ArrayBlockingQueue<MediaPipeline>(1);
    pipelineFactory.create(new Continuation<MediaPipeline>() {
        @Override/*from ww  w  .  j  a v a 2s  .c  om*/
        public void onSuccess(MediaPipeline result) {
            events.add(result);
        }

        @Override
        public void onError(Throwable cause) {
            throw new KurentoMediaFrameworkException(cause);
        }
    });
    pipeline = events.poll(500, MILLISECONDS);

    if (pipeline == null) {
        Assert.fail();
    }
}

From source file:io.gravitee.management.standalone.jetty.JettyServerFactory.java

@Override
public Server getObject() throws Exception {

    // Setup ThreadPool
    QueuedThreadPool threadPool = new QueuedThreadPool(jettyConfiguration.getPoolMaxThreads(),
            jettyConfiguration.getPoolMinThreads(), jettyConfiguration.getPoolIdleTimeout(),
            new ArrayBlockingQueue<Runnable>(jettyConfiguration.getPoolQueueSize()));
    threadPool.setName("gravitee-listener");

    Server server = new Server(threadPool);

    // Extra options
    server.setDumpAfterStart(false);/*w  ww  .  j  a v a 2 s .c o  m*/
    server.setDumpBeforeStop(false);
    server.setStopAtShutdown(true);

    // Setup JMX
    if (jettyConfiguration.isJmxEnabled()) {
        MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        server.addBean(mbContainer);
    }

    // HTTP Configuration
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme("https");
    httpConfig.setSecurePort(8443);
    httpConfig.setOutputBufferSize(32768);
    httpConfig.setRequestHeaderSize(8192);
    httpConfig.setResponseHeaderSize(8192);
    httpConfig.setSendServerVersion(false);
    httpConfig.setSendDateHeader(false);

    // Setup Jetty HTTP Connector
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    http.setPort(jettyConfiguration.getHttpPort());
    http.setIdleTimeout(jettyConfiguration.getIdleTimeout());

    server.addConnector(http);

    // Setup Jetty statistics
    if (jettyConfiguration.isStatisticsEnabled()) {
        StatisticsHandler stats = new StatisticsHandler();
        stats.setHandler(server.getHandler());
        server.setHandler(stats);
    }

    if (jettyConfiguration.isAccessLogEnabled()) {
        AsyncNCSARequestLog requestLog = new AsyncNCSARequestLog(jettyConfiguration.getAccessLogPath());
        requestLog.setRetainDays(90);
        requestLog.setExtended(true);
        requestLog.setLogLatency(true);
        requestLog.setLogTimeZone("GMT");

        server.setRequestLog(requestLog);
    }

    return server;
}

From source file:org.openqa.selenium.server.SingleEntryAsyncQueue.java

public SingleEntryAsyncQueue(int timeoutInSecs) {
    timeoutInSeconds = timeoutInSecs;/*from   w  ww  .j a  va  2  s .  co m*/
    holder = new ArrayBlockingQueue<T>(1);
    poisonData = new AtomicReference<T>();
}