• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BlockableQueue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: AbstractService

import org.magnos.util.BlockableQueue; //导入依赖的package包/类
/**
 * Instantiates a new AbstractService.
 * 
 * @param sourceQueue
 * 		The queue implementation to use internally as an event queue.
 */
public AbstractService(Queue<E> sourceQueue) 
{
	super(new BlockableQueue<E>(sourceQueue));
	getListeners().add(this);
}
 
开发者ID:ClickerMonkey,项目名称:Surfice,代码行数:12,代码来源:AbstractService.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ScrollOfWipeOut类代码示例发布时间:2022-05-16
下一篇:
Java SaxWriter类代码示例发布时间:2022-05-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap