@Override @SuppressWarnings("unchecked") public boolean hasNext() { try { current = (T) queue.take(); if (current instanceof Null) { current = null; } } catch (InterruptedException e) { current = null; } log.trace("hasNext; current: {}", current); return current != null; }
private void take(Exchange exchange) throws InterruptedException { exchange.getOut().setBody(this.queue.take()); }
public void run() { IQueue queue = hazelcast.getQueue("myQ"); try { queue.take(); } catch (InterruptedException e) { throw new RuntimeException(e); } } }, 10);
@Override public void run() { System.out.println((System.currentTimeMillis() - lastLap) + " Start receiving msgs"); for (int i = 1; i < TOTAL + 1; ++i) { try { Object msg = queue.take(); if (i % LAP == 0) { final long lapTime = System.currentTimeMillis() - lastLap; System.out.printf("<- messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime)); lastLap = System.currentTimeMillis(); } } catch (InterruptedException e) { e.printStackTrace(); } } } };
public static void main(String[] args) throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IQueue<Integer> queue = hz.getQueue("queue"); while (true) { int item = queue.take(); System.out.println("Consumed: " + item); if (item == -1) { queue.put(-1); break; } Thread.sleep(5000); } System.out.println("Consumer Finished!"); } }
protected void handleQTake(String[] args) { try { println(getQueue().take()); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
protected void handleQTake(String[] args) { try { println(getQueue().take()); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
protected void handleQTake(String[] args) { try { println(getQueue().take()); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
protected void handleQTake(String[] args) { try { println(getQueue().take()); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
public static void main(String[] args) throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IQueue<Integer> queue = hz.getQueue("queue"); while (true) { int item = queue.take(); System.out.println("Consumed: " + item); if (item == -1) { queue.put(-1); break; } Thread.sleep(5000); } System.out.println("Consumer Finished!"); } }
@Override public void response(String address, Consumer<String> consumer) { new Thread(() -> { try { while (hazelcastAdapter.isActive()) { String message = (String) hazelcastAdapter.getHazelcastInstance().getQueue(address).take(); logger.trace("[MQ] response {}:{}", address, message); consumer.accept(message); } } catch (HazelcastClientNotActiveException e) { if (hazelcastAdapter.isActive()) { logger.error("Hazelcast Response error.", e); } } catch (Exception e) { logger.error("Hazelcast Response error.", e); } }).start(); }
@Override public void run() { while (true) { try { DecodedDeviceRequest<?> payload = getEventQueue().take(); EventProcessingLogic.processRawPayload(HazelcastQueueReceiver.this, payload, null); LOGGER.debug("Processed event from " + payload.getHardwareId() + " from Hazelcast event queue."); } catch (InterruptedException e) { LOGGER.warn("Hazelcast queue processor interrupted."); return; } } } }
@Override public void run() { long iter = 0; while (!testContext.isStopped()) { try { workQueue.take(); consumed.incrementAndGet(); Thread.sleep(rand.nextInt(maxIntervalMillis) * producerCount); iter++; if (iter % 20 == 0) { logState(iter); } } catch (Exception e) { throw new RuntimeException(e); } } }
@Override protected void doResponse(String address, Consumer<String> consumer) { try { while (hazelcastAdapter.isActive()) { String message = (String) hazelcastAdapter.getHazelcastInstance().getQueue(address).take(); consumer.accept(message); } } catch (HazelcastClientNotActiveException e) { if (hazelcastAdapter.isActive()) { logger.error("Hazelcast Response error.", e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.error("Hazelcast Response error.", e); } }
@TimeStep(executionGroup = "consumer") public void consume(ConsumerState state) throws Exception { Long item = workQueue.take(); if (item.equals(-1L)) { workQueue.add(item); throw new StopException(); } state.consumed++; Thread.sleep(state.randomInt(maxIntervalMillis)); }
@Override public void run() { try { long iteration = 0; while (!testContext.isStopped()) { long item = fromQueue.take(); toQueue.put(item + 1); iteration++; } toQueue.put(0L); totalCounter.addAndGet(iteration); } catch (InterruptedException e) { throw rethrow(e); } } }
@Override public void run() { try { long iteration = 0; while (!testContext.isStopped()) { long item = fromQueue.take(); toQueue.put(item + 1); if (iteration % 200 == 0) { log.info(Thread.currentThread().getName() + " At iteration: " + iteration+" fromQueue size="+fromQueue.size()+", toQueue size="+toQueue.size()); } iteration++; } toQueue.put(0L); totalCounter.addAndGet(iteration); } catch (InterruptedException e) { throw new RuntimeException(e); } } }