当前位置: 首页>>代码示例>>Java>>正文


Java BlockableQueue类代码示例

本文整理汇总了Java中org.magnos.util.BlockableQueue的典型用法代码示例。如果您正苦于以下问题:Java BlockableQueue类的具体用法?Java BlockableQueue怎么用?Java BlockableQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BlockableQueue类属于org.magnos.util包,在下文中一共展示了BlockableQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSize

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testSize()
{
	BlockableQueue<String> q = new BlockableQueue<String>();

	assertEquals( 0, q.size() );
	q.offer("Hello");
	assertEquals( 1, q.size() );
	q.offer("Mommy");
	assertEquals( 2, q.size() );
	q.poll();
	assertEquals( 1, q.size() );
	q.offer("Know All");
	assertEquals( 2, q.size() );
	q.poll();
	assertEquals( 1, q.size() );
	q.offer("See All");
	assertEquals( 2, q.size() );
	
	q.clear();

	assertEquals( 0, q.size() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:24,代码来源:TestBlockableQueue.java

示例2: testPeekInterrupt

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testPeekInterrupt()
{
	final AtomicReference<Thread> thread = new AtomicReference<Thread>();
	final BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(500);
	
	GroupTask.initialize(1);
	GroupTask.add(new Runnable() {
		public void run() {
			thread.set(Thread.currentThread());
			assertNull( q.peek() );
		}
	});
	GroupTask.begin();
	
	sleep(100);
	
	thread.get().interrupt();
	
	GroupTask.finish();
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:24,代码来源:TestBlockableQueue.java

示例3: testPollInterrupt

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testPollInterrupt()
{
	final AtomicReference<Thread> thread = new AtomicReference<Thread>();
	final BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(500);
	
	GroupTask.initialize(1);
	GroupTask.add(new Runnable() {
		public void run() {
			thread.set(Thread.currentThread());
			assertNull( q.poll() );
		}
	});
	GroupTask.begin();
	
	sleep(100);
	
	thread.get().interrupt();
	
	GroupTask.finish();
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:24,代码来源:TestBlockableQueue.java

示例4: testNonblocking

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testNonblocking()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(false);
	
	assertTrue( q.offer("Hello") );
	assertTrue( q.offer("World") );

	assertEquals( "Hello", q.peek() );
	assertEquals( "Hello", q.poll() );
	
	assertEquals( "World", q.peek() );
	assertEquals( "World", q.poll() );
	
	assertNull( q.poll() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:18,代码来源:TestBlockableQueue.java

示例5: testIsBlocking

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testIsBlocking()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	
	q.setBlocking(true);
	assertTrue( q.isBlocking() );
	
	q.setBlocking(false);
	assertFalse( q.isBlocking() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:12,代码来源:TestBlockableQueue.java

示例6: testIterator

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testIterator()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.offer("Hello");
	q.offer("World");
	
	Iterator<String> iter = q.iterator();
	assertEquals( "Hello", iter.next() );
	assertEquals( "World", iter.next() );
	assertFalse( iter.hasNext() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:13,代码来源:TestBlockableQueue.java

示例7: testTimeout

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testTimeout()
{
	BlockableQueue<String> q = new BlockableQueue<String>();

	q.setTimeout(100);
	assertEquals( 100, q.getTimeout() );
	
	q.setTimeout(2, TimeUnit.SECONDS);
	assertEquals( 2000, q.getTimeout() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:12,代码来源:TestBlockableQueue.java

示例8: testPeekTimeout

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testPeekTimeout()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(100);
	
	assertNull( q.peek() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:10,代码来源:TestBlockableQueue.java

示例9: testPollTimeout

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testPollTimeout()
{
	BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	q.setTimeout(100);
	
	assertNull( q.poll() );
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:10,代码来源:TestBlockableQueue.java

示例10: testWakeup

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testWakeup()
{
	final BlockableQueue<String> q = new BlockableQueue<String>();
	q.setBlocking(true);
	
	GroupTask.initialize(1);
	GroupTask.add(new Runnable() {
		public void run() {
			sleep(500);
			q.wakeup();
			sleep(500);
			q.wakeup();
		}
	});
	GroupTask.begin();
	
	watch.start("Before poll...");
	assertNull( null, q.poll() );
	watch.stop(" poll awoken (%.3f), done.\n");
	
	watch.start("Before peek...");
	assertNull( null, q.peek() );
	watch.stop(" peek awoken (%.3f), done.\n");
	
	GroupTask.finish();
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:28,代码来源:TestBlockableQueue.java

示例11: Service

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
/**
 * Instantiates a new Service given a queue to poll and offer events to.
 * 
 * @param eventQueue
 * 		The queue of events.
 */
public Service(BlockableQueue<E> eventQueue) 
{
	this.eventQueue = eventQueue;
	this.notifier = Notifier.create(ServiceListener.class);
	this.release = new Release();
	this.release.getBlockers().add(this);
	this.state.set(Stopped);
}
 
开发者ID:ClickerMonkey,项目名称:Surfice,代码行数:15,代码来源:Service.java

示例12: testSingleReaderManyWriters

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testSingleReaderManyWriters()
{
	final int MESSAGES = 10000;
	final int WRITERS = 10;
	final int MESSAGES_PER_WRITER = MESSAGES / WRITERS;
	
	final AtomicInteger nullCounter = new AtomicInteger();
	final BlockableQueue<Integer> q = new BlockableQueue<Integer>();
	q.setBlocking(true);
	
	Runnable reader = new Runnable() {
		public void run() {
			int total = 0;
			double minWait = Double.MAX_VALUE;
			double maxWait = -Double.MAX_VALUE;
			Stopwatch watch = new Stopwatch();
			while (total < MESSAGES) {
				watch.start();
				Integer value = q.poll();
				watch.stop();
				if (value != null) {
					minWait = Math.min(minWait, watch.seconds());
					maxWait = Math.max(maxWait, watch.seconds());
					total++;	
				} else {
					nullCounter.incrementAndGet();
				}
			}
			System.out.format("Wait: min[%.6fs] max[%.6fs]\n", minWait, maxWait);
		}
	};
	
	Runnable writer = new Runnable() {
		public void run() {
			for (int i = 0; i < MESSAGES_PER_WRITER; i++) {
				assertTrue( q.offer(i) );
				// Causes the reader to wait some amount of time
				sleep(1);
			}
		}
	};
	
	GroupTask.initialize(WRITERS + 1);
	GroupTask.add(writer, WRITERS);
	GroupTask.add(reader);
	GroupTask.execute();
	
	System.out.println("Null polls: " + nullCounter.get());
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:51,代码来源:TestBlockableQueue.java

示例13: testSingleWriterManyReads

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
@Test
public void testSingleWriterManyReads()
{
	final int MESSAGES = 10000;
	final int READERS = 10;
	final int MESSAGES_PER_READER = MESSAGES / READERS;

	final AtomicInteger nullCounter = new AtomicInteger();
	final BlockableQueue<Integer> q = new BlockableQueue<Integer>();
	q.setBlocking(true);
	
	Runnable reader = new Runnable() {
		public void run() {
			int total = 0;
			double minWait = Double.MAX_VALUE;
			double maxWait = -Double.MAX_VALUE;
			Stopwatch watch = new Stopwatch();
			while (total < MESSAGES_PER_READER) {
				watch.start();
				Integer value = q.poll();
				watch.stop();
				if (value != null) {
					minWait = Math.min(minWait, watch.seconds());
					maxWait = Math.max(maxWait, watch.seconds());
					total++;	
				} else {
					nullCounter.incrementAndGet();
				}
			}
			System.out.format("Wait: min[%.6fs] max[%.6fs]\n", minWait, maxWait);
		}
	};
	
	Runnable writer = new Runnable() {
		public void run() {
			for (int i = 0; i < MESSAGES; i++) {
				assertTrue( q.offer(i) );
			}
		}
	};
	
	GroupTask.initialize(READERS + 1);
	GroupTask.add(reader, READERS);
	GroupTask.add(writer);
	GroupTask.execute();
	
	System.out.println("Null polls: " + nullCounter.get());
}
 
开发者ID:ClickerMonkey,项目名称:Curity,代码行数:49,代码来源:TestBlockableQueue.java

示例14: TaskService

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
/**
 * Instantiates a new TaskService.
 * 
 * @param eventQueue
 * 		The queue of events to poll from.
 */
public TaskService(BlockableQueue<Task<?>> eventQueue) 
{
	super(eventQueue);
}
 
开发者ID:ClickerMonkey,项目名称:Taskaroo,代码行数:11,代码来源:TaskService.java

示例15: getEventQueue

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
/**
 * The queue of events which have been added to the service. Events should
 * not be directly added to this queue unless you mean to purposely bypass
 * all logic imposed by several properties of this Service.
 * 
 * @return
 * 		The reference to the event queue.
 */
public BlockableQueue<E> getEventQueue() 
{
	return eventQueue;
}
 
开发者ID:ClickerMonkey,项目名称:Surfice,代码行数:13,代码来源:Service.java


注:本文中的org.magnos.util.BlockableQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。