當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。