Java Code Examples for org.redisson.api.RBlockingQueue#take()

The following examples show how to use org.redisson.api.RBlockingQueue#take() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileConverQueueTask.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    while (true) {
        try {
            final RBlockingQueue<String> queue = redissonClient.getBlockingQueue(FileConverQueueTask.queueTaskName);
            String url = queue.take();
            if(url!=null){
                FileAttribute fileAttribute=fileUtils.getFileAttribute(url);
                logger.info("正在处理转换任务,文件名称【{}】",fileAttribute.getName());
                FileType fileType=fileAttribute.getType();
                if(fileType.equals(FileType.compress) || fileType.equals(FileType.office)){
                    FilePreview filePreview=previewFactory.get(url);
                    filePreview.filePreviewHandle(url,new ExtendedModelMap());
                }
            }
        } catch (Exception e) {
            try {
                Thread.sleep(1000*10);
            }catch (Exception ex){
                ex.printStackTrace();
            }
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTakeInterrupted() throws InterruptedException {
    final AtomicBoolean interrupted = new AtomicBoolean();
    
    Thread t = new Thread() {
        public void run() {
            try {
                RBlockingQueue<Integer> queue1 = getQueue(redisson);
                queue1.take();
            } catch (InterruptedException e) {
                interrupted.set(true);
            }
        };
    };

    t.start();
    t.join(1000);

    t.interrupt();
    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(interrupted);

    RBlockingQueue<Integer> q = getQueue(redisson);
    q.add(1);
    Thread.sleep(1000);
    assertThat(q.contains(1)).isTrue();
}
 
Example 3
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTake() throws InterruptedException {
    RBlockingQueue<Integer> queue1 = getQueue();
    Executors.newSingleThreadScheduledExecutor().schedule(() -> {
        RBlockingQueue<Integer> queue = getQueue();
        try {
            queue.put(3);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }, 10, TimeUnit.SECONDS);

    long s = System.currentTimeMillis();
    int l = queue1.take();

    Assert.assertEquals(3, l);
    Assert.assertTrue(System.currentTimeMillis() - s > 9000);
}
 
Example 4
Source File: DefaultRedisQueue.java    From SeimiCrawler with Apache License 2.0 5 votes vote down vote up
@Override
public Request bPop(String crawlerName) {
    Request request = null;
    try {
        RBlockingQueue<Request> rBlockingQueue = getQueue(crawlerName);
        request = rBlockingQueue.take();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
    }
    return request;
}
 
Example 5
Source File: CacheServiceRedisImpl.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
@Override
public String takeQueueTask() throws InterruptedException {
    RBlockingQueue<String> queue = redissonClient.getBlockingQueue(TASK_QUEUE_NAME);
    return queue.take();
}