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

Java IQueue类代码示例

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

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



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

示例1: run

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private static void run() {

        Config config = new Config("queueTest");

        HazelcastInstance hzInstance = Hazelcast.newHazelcastInstance(config);

        IQueue<Integer> queue = hzInstance.getQueue(QNAME);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 2000000) {
            if (i % 10000 == 0) {
                logger.info(Integer.toString(i) + "\t" + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }
            queue.add(i);
        }
    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:20,代码来源:Test1.java


示例2: pollAndProcess

import com.hazelcast.core.IQueue; //导入依赖的package包/类
/**
 * Polls the response queue and processes the received events. If no events are received this operation times out.
 */
private boolean pollAndProcess(final Set<String> processedKeys, final String syncRequestId, final IQueue<Event> responseQueue)
        throws InterruptedException, SyncFailureException {

    final Event event = responseQueue.poll(timeout, TimeUnit.MILLISECONDS);
    if (event != null) {
        if (event.id().equals(syncRequestId)) {
            // Sync completed
            return true;
        } else {
            processEvent(event, processedKeys);
        }
    } else {
        // No response - unable to sync
        throw new SyncFailureException("Unable to sync, no response from queue");
    }
    return false;
}
 
开发者ID:wassgren,项目名称:NoMQ,代码行数:21,代码来源:EventSynchronizer.java


示例3: drainTo

import com.hazelcast.core.IQueue; //导入依赖的package包/类
public int drainTo(Collection<? super E> objects, int i) {
    if (objects == null) throw new NullPointerException("drainTo null!");
    if (i < 0) throw new IllegalArgumentException("Negative maxElements:" + i);
    if (i == 0) return 0;
    if (objects instanceof IQueue) {
        if (((IQueue) objects).getName().equals(getName())) {
            throw new IllegalArgumentException("Cannot drainTo self!");
        }
    }
    E e;
    int counter = 0;
    while (counter < i && (e = poll()) != null) {
        objects.add(e);
        counter++;
    }
    return counter;
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:18,代码来源:QueueClientProxy.java


示例4: testQueuePoll

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Test
public void testQueuePoll() throws InterruptedException {
    HazelcastClient hClient = getHazelcastClient();
    final CountDownLatch cl = new CountDownLatch(1);
    final IQueue<String> queue = hClient.getQueue("testQueuePoll");
    assertTrue(queue.offer("a"));
    assertEquals("a", queue.poll());
    new Thread(new Runnable() {

        public void run() {
            try {
                Thread.sleep(100);
                assertEquals("b", queue.poll(100, TimeUnit.MILLISECONDS));
                cl.countDown();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }).start();
    Thread.sleep(50);
    assertTrue(queue.offer("b"));
    assertTrue(cl.await(200, TimeUnit.MILLISECONDS));
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:24,代码来源:HazelcastClientQueueTest.java


示例5: iterator

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Test
public void iterator() {
    HazelcastClient hClient = getHazelcastClient();
    IQueue<String> queue = hClient.getQueue("iterator");
    assertTrue(queue.isEmpty());
    int count = 100;
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < count; i++) {
        queue.offer("" + i);
        map.put(i, 1);
    }
    Iterator<String> it = queue.iterator();
    while (it.hasNext()) {
        String o = it.next();
        map.put(Integer.valueOf(o), map.get(Integer.valueOf(o)) - 1);
    }
    for (int i = 0; i < count; i++) {
        assertTrue(map.get(i) == 0);
    }
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:21,代码来源:HazelcastClientQueueTest.java


示例6: removeAll

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Test
public void removeAll() {
    HazelcastClient hClient = getHazelcastClient();
    IQueue<String> queue = hClient.getQueue("removeAll");
    assertTrue(queue.isEmpty());
    int count = 100;
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < count; i++) {
        queue.offer("" + i);
        map.put(i, 1);
    }
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < count / 2; i++) {
        list.add(String.valueOf(i));
    }
    queue.removeAll(list);
    assertTrue(queue.size() == count / 2);
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:19,代码来源:HazelcastClientQueueTest.java


示例7: testIterator

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Test
public void testIterator() {
    HazelcastClient hClient = getHazelcastClient();
    IQueue<String> queue = hClient.getQueue("testIterator");
    assertTrue(queue.isEmpty());
    int count = 100;
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < count; i++) {
        queue.offer("" + i);
        map.put(i, 1);
    }
    Iterator<String> it = queue.iterator();
    while (it.hasNext()) {
        String item = it.next();
        map.remove(Integer.valueOf(item));
        it.remove();
    }
    assertEquals(0, queue.size());
    assertEquals(0, map.size());
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:21,代码来源:HazelcastClientQueueTest.java


示例8: setup

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Setup
@SuppressWarnings("unchecked")
public void setup() {
    queues = new IQueue[queueLength];

    // the KeyLocality has to be RANDOM here, since we need different queues on each Worker
    String[] names = generateStringKeys(name, queueLength, name.length() + 5, RANDOM, targetInstance);
    for (int i = 0; i < queues.length; i++) {
        queues[i] = targetInstance.getQueue(names[i]);
    }

    for (IQueue<Long> queue : queues) {
        for (int i = 0; i < messagesPerQueue; i++) {
            queue.add(0L);
        }
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:18,代码来源:QueueTest.java


示例9: run

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Override
public void run() {
  IQueue<String> demoQueue = hazelcastInstance.getQueue("demo.queue");
  while (!shutdown) {
    String data = null;
    try {
      data = demoQueue.poll(2, TimeUnit.SECONDS);
    }
    catch (InterruptedException ex) {
      // ignore
    }
    if (data != null) {
      log.info("Read data: {}", data);
    }
  }
}
 
开发者ID:mpilone,项目名称:hazelcastmq,代码行数:17,代码来源:DemoQueueReader.java


示例10: testHazelcast

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Bean
public Object testHazelcast(HazelcastInstance inst) throws Exception {

	ConcurrentMap aMap = inst.getMap("cz.rkr");
	aMap.put("initialValue1", "val1");
	aMap.put("initialValue2", "val2");
	aMap.put("initialValue3", "val3");
	aMap.put("initialValue4", "val4");
	aMap.put("initialValue5", "val5");

	IQueue<String> queueCustomers = inst.getQueue("cz.eetlite");
	queueCustomers.offer("Tom");
	queueCustomers.offer("Mary");
	queueCustomers.offer("Jane");
	System.out.println("First customer: " + queueCustomers.poll());
	System.out.println("Second customer: " + queueCustomers.peek());
	System.out.println("Second customer: " + queueCustomers.peek());
	System.out.println("First customer: " + queueCustomers.poll());
	System.out.println("First customer: " + queueCustomers.poll());

	System.out.println("Queue size: " + queueCustomers.size());

	queueCustomers.put("TEST");
	System.out.println("Queue size: " + queueCustomers.size());
	System.out.println("take: " + queueCustomers.take());
	System.out.println("Queue size: " + queueCustomers.size());
	return aMap;
}
 
开发者ID:eetlite,项目名称:eet.osslite.cz,代码行数:29,代码来源:HazelcastConfiguration.java


示例11: getIQueue

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <E> IQueue<E> getIQueue(String name)
{
    name = Objects.requireNonNull(name);

    final IQueue<E> valu = getBeanSafely(name, IQueue.class);

    if (null != valu)
    {
        return valu;
    }
    return hz().getQueue(name);
}
 
开发者ID:ahome-it,项目名称:ahome-tooling-server-hazelcast,代码行数:15,代码来源:HazelcastContextInstance.java


示例12: awaitEmpty

import com.hazelcast.core.IQueue; //导入依赖的package包/类
public void awaitEmpty( IQueue<?> queue ) throws InterruptedException{
    synchronized( monitor ){
        if( !queue.isEmpty() ){
            monitor.wait();
        }
    }
}
 
开发者ID:zutnop,项目名称:telekom-workflow-engine,代码行数:8,代码来源:HazelcastWorkQueue.java


示例13: run

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private static void run() {

        Config config = new Config("queueTest");

        QueueConfig queueConfig = config.getQueueConfig(QNAME);

        QueueStoreConfig queueStoreConfig = new QueueStoreConfig();
        queueStoreConfig.setEnabled(true);
        queueStoreConfig.setStoreImplementation(new MockQueueStore());
        queueStoreConfig.getProperties().setProperty("memory-limit", "0");

        queueConfig.setQueueStoreConfig(queueStoreConfig);

        HazelcastInstance hzInstance = Hazelcast.newHazelcastInstance(config);

        IQueue<Integer> queue = hzInstance.getQueue(QNAME);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 2000000) {
            if (i % 10000 == 0) {
                logger.info(Integer.toString(i) + "\t" + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }
            queue.add(i);
        }
    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:29,代码来源:Test2.java


示例14: consume

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private static void consume(HazelcastInstance hazelcastInstance) {
   IQueue<String> cola = hazelcastInstance.getQueue("cola");
   while (true){
      try {
         System.out.println("Taken from queue: "+cola.take());
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }
   
}
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:12,代码来源:AtomicExample.java


示例15: produce

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private static void produce(HazelcastInstance hazelcastInstance) {
   IQueue<String> cola = hazelcastInstance.getQueue("cola");
   
   int count=0;
   while (true){
      try {
         cola.offer(Integer.toString(count++));
         Thread.sleep(1000);
         System.out.println("Added to queue. It has now "+cola.size());
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }
}
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:15,代码来源:AtomicExample.java


示例16: sendSyncResponse

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private void sendSyncResponse(final String syncId, final String replayFromId) {
    final IQueue<Event> queue = hz.getQueue(syncId);

    replayStream(replayFromId).forEach(event -> {
        try {
            queue.put(event);
        } catch (InterruptedException e) {
            throw new IllegalStateException("Unable to respond to sync request", e);
        }
    });
}
 
开发者ID:wassgren,项目名称:NoMQ,代码行数:12,代码来源:EventSynchronizer.java


示例17: waitForSyncResponse

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private void waitForSyncResponse(final Set<String> processedKeys, final String syncRequestId) throws SyncFailureException {
    // Wait/handle the response
    try {
        // The response queue uses the same name as the entire sync-operation
        final IQueue<Event> responseQueue = hz.getQueue(syncRequestId);

        while (true) {
            if (pollAndProcess(processedKeys, syncRequestId, responseQueue)) {
                break;
            }
        }
    } catch (final InterruptedException e) {
        throw new IllegalStateException("Interrupted", e);
    }
}
 
开发者ID:wassgren,项目名称:NoMQ,代码行数:16,代码来源:EventSynchronizer.java


示例18: hzConsumeCommandsRoute

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Provides
@Singleton
public HzConsumeCommandsRoute hzConsumeCommandsRoute(
        @Named("commandsDestinationUri") String commandsDestinationUri,
        HzInventoryItemCmdProcessor inventoryItemCmdProcessor,
        IQueue<UUID> eventsQueue) {
    return new HzConsumeCommandsRoute(commandsDestinationUri, inventoryItemCmdProcessor, eventsQueue);
    
}
 
开发者ID:rodolfodpk,项目名称:myeslib,代码行数:10,代码来源:CamelModule.java


示例19: hzConsumeEventsRoute

import com.hazelcast.core.IQueue; //导入依赖的package包/类
@Provides
@Singleton
public HzConsumeEventsRoute hzConsumeEventsRoute(
        SnapshotReader<UUID, InventoryItemAggregateRoot> snapshotReader,
        IMap<UUID, Snapshot<InventoryItemAggregateRoot>> lastSnapshotMap,
        IQueue<UUID> eventsQueue) {
    return new HzConsumeEventsRoute(eventsQueueConsumers, snapshotReader, lastSnapshotMap, eventsQueue);
}
 
开发者ID:rodolfodpk,项目名称:myeslib,代码行数:9,代码来源:CamelModule.java


示例20: startIdProducer

import com.hazelcast.core.IQueue; //导入依赖的package包/类
private void startIdProducer() {
    producer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            IQueue<Integer> q = Hazelcast.getQueue("default");
            if (q.size() < 5000) {
                for (int i = 0; i < 5000; i++) {
                    q.offer(ids.incrementAndGet());
                }
            }
        }
    }, 0, 1000);
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:14,代码来源:LongRunningTransactionTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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