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


Java IQueue.poll方法代码示例

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


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

示例1: 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

示例2: 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

示例3: run

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

        HazelcastInstance hzInstance1 = Hazelcast.newHazelcastInstance();
        HazelcastInstance hzInstance2 = Hazelcast.newHazelcastInstance();

        String hz1PartitionKey = hzInstance1.getPartitionService()
                .randomPartitionKey();
        String queueName = QNAME + "@" + hz1PartitionKey;

        // who is queue owner?

        HazelcastInstance ownerInstance;
        HazelcastInstance secondInstance;

        Partition partition = hzInstance1.getPartitionService().getPartition(hz1PartitionKey);
        if (hzInstance1.getCluster().getLocalMember().equals(partition.getOwner())) {
            ownerInstance = hzInstance1;
            secondInstance = hzInstance2;
        } else {
            ownerInstance = hzInstance2;
            secondInstance = hzInstance1;
        }

        IQueue<Integer> queue = secondInstance.getQueue(queueName);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("add " + Integer.toString(i) + "\t" +
                        String.format("%8.3f", (double) (System.currentTimeMillis() -
                                startTime) / i));
            }
            queue.add(i);
        }

        startTime = System.currentTimeMillis();

        i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("poll " + Integer.toString(i) + "\t"
                        + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }
            Integer intVal = queue.poll();
            if (intVal == null || intVal.intValue() != i) {
                logger.info("Error: " + (intVal) + "!=" + i);
                System.exit(-1);
            }
        }
    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:54,代码来源:Test4_1.java

示例4: run

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

        HazelcastInstance hzInstance1 = Hazelcast.newHazelcastInstance();
        HazelcastInstance hzInstance2 = Hazelcast.newHazelcastInstance();

        String hz1PartitionKey = hzInstance1.getPartitionService()
                .randomPartitionKey();
        String queueName = QNAME + "@" + hz1PartitionKey;

        // who is queue owner?

        HazelcastInstance ownerInstance;
        HazelcastInstance secondInstance;

        Partition partition = hzInstance1.getPartitionService().getPartition(hz1PartitionKey);
        if (hzInstance1.getCluster().getLocalMember().equals(partition.getOwner())) {
            ownerInstance = hzInstance1;
            secondInstance = hzInstance2;
        } else {
            ownerInstance = hzInstance2;
            secondInstance = hzInstance1;
        }

        IQueue<Integer> queue = ownerInstance.getQueue(queueName);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("add " + Integer.toString(i) + "\t" +
                        String.format("%8.3f", (double) (System.currentTimeMillis() -
                                startTime) / i));
            }
            queue.add(i);
        }

        startTime = System.currentTimeMillis();

        i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("poll " + Integer.toString(i) + "\t"
                        + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }
            Integer intVal = queue.poll();
            if (intVal == null || intVal.intValue() != i) {
                logger.info("Error: " + (intVal) + "!=" + i);
                System.exit(-1);
            }
        }
    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:54,代码来源:Test4.java

示例5: run

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

        HazelcastInstance hzInstance1 = Hazelcast.newHazelcastInstance(createConfig("1"));
        HazelcastInstance hzInstance2 = Hazelcast.newHazelcastInstance(createConfig("2"));

        String hz1PartitionKey = hzInstance1.getPartitionService()
                .randomPartitionKey();
        String queueName = QNAME + "@" + hz1PartitionKey;

        // who is queue owner?

        HazelcastInstance ownerInstance;
        HazelcastInstance secondInstance;

        Partition partition = hzInstance1.getPartitionService().getPartition(hz1PartitionKey);
        if (hzInstance1.getCluster().getLocalMember().equals(partition.getOwner())) {
            ownerInstance = hzInstance1;
            secondInstance = hzInstance2;
        } else {
            ownerInstance = hzInstance2;
            secondInstance = hzInstance1;
        }

        IQueue<Integer> queue = ownerInstance.getQueue(queueName);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("add " + Integer.toString(i) + "\t" + String.format("%8.3f",
                        (double) (System.currentTimeMillis() -
                                startTime) / i));
            }
            queue.add(i);
        }


        ownerInstance.shutdown();
        queue = secondInstance.getQueue(queueName);

        startTime = System.currentTimeMillis();

        int breakOrder = 0;
        HashMap<Long, Integer> queueItems = new HashMap<Long, Integer>();

        i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("poll " + Integer.toString(i) + "\t"
                        + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }
            Integer intVal = queue.poll();
            if (intVal != null) {
                queueItems.put((long) i, intVal);

                if (intVal.intValue() != i) {
                    breakOrder++;
                }
            }
        }

        if (breakOrder > 0) {
            logger.info("Error: mixed order of items - " + breakOrder);
        }

        if (queueItems.size() != 100000) {
            logger.info("Error: missed queue items - " + (100000 - queueItems.size()));
        }

    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:73,代码来源:Test7.java

示例6: run

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

        HazelcastInstance hzInstance1 = Hazelcast.newHazelcastInstance();
        HazelcastInstance hzInstance2 = Hazelcast.newHazelcastInstance();

        String hz1PartitionKey = hzInstance1.getPartitionService()
                .randomPartitionKey();
        String queueName = QNAME + "@" + hz1PartitionKey;

        // who is queue owner?

        HazelcastInstance ownerInstance;
        HazelcastInstance secondInstance;

        Partition partition = hzInstance1.getPartitionService().getPartition(hz1PartitionKey);
        if (hzInstance1.getCluster().getLocalMember().equals(partition.getOwner())) {
            ownerInstance = hzInstance1;
            secondInstance = hzInstance2;
        } else {
            ownerInstance = hzInstance2;
            secondInstance = hzInstance1;
        }

        IQueue<Integer> queue = ownerInstance.getQueue(queueName);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("add " + Integer.toString(i) + "\t" +
                        String.format("%8.3f", (double) (System.currentTimeMillis() -
                                startTime) / i));
            }
            queue.add(i);
        }

        ownerInstance.shutdown();
        queue = secondInstance.getQueue(queueName);

        startTime = System.currentTimeMillis();

        i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("poll " + Integer.toString(i) + "\t"
                        + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }
            Integer intVal = queue.poll();
            if (intVal == null || intVal.intValue() != i) {
                logger.info("Error: " + (intVal) + "!=" + i);
                System.exit(-1);
            }
        }

    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:58,代码来源:Test5.java

示例7: run

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

        HazelcastInstance hzInstance1 = Hazelcast.newHazelcastInstance(createConfig("1"));
        HazelcastInstance hzInstance2 = Hazelcast.newHazelcastInstance(createConfig("2"));

        String hz1PartitionKey = hzInstance1.getPartitionService()
                .randomPartitionKey();
        String queueName = QNAME + "@" + hz1PartitionKey;

        // who is queue owner?

        HazelcastInstance ownerInstance;
        HazelcastInstance secondInstance;

        Partition partition = hzInstance1.getPartitionService().getPartition(hz1PartitionKey);
        if (hzInstance1.getCluster().getLocalMember().equals(partition.getOwner())) {
            ownerInstance = hzInstance1;
            secondInstance = hzInstance2;
        } else {
            ownerInstance = hzInstance2;
            secondInstance = hzInstance1;
        }

        IQueue<Integer> queue = ownerInstance.getQueue(queueName);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 100000) {
            if (i % 10000 == 0) {
                logger.info("add " + Integer.toString(i) + "\t" + String.format("%8.3f",
                        (double) (System.currentTimeMillis() -
                                startTime) / i));
            }
            queue.add(i);
        }


        ownerInstance.shutdown();
        queue = secondInstance.getQueue(queueName);

        Integer intVal = queue.poll();

        if (intVal != null) {
            logger.info("Error: Queue should be empty");
            System.exit(-1);
        }


    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:51,代码来源:Test6.java

示例8: runNode

import com.hazelcast.core.IQueue; //导入方法依赖的package包/类
private void runNode() throws TaskException, MessagingException, DAOException {

		System.setProperty("hazelcast.logging.type", "none");
		Config cfg = createConfig();

		HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

		IQueue<Message> queue = instance.getQueue(props.getString(HAZELCAST_QUEUE_NAME));

		long msgReceivedCnt = 0;
		long msgCorruptedCnt = 0;
		boolean isFirstMsg = true;
		long firstMsgTime = 0;
		long lastMsgTime = 0;
		long startRetries = 2;

		boolean checkMessage = props.getBoolean(NODE_CHECK_MESSAGE);

		setAddressCheckPoint(instance);

		try (CheckpointController checkpoint = CheckpointController.create()) {
			checkpoint.latchCountDown(NODE_LATCH.getPropertyName());
			checkpoint.latchWait(NODE_LATCH.getPropertyName());
		}

		try {
			while (true) {
				// TODO consider timeout as a parameter
				Message msg = queue.poll(10, TimeUnit.SECONDS);
				if (msg == null) {

					if (isFirstMsg && --startRetries > 0) {
						log.debug("Waiting for work");
						continue;
					} else if (!isFirstMsg) {
						break;
					} else {
						log.debug("Giving up");
						return;
					}
				}

				if (isFirstMsg) {
					firstMsgTime = System.nanoTime();
					isFirstMsg = false;
				}

				++msgReceivedCnt;

				if (checkMessage) {
					// "simulate work"
					if (!Message.checkMessage(msg)) {
						++msgCorruptedCnt;
					}
				}

				lastMsgTime = System.nanoTime();

			}

		} catch (InterruptedException e) {
			log.error("No value polled", e);
		} finally {
			closeHazelcastInstance(instance);
		}

		final long elapsed = lastMsgTime - firstMsgTime;
		final String nodeId = props.getString(NODE_ID);

		NodeResult result = Results.createNodeResult(props, elapsed, msgReceivedCnt);
		log.debug("{} finished in {}s", nodeId, TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));

		store(result, GROUP);

	}
 
开发者ID:ever-been,项目名称:benchmark-hazelcast3,代码行数:76,代码来源:NodeTask.java


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