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


Java BlockingQueue.add方法代码示例

本文整理汇总了Java中java.util.concurrent.BlockingQueue.add方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingQueue.add方法的具体用法?Java BlockingQueue.add怎么用?Java BlockingQueue.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.BlockingQueue的用法示例。


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

示例1: output

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Output the items in the stream with a function.
 * This method will block until the result returns.
 * Eg. `output(StatisticOperators.count())` will output the number of items.
 *
 * @param itemsCollector the function used to output current stream
 * @param <Tout> the type of the result
 * @return the result
 * @throws PSException if failed to the result.
 */
@PSAction(blocking = true)
public <Tout> Tout output(Function<List<Item>, Tout> itemsCollector) throws PSException {
    final BlockingQueue<Object> resultQueue = new LinkedBlockingQueue<>();
    Callback<Tout> resultHandler = new Callback<Tout>() {
        @Override
        protected void onInput(Tout input) {
            resultQueue.add(input);
        }

        @Override
        protected void onFail(PSException exception) {
            resultQueue.add(exception);
        }
    };
    this.output(itemsCollector, resultHandler);
    try {
        Object resultOrException = resultQueue.take();
        if (resultOrException instanceof PSException) {
            throw (PSException) resultOrException;
        }
        return (Tout) resultOrException;
    } catch (InterruptedException e) {
        throw PSException.INTERRUPTED(e.getMessage());
    }
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:36,代码来源:PStream.java

示例2: processMessage

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void processMessage(String taskId, SimpleMessage message, boolean request)
{
	synchronized( stateMutex )
	{
		if( request )
		{
			Task task = runningTasks.get(taskId);
			if( task != null )
			{
				task.postMessage(message);
			}
		}
		else
		{
			BlockingQueue<SimpleMessage> waitingQueue = messageResponses.getIfPresent(message.getMessageId());
			if( waitingQueue != null )
			{
				messageResponses.invalidate(message.getMessageId());
				waitingQueue.add(message);
			}
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:24,代码来源:LocalTaskServiceImpl.java

示例3: testDelayQueue

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
void testDelayQueue(final BlockingQueue q) throws Throwable {
    System.err.println(q.getClass().getSimpleName());
    for (int i = 0; i < CAPACITY; i++)
        q.add(new PDelay(i));
    ArrayBlockingQueue q2 = new ArrayBlockingQueue(SMALL);
    try {
        q.drainTo(q2, SMALL + 3);
        fail("should throw");
    } catch (IllegalStateException success) {
        equal(SMALL, q2.size());
        equal(new PDelay(0), q2.poll());
        equal(new PDelay(1), q2.poll());
        check(q2.isEmpty());
        for (int i = SMALL; i < CAPACITY; i++)
            equal(new PDelay(i), q.poll());
        equal(0, q.size());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DrainToFails.java

示例4: main

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {

        BlockingQueue<String> queue = new ArrayBlockingQueue<>(1);

        queue.add("add");

        //
        String peek = queue.peek();
        System.out.println(peek);

        queue.poll();
        boolean offer = queue.offer("offer");
        if (!offer) {
            System.out.println("it is't possible to do so immediately");
        }
        System.out.println(queue.take());

        queue.put("put operation");
        System.out.println(queue.take());
    }
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:21,代码来源:ArrayBlockingQueueExample.java

示例5: test06

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Test
public void test06() throws Exception {
    BlockingQueue<String> queue = new LinkedBlockingQueue<>();
    queue.add("1");
    queue.add("2");
    queue.add("3");

    System.out.println(queue.poll());
    queue.add("4");
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
}
 
开发者ID:jt120,项目名称:take,代码行数:15,代码来源:TakeTest.java

示例6: spawnNewTask

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private static void spawnNewTask(StateContext context, BlockingQueue<Continuation> workQueue) {
  Continuation cont = RuntimeCallInitialiser.forState(context)
      .newCall(FN_INSTANCE, nextId.getAndIncrement(), workQueue);
  assert (cont != null);
  numLive.incrementAndGet();
  workQueue.add(cont);
}
 
开发者ID:kroepke,项目名称:luna,代码行数:8,代码来源:SimpleMultiThreadedAsync.java

示例7: addsAndRemoves

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Benchmark void addsAndRemoves(int reps) {
  int capacity = this.capacity;
  BlockingQueue<String> queue = this.queue;
  String[] strings = this.strings;
  for (int i = 0; i < reps; i++) {
    for (int j = 0; j < capacity; j++) {
      queue.add(strings[j]);
    }
    for (int j = 0; j < capacity; j++) {
      queue.remove();
    }
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:MonitorBenchmark.java

示例8: processResponse

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private boolean processResponse(SimpleMessage message)
{
	BlockingQueue<SimpleMessage> waitingQueue = messageResponses.getIfPresent(message.getMessageId());
	if( waitingQueue != null )
	{
		messageResponses.invalidate(message.getMessageId());
		waitingQueue.add(message);
		return true;
	}
	return false;
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:ClusteredTaskServiceImpl.java

示例9: addWaiter

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public synchronized void addWaiter(BlockingQueue<Object> queue)
{
	if( finished )
	{
		queue.add(this);
	}
	else
	{
		waitingList.put(queue, queue);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:AbstractBeanLocatorCallable.java

示例10: finished

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public synchronized void finished()
{
	finished = true;
	locator.clearCallable();
	for( BlockingQueue<Object> waiter : waitingList.keySet() )
	{
		waiter.add(this);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:10,代码来源:AbstractBeanLocatorCallable.java

示例11: Drone

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Creates a drone based on a sprite
 * @param uiUpdates - uiupdates
 * @param image - Path to the sprite image
 */
Drone(BlockingQueue<UIUpdate> uiUpdates, String image) {
    super(uiUpdates, image);
    new SpriteAnimation(imageView, Duration.millis(200), DRONE_SPRITE_COLUMNS, DRONE_SPRITE_COLUMNS, 0, 0, Settings.SPRITE_WIDTH, Settings.SPRITE_HEIGTH).play();
    heightText = new Text(0, 20, "Height: 0");
    heightText.setFill(Color.WHITE);
    imageView.setFitHeight(Settings.DRONE_HEIGHT);
    imageView.setFitWidth(Settings.DRONE_WIDTH);
    imageView.setId("drone");
    currentHP = -1;
    uiUpdates.add(new AddDrone(heightText));
}
 
开发者ID:INAETICS,项目名称:Drones-Simulator,代码行数:17,代码来源:Drone.java

示例12: createTempQueueAndAddEvent

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private BlockingQueue<GatewaySenderEventImpl> createTempQueueAndAddEvent(
    ParallelGatewaySenderEventProcessor pgsep, GatewaySenderEventImpl gsei) {
  ParallelGatewaySenderQueue pgsq = (ParallelGatewaySenderQueue) pgsep.getQueue();
  Map<Integer, BlockingQueue<GatewaySenderEventImpl>> tempQueueMap =
      pgsq.getBucketToTempQueueMap();
  BlockingQueue<GatewaySenderEventImpl> tempQueue = new LinkedBlockingQueue();
  when(gsei.getShadowKey()).thenReturn(KEY);
  tempQueue.add(gsei);
  tempQueueMap.put(BUCKET_ID, tempQueue);
  return tempQueue;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:12,代码来源:ParallelQueueRemovalMessageJUnitTest.java

示例13: testEmptyFull

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Queue transitions from empty to full when elements added
 */
public void testEmptyFull() {
    BlockingQueue q = populatedQueue(0, 2, 2, false);
    assertTrue(q.isEmpty());
    assertEquals(2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.offer(two));
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ArrayBlockingQueueTest.java

示例14: testRemoveElement

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * remove(x) removes x and returns true if present
 * TODO: move to superclass CollectionTest.java
 */
public void testRemoveElement() {
    final BlockingQueue q = emptyCollection();
    final int size = Math.min(q.remainingCapacity(), SIZE);
    final Object[] elts = new Object[size];
    assertFalse(q.contains(makeElement(99)));
    assertFalse(q.remove(makeElement(99)));
    checkEmpty(q);
    for (int i = 0; i < size; i++)
        q.add(elts[i] = makeElement(i));
    for (int i = 1; i < size; i += 2) {
        for (int pass = 0; pass < 2; pass++) {
            assertEquals((pass == 0), q.contains(elts[i]));
            assertEquals((pass == 0), q.remove(elts[i]));
            assertFalse(q.contains(elts[i]));
            assertTrue(q.contains(elts[i - 1]));
            if (i < size - 1)
                assertTrue(q.contains(elts[i + 1]));
        }
    }
    if (size > 0)
        assertTrue(q.contains(elts[0]));
    for (int i = size - 2; i >= 0; i -= 2) {
        assertTrue(q.contains(elts[i]));
        assertFalse(q.contains(elts[i + 1]));
        assertTrue(q.remove(elts[i]));
        assertFalse(q.contains(elts[i]));
        assertFalse(q.remove(elts[i + 1]));
        assertFalse(q.contains(elts[i + 1]));
    }
    checkEmpty(q);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:BlockingQueueTest.java

示例15: convertVideoToImages

import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
 * Converts the specified video file to a series of images and adds them to
 * the given shared queue. 
 * 
 * @param f the video file
 * @param singleImage whether just a single preview image is required
 * @param sharedQueue the shared processing queue
 * @throws IOException if there is a problem loading the media file
 * @throws InterruptedException if loading is interupted
 */
public void convertVideoToImages(File f, boolean singleImage, final BlockingQueue<Image> sharedQueue, VideoLoadedLock videoLoadedLock) throws IOException, InterruptedException {
	EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
	JWindow frame = new JWindow();
	frame.setBounds(0,0,1,1);
	frame.add(mediaPlayerComponent);
	frame.setVisible(true);
	final MediaPlayer player = mediaPlayerComponent.getMediaPlayer();
	player.mute();
	player.playMedia(f.getAbsolutePath());
	long len = player.getLength();
	if (len == 0) {
		Thread.sleep(MEDIA_PRELOAD_WAIT);
		len = player.getLength();
	}
	int singleImageSelectionTime = -1;
	if (singleImage) {
		singleImageSelectionTime = new Random().nextInt(RANDOM_INTRO_WAIT) + MINIMUM_INTRO_WAIT;
		if (singleImageSelectionTime > len) {
			singleImageSelectionTime = (int) len-1;
		}
	}
	frame.setVisible(false);
	log.debug("Player time: {}, Len: {}", player.getTime(), len);
	videoLoadedLock.preloadFinished();
	try {
		while (player.getTime() < len) {
			if (cancel) {
				break;
			}
			
			// Always add images if we don't want a single preview
			// image or when the time exceeds the point we want a
			// single image from
			if (singleImageSelectionTime == -1 || player.getTime() >= singleImageSelectionTime) {
				sharedQueue.add(player.getSnapshot());

				// We only want one image if single image selection
				// is turned on
				if (singleImageSelectionTime != -1 && player.getTime() >= singleImageSelectionTime) {
					break;
				}
			}
		}
	} finally {
		player.stop();
		player.release();
		mediaPlayerComponent.release();
		cancel = false;
	}
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:61,代码来源:VLCVideoImportEngine.java


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