Java 8 ArrayBlockingQueue - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ArrayBlockingQueue class.

This code example shows how to use the following methods:poll
		} 
	} 
 
	public <T extends BaseResponsePacket> T commit(BasePacket packet) {
		try { 
			BlockingQueue<BaseResponsePacket> queue = new ArrayBlockingQueue<BaseResponsePacket>(1);
			results.put(packet.getRequest(), queue);
			Session session = sessionFactory.getSession(this, address, timeout,
					unit);
			packet.setTimeout(timeout); // set timeout, should before getBuffer
			ByteBuffer bb = packet.getBuffer();
			//System.out.println("start commit@" + System.currentTimeMillis()); 
			this.handle(session, session.commit(bb.array()));
			//System.out.println("end commit@" + System.currentTimeMillis()); 
			BaseResponsePacket result = queue.poll(timeout, unit);
			//System.out.println("get response@" + System.currentTimeMillis()); 
			if (result == null) {
				//session.close(); 
				//System.out.println("get null response"); 
				throw new TimeOutException("timeout: " + timeout + ", server: " + toString());
7
CodeRank
This code example shows how to use the following methods:
    public BlockingQueueOperationListener() { 
        this(new LinkedBlockingQueue<TransactionalProtocolClient.PreparedOperation<T>>());
    } 
 
    public BlockingQueueOperationListener(final int capacity) {
        this(new ArrayBlockingQueue<TransactionalProtocolClient.PreparedOperation<T>>(capacity));
    } 
 
    public BlockingQueueOperationListener(final BlockingQueue<TransactionalProtocolClient.PreparedOperation<T>> queue) {
        this.queue = queue;
    } 
 
    @Override 
    public void operationPrepared(final TransactionalProtocolClient.PreparedOperation<T> prepared) { 
        if(! queue.offer(prepared)) { 
            prepared.rollback(); 
        } 
    } 
 
    @Override 
7
CodeRank
This code example shows how to use the following methods:poll
        "}\n"); 
  } 
 
  private void testKeyHandler(String command) throws Exception {
    CountDownLatch latch1 = new CountDownLatch(1);
    ArrayBlockingQueue<int[]> queue = new ArrayBlockingQueue<int[]>(1);
    groovyShell.setVariable("queue", queue);
    groovyShell.setVariable("latch1", latch1);
    groovyShell.setVariable("latch2", new CountDownLatch(1));
    lifeCycle.bindGroovy("foo", command);
    final BaseProcessContext process = create("foo");
    new Thread() {
      @Override 
      public void run() { 
        process.execute();
      } 
    }.start();
    latch1.await(10, TimeUnit.SECONDS);
    process.on(null, new int[]{'a'});
    ShellResponse response = process.getResponse();

7
CodeRank
This code example shows how to use the following methods:
   * {@inheritDoc} 
   */ 
  @Override 
  protected boolean configureClient(RemoteReceiverClient client) { 
    client.setContext(getContext()); 
    client.setQueue(new ArrayBlockingQueue<Serializable>(clientQueueSize)); 
    return true; 
  } 
 
} 
6
CodeRank
This code example shows how to use the following methods:
 
    final TwitterStream twitterStream;
    final StatusListener statusListener;
    final int QUEUE_SIZE = 2000;
    /** This queue is used to move twitter events from the twitter4j thread to the druid ingest thread.   */ 
    final BlockingQueue<Status> queue = new ArrayBlockingQueue<Status>(QUEUE_SIZE);
    final LinkedList<String> dimensions = new LinkedList<String>();
    final long startMsec = System.currentTimeMillis();
 
    dimensions.add("htags");
    dimensions.add("lang");
    dimensions.add("utc_offset");
 
    // 
    //   set up Twitter Spritzer 
    // 
    twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addConnectionLifeCycleListener(connectionLifeCycleListener);
    statusListener = new StatusListener() {  // This is what really gets called to deliver stuff from twitter4j
      @Override 
6
CodeRank
This code example shows how to use the following methods:remainingCapacity, size
		sb.append(task.getClass().getName());
		sb.append(" \t| total: ").append(threadPool.getTaskCount());
		sb.append(" \t| completed: ")
				.append(threadPool.getCompletedTaskCount());
		sb.append(" \t| active: ").append(threadPool.getActiveCount());
		sb.append(" \t| in queue: ").append(queue.size());
		sb.append(" \t| remaining in queue: ")
				.append(queue.remainingCapacity());
 
		return sb.toString();
	} 
 
	private class ScheduledTask implements Runnable {
 
        private final Runnable task;
 
        public ScheduledTask( Runnable task ) {
            this.task = task;
        } 
 
6
CodeRank
This code example shows how to use the following methods:
	//调度任务 jobId 
	private Queue<String> queue=new ArrayBlockingQueue<String>(10000);
	//调试任务  debugId 
	private Queue<String> debugQueue=new ArrayBlockingQueue<String>(1000);
	//手动任务  historyId 
	private Queue<String> manualQueue=new ArrayBlockingQueue<String>(1000);
	private MasterHandler handler;
	private MasterServer server;
	private ExecutorService threadPool=Executors.newCachedThreadPool();
	private ScheduledExecutorService schedulePool=Executors.newScheduledThreadPool(5);
	 
	public MasterContext(ApplicationContext applicationContext){
		this.applicationContext=applicationContext;
	} 
	public void init(int port){
		try { 
			scheduler=new StdSchedulerFactory().getScheduler();
			scheduler.start();
		} catch (SchedulerException e) {
			ScheduleInfoLog.error("schedule start fail", e);
6
CodeRank
This code example shows how to use the following methods:
  private final long timeoutInSeconds;
  private final ArrayBlockingQueue<T> holder;
 
  public SingleEntryAsyncQueue(long timeoutInSecs) {
    timeoutInSeconds = timeoutInSecs;
    holder = new ArrayBlockingQueue<T>(1);
    poisonData = new AtomicReference<T>();
  } 
 
  public long getTimeoutInSeconds() { 
    return timeoutInSeconds;
  } 
 
  protected void setPoison(T poisonInstance) {
    poisonData.set(poisonInstance);
  } 
 
  protected boolean isPoison(T poisonSample) {
    T poison = poisonData.get();
    return null != poison && poison.equals(poisonSample);
6
CodeRank
This code example shows how to use the following methods:
 
    public FJBatchIterableProcedureRunner(Combiner<PT> newCombiner, int taskCount)
    { 
        this.combiner = newCombiner;
        this.taskCount = taskCount;
        this.outputQueue = this.combiner.useCombineOne() ? new ArrayBlockingQueue<PT>(taskCount) : null;
    } 
 
    private FastList<ForkJoinTask<PT>> createAndExecuteTasks(ForkJoinPool executor, ProcedureFactory<PT> procedureFactory, BatchIterable<T> iterable)
    { 
        FastList<ForkJoinTask<PT>> tasks = FastList.newList(this.taskCount);
        for (int index = 0; index < this.taskCount; index++)
        { 
            ForkJoinTask<PT> voidBlockFJTask = new FJBatchIterableProcedureTask<>(this, procedureFactory, iterable, index, this.taskCount);
            tasks.add(voidBlockFJTask);
            executor.execute(voidBlockFJTask);
        } 
        return tasks;
    } 
 
6
CodeRank
This code example shows how to use the following methods:add, remove
        //"e791b43af91c0523b2095b3841413ece" 
        //Map map = new HashMap(); 
        //map.put("filter", " where lastname like $P{lastname}"); 
        //String s = "select o from where ${filter} "; 
        //System.out.println( ExprUtil.substituteValues( s, map )); 
        ArrayBlockingQueue aq = new ArrayBlockingQueue(2);
        aq.add("test1");
        aq.add("test2");
        aq.remove("test2");
        aq.add("test3");
         
    } 
 
} 
6
CodeRank
See Code Examples for Java 8 ArrayBlockingQueue Methods: