PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 0ms app.codeStats 1ms

/.metadata/.plugins/org.eclipse.core.resources/.history/85/c0b1157e6ca3001e1d98c762f0e1eac2

https://bitbucket.org/fixpoint/connexion
#! | 40 lines | 34 code | 6 blank | 0 comment | 0 complexity | a3388ad7b0b3e83a8c8410f830578b02 MD5 | raw file
 1package info.reflectionsofmind.connexion.util;
 2
 3import java.util.ArrayList;
 4import java.util.List;
 5import java.util.concurrent.BlockingQueue;
 6import java.util.concurrent.Callable;
 7import java.util.concurrent.Executors;
 8import java.util.concurrent.Future;
 9import java.util.concurrent.SynchronousQueue;
10
11public class Waiter<T>
12{
13	private final List<BlockingQueue<T>> queues = new ArrayList<BlockingQueue<T>>();
14
15	public Waiter()
16	{
17	}
18
19	public void put(final T object)
20	{
21		for (final BlockingQueue<T> queue : this.queues)
22		{
23			queue.offer(object);
24		}
25	}
26
27	public Future<T> get()
28	{
29		final BlockingQueue<T> queue = new SynchronousQueue<T>();
30		this.queues.add(queue);
31
32		return Executors.newSingleThreadExecutor().submit(new Callable<T>()
33				{
34			public T call() throws Exception
35			{
36				return queue.take();
37			}
38				});
39	}
40}