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


Java IQueue类代码示例

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


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


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