List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue
public LinkedBlockingQueue()
From source file:com.openteach.diamond.network.waverider.session.DefaultSession.java
public static void main(String[] args) { BlockingQueue<ByteBuffer> inputBuffer = new LinkedBlockingQueue<ByteBuffer>(); /*for (int i = 0; i < 10; i++) {*///from w ww . ja v a 2 s . c o m ByteBuffer byteBuffer = ByteBuffer.allocate(1024); byteBuffer.put(makePacket().marshall()); byteBuffer.put(makePacket().marshall()); byteBuffer.flip(); byte[] b = new byte[8]; ByteBuffer halfBuf0 = ByteBuffer.allocate(8); byteBuffer.get(b); halfBuf0.put(b); halfBuf0.flip(); inputBuffer.add(halfBuf0); inputBuffer.add(byteBuffer); /*}*/ int size = 0; int oldSize = size; long length = Packet.getHeaderSize(); ByteBuffer buffer = ByteBuffer.allocate(NetWorkConstants.DEFAULT_NETWORK_BUFFER_SIZE); ByteBuffer currentBuffer = null; while (size < length) { currentBuffer = inputBuffer.peek(); oldSize = size; int position = currentBuffer.position(); size += currentBuffer.remaining(); buffer.put(currentBuffer); if (size >= Packet.getHeaderSize()) { length = buffer.getLong(Packet.getLengthPosition()); } if (size <= length) { inputBuffer.remove(); } else { currentBuffer.position(position); buffer.position(buffer.position() - currentBuffer.remaining()); byte[] buf = new byte[(int) (length - oldSize)]; currentBuffer.get(buf); buffer.put(buf); } } // buffer.position(0); buffer.flip(); Packet packet = Packet.unmarshall(buffer); Command command = CommandFactory.createCommand(packet.getType(), packet.getPayLoad()); String str = new String(command.getPayLoad().array()); System.out.println(str); }
From source file:jp.realglobe.util.uploader.DirectoryUploaderWithServerTest.java
/** * ??/*from ww w .jav a 2 s . com*/ * @throws IOException * @throws InterruptedException ???? */ @Before public void setUp() throws IOException, InterruptedException { this.requestQueue = new LinkedBlockingQueue<>(); this.executor = Executors.newCachedThreadPool(); this.uploaderId = String.valueOf(Math.abs(System.nanoTime())); this.targetDirectory = Files.createTempDirectory(""); try { this.server = HttpServer.create(new InetSocketAddress(0), 0); this.server.createContext("/", this::handle); this.server.start(); } catch (final IOException e) { FileUtils.deleteDirectory(this.targetDirectory.toFile()); throw e; } // ?? Thread.sleep(1_000); }
From source file:com.manydesigns.elements.messages.SessionMessages.java
protected static BlockingQueue<String> getQueue(String queueName) { HttpServletRequest req = ElementsThreadLocals.getHttpServletRequest(); if (req == null) { logger.debug("No request available. Returning dummy queue."); return new LinkedBlockingQueue<String>(); }//from w w w . j a v a 2s . c o m HttpSession session = req.getSession(); BlockingQueue<String> infoQueue; synchronized (session) { infoQueue = (BlockingQueue) session.getAttribute(queueName); if (infoQueue == null) { // install a new queue infoQueue = new LinkedBlockingQueue<String>(); session.setAttribute(queueName, infoQueue); } } return infoQueue; }
From source file:org.apache.axis2.transport.base.threads.NativeWorkerPool.java
public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, String threadGroupName, String threadGroupId, BlockingQueue<Runnable> queue, RejectedExecutionHandler rejectedExecutionHandler) { if (log.isDebugEnabled()) { log.debug("Using native util.concurrent package.."); }//from w w w . ja va 2 s.c o m if (queue == null) { blockingQueue = (queueLength == -1 ? new LinkedBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>(queueLength)); } else { blockingQueue = queue; } executor = new Axis2ThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, blockingQueue, new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId), rejectedExecutionHandler); }
From source file:com.fusesource.forge.jmstest.threading.SteppablePool.java
public ExecutorService getExecutor() { if (executor == null) { executor = new ThreadPoolExecutor(minPoolSize, maxPoolSize, getIdleTimeout(), TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); }//from ww w.j a va2 s .com return executor; }
From source file:com.openteach.diamond.network.waverider.network.DefaultNetWorkClient.java
public DefaultNetWorkClient(String hostName, int port) { this.hostName = hostName; this.port = port; state = new AtomicInteger(NetworkStateEnum.NETWORK_STATE_DISCONNECT.value); isWeakuped = new AtomicBoolean(false); inputBuffer = new LinkedBlockingQueue<ByteBuffer>(); outputBuffer = new LinkedBlockingQueue<Command>(); waitMoreDataLock = new byte[0]; }
From source file:org.geoserver.wps.executor.DefaultProcessManager.java
public void setMaxSynchronousProcesses(int maxSynchronousProcesses) { if (synchService == null) { // create a fixed size pool. If we allow a delta between core and max // the pool will create new threads only if the queue is full, but the linked queue never is synchService = new ThreadPoolExecutor(maxSynchronousProcesses, maxSynchronousProcesses, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); } else {/* w w w .jav a 2 s .c om*/ synchService.setCorePoolSize(maxSynchronousProcesses); synchService.setMaximumPoolSize(maxSynchronousProcesses); } }
From source file:com.sm.store.client.ClientConnections.java
private void init(List<ClusterNodes> clusterNodesList) { this.clusterNodesList = clusterNodesList; partitionMap = buildPartitionMap(clusterNodesList); clusterConnections = buildClusterConnection(clusterNodesList, clientType); totalPartition = partitionMap.size(); reconnectQueue = new LinkedBlockingQueue<Connection>(); logger.info("start reconnect thread"); connectThread = new Thread(new ReconnectThread(reconnectQueue)); connectThread.start();//from w ww. j a va 2 s . c o m }
From source file:it.infn.ct.futuregateway.apiserver.utils.ThreadPoolFactory.java
/** * Create a new ExecutorService./* w w w . j a v a 2s .c o m*/ * The ExecutorService is based on the ThreadPoolExecutor but only * a subset of parameter can be specified. * * @param threadPoolSize The initial and minimum size of the pool * @param maxThreadPoolSize The maximum size of the pool * @param maxThreadIdleTime The time in milliseconds a thread can be idle * @return The new ExecutorService */ public static ExecutorService getThreadPool(final int threadPoolSize, final int maxThreadPoolSize, final int maxThreadIdleTime) { return new ThreadPoolExecutor(threadPoolSize, maxThreadPoolSize, maxThreadIdleTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); }
From source file:se.vgregion.pubsub.push.impl.DefaultFeedRetrieverTest.java
/** * Fragments should only be used during retrievel and stripped before publication *//*from w ww . j av a 2 s.co m*/ @Test public void retrievalWithFragment() throws Exception { final BlockingQueue<String> paths = new LinkedBlockingQueue<String>(); server.register("/*", new HttpRequestHandler() { @Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { paths.add(request.getRequestLine().getUri()); response.setEntity(testEntity); } }); String retrivalPath = "/test#foo"; URI publicationUrl = buildTestUrl("/test"); URI url = buildTestUrl(retrivalPath); retriever.retrieve(url); String path = paths.poll(2000, TimeUnit.MILLISECONDS); // retrived URI must contain fragment Assert.assertEquals(retrivalPath, path); ArgumentCaptor<Feed> publishedFeed = ArgumentCaptor.forClass(Feed.class); // published URI must no contain fragment Mockito.verify(pushSubscriberManager).publish(Mockito.eq(publicationUrl), publishedFeed.capture()); Assert.assertEquals("f1", publishedFeed.getValue().getFeedId()); }