Java 8 LinkedBlockingQueue - 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 LinkedBlockingQueue class.

This code example shows how to use the following methods:
 
	private final StompDecoder stompDecoder;
 
	private final int bufferSizeLimit;
 
	private final Queue<ByteBuffer> chunks = new LinkedBlockingQueue<ByteBuffer>();
 
	private volatile Integer expectedContentLength;
 
 
	public BufferingStompDecoder(StompDecoder stompDecoder, int bufferSizeLimit) {
		Assert.notNull(stompDecoder, "'stompDecoder' is required");
		Assert.isTrue(bufferSizeLimit > 0, "Buffer size must be greater than 0");
		this.stompDecoder = stompDecoder;
		this.bufferSizeLimit = bufferSizeLimit;
	} 
 
 
	/** 
	 * Return the wrapped 
8
CodeRank
This code example shows how to use the following methods:
 * @see #getQueue() 
 */ 
public class BlockedSyslogServerEventHandler implements SyslogServerEventHandlerIF { 
 
    private static final long serialVersionUID = -3814601581286016000L; 
    private static final BlockingQueue<SyslogServerEventIF> queue = new LinkedBlockingQueue<SyslogServerEventIF>(); 
 
    public static BlockingQueue<SyslogServerEventIF> getQueue() { 
        return queue; 
    } 
 
    public void event(SyslogServerIF syslogServer, SyslogServerEventIF event) { 
        queue.offer(event); 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:
public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorator {
 
	private static final Log logger = LogFactory.getLog("_" + ConcurrentWebSocketSessionDecorator.class.getName());
 
 
	private final Queue<WebSocketMessage<?>> buffer = new LinkedBlockingQueue<WebSocketMessage<?>>();
 
	private final AtomicInteger bufferSize = new AtomicInteger();
 
	private final int bufferSizeLimit;
 
 
	private volatile long sendStartTime;
 
	private final int sendTimeLimit;
 
 
	private volatile boolean limitExceeded;
 
	private volatile boolean shutdownInProgress;
8
CodeRank
This code example shows how to use the following methods:
     */ 
    public CachingByteBufferAllocator(boolean direct, int smallBufferSizeInBytes, int largeBufferSizeInBytes,
                                      int smallCacheSizeInBytes, int largeCacheSizeInBytes) {
        super(direct, smallBufferSizeInBytes, largeBufferSizeInBytes);
        this.smallCache = new LinkedBlockingQueue<ByteBuffer>(smallCacheSizeInBytes / smallBufferSizeInBytes);
        this.largeCache = new LinkedBlockingQueue<ByteBuffer>(largeCacheSizeInBytes / largeBufferSizeInBytes);
    } 
 
 
    public ByteBuffer allocate(Type type) throws IOException {
        ByteBuffer buffer = type == Type.SMALL ? smallCache.poll() : largeCache.poll();
        if (buffer == null) {
            buffer = super.allocate(type);
        } 
        return buffer;
    } 
 
    public void release(ByteBuffer buffer) {
        if (buffer.capacity() == smallBufferSizeInBytes) {
            boolean success = smallCache.offer(buffer);
8
CodeRank
This code example shows how to use the following methods:
 * @author "Xiaoyang Gu<xgu@linkedin.com>" 
 * 
 */ 
public class ZoieExecutors { 
  public static ExecutorService newFixedThreadPool(int nThreads) { 
    return new ZoieThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, 
        new LinkedBlockingQueue<Runnable>()); 
  } 
 
  public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) { 
    return new ZoieThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, 
        new LinkedBlockingQueue<Runnable>(), threadFactory); 
  } 
 
  public static ExecutorService newCachedThreadPool() { 
    return new ZoieThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, 
        new SynchronousQueue<Runnable>()); 
  } 
 
  public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { 
8
CodeRank
This code example shows how to use the following methods:
import javax.servlet.http.HttpSessionListener; 
 
@WebListener 
public class RecordingWebListener implements HttpSessionListener, HttpSessionAttributeListener { 
 
    public static BlockingQueue<String> createdSessions = new LinkedBlockingQueue<>();
    public static BlockingQueue<String> destroyedSessions = new LinkedBlockingQueue<>();
    public static ConcurrentMap<String, BlockingQueue<String>> addedAttributes = new ConcurrentHashMap<>();
    public static ConcurrentMap<String, BlockingQueue<String>> removedAttributes = new ConcurrentHashMap<>();
    public static ConcurrentMap<String, BlockingQueue<String>> replacedAttributes = new ConcurrentHashMap<>();
 
    private static void record(HttpSessionBindingEvent event, ConcurrentMap<String, BlockingQueue<String>> attributes) {
        BlockingQueue<String> set = new LinkedBlockingQueue<>();
        BlockingQueue<String> existing = attributes.putIfAbsent(event.getSession().getId(), set);
        ((existing != null) ? existing : set).add(event.getName());
    } 
 
    @Override 
    public void attributeAdded(HttpSessionBindingEvent event) {
        record(event, addedAttributes);
8
CodeRank
This code example shows how to use the following methods:
        } 
    } 
 
    private static class TestHandler extends SimpleChannelInboundHandler<ByteBuf> { 
        volatile SocketChannel ch;
        final BlockingQueue<Byte> queue = new LinkedBlockingQueue<Byte>();
 
        @Override 
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            ch = (SocketChannel) ctx.channel();
        } 
 
        @Override 
        public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
            queue.offer(msg.readByte());
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:add
	/** Tests that a connection that has been idle for more than the set time is closed off.  
	 * @throws SQLException  
	 * @throws CloneNotSupportedException */ 
	@Test 
	public void testIdleConnectionIsKilled() throws SQLException, CloneNotSupportedException { 
		LinkedBlockingQueue<ConnectionHandle> fakeFreeConnections = new LinkedBlockingQueue<ConnectionHandle>(100);
		fakeFreeConnections.add(mockConnection);
		fakeFreeConnections.add(mockConnection);
		BoneCPConfig localconfig = config.clone();
		expect(mockPool.getConfig()).andReturn(localconfig.clone()).anyTimes();
		expect(mockConnectionPartition.getFreeConnections()).andReturn(fakeFreeConnections).anyTimes();
		expect(mockConnectionPartition.getAvailableConnections()).andReturn(2).anyTimes();
		 
//		expect(mockConnectionPartition.getMinConnections()).andReturn(0).once(); 
		expect(mockConnection.isPossiblyBroken()).andReturn(false);
		expect(mockConnection.getConnectionLastUsedInMs()).andReturn(0L);
		 
		// connection should be closed 
		mockConnection.internalClose();
		mockPool.postDestroyConnection(mockConnection);
7
CodeRank
This code example shows how to use the following methods:isEmpty
    @Test
    public void testAutoSubscribeToNoListeners() throws Exception {
 
        Mockito.when(channelManager.getNodeSubscriptionListeners()).thenReturn(new ResultSetImpl<NodeSubscription>(new LinkedList<NodeSubscription>()));
 
        BlockingQueue<Packet> outQueue = new LinkedBlockingQueue<Packet>();
        onlineUser.subscribeToNodeListeners(outQueue);
 
        Assert.assertTrue(outQueue.isEmpty());
    } 
 
    @Test
    public void testAutoSubscribeToListeners() throws Exception {
 
        JID jid = new JID("user@server.com");
        LinkedList<NodeSubscription> subscriptions = new LinkedList<NodeSubscription>();
        subscriptions.add(new NodeSubscriptionImpl("nodeId", jid, Subscriptions.subscribed, null));
        Mockito.when(channelManager.getNodeSubscriptionListeners()).thenReturn(new ResultSetImpl<NodeSubscription>(subscriptions));
 
        BlockingQueue<Packet> outQueue = new LinkedBlockingQueue<Packet>();
7
CodeRank
This code example shows how to use the following methods:
    return new THsHaServer(serverArgs);
  } 
 
  private static ExecutorService createExecutor(
      int workerThreads, ThriftMetrics metrics) {
    CallQueue callQueue = new CallQueue(
        new LinkedBlockingQueue<Call>(), metrics);
    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
    tfb.setDaemon(true);
    tfb.setNameFormat("thrift2-worker-%d");
    return new ThreadPoolExecutor(workerThreads, workerThreads,
            Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());
  } 
 
  private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory, THBaseService.Processor processor,
      TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(inetSocketAddress);
    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processor(processor);
7
CodeRank
See Code Examples for Java 8 LinkedBlockingQueue Methods: