@Override @SuppressWarnings("unchecked") public boolean add(T result) { boolean added = queue.offer(result); logger.trace("add; added: {}", added); return added; }
private void offer(Exchange exchange) { Object body = exchange.getIn().getBody(); this.queue.offer(body); }
public void run() { IQueue queue = hazelcast.getQueue("myQ"); queue.offer(new byte[100]); } }, 10);
public void run() { IQueue queue = hazelcast.getQueue("myQ"); try { queue.offer(new byte[100], 10, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new RuntimeException(e); } } }, 10);
@Override public boolean offer(String queueName, Object value) { return hazelcast.getQueue(queueName).offer(value); }
@Override public boolean offer(String queueName, Object value) { return hazelcast.getQueue(queueName).offer(value); }
@Transactional public void processWithTransaction() { IQueue<String> demoQueue = getQueue("demo.queue", hazelcastInstance); log.info("Offering to queue in transaction."); demoQueue.offer(getClass().getName() + ": processWithTransaction"); log.info("Sleeping."); sleep(5, TimeUnit.SECONDS); log.info("Done."); }
@Transactional public void processWithTransactionAndException() { IQueue<String> demoQueue = getQueue("demo.queue", hazelcastInstance); log.info("Offering to queue in transaction."); demoQueue.offer(getClass().getName() + ": processWithTransactionAndException"); log.info("Sleeping."); sleep(5, TimeUnit.SECONDS); log.info("Throwing exception in transaction."); throw new RuntimeException("Better roll back."); }
public void processWithoutTransaction() { IQueue<String> demoQueue = getQueue("demo.queue", hazelcastInstance); log.info("Offering to queue outside transaction."); demoQueue.offer(getClass().getName() + ": processWithoutTransaction"); log.info("Sleeping."); sleep(5, TimeUnit.SECONDS); log.info("Done."); }
protected void handleQOffer(String[] args) { long timeout = 0; if (args.length > 2) { timeout = Long.parseLong(args[2]); } try { boolean offered = getQueue().offer(args[1], timeout, TimeUnit.SECONDS); println(offered); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
protected void handleQOffer(String[] args) { long timeout = 0; if (args.length > 2) { timeout = Long.parseLong(args[2]); } try { boolean offered = getQueue().offer(args[1], timeout, TimeUnit.SECONDS); println(offered); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
@TimeStep(executionGroup = "producer") public void produce(ProducerState state) throws Exception { Thread.sleep(state.randomInt(maxIntervalMillis)); workQueue.offer(0L); state.produced++; }
protected void handleQOffer(String[] args) { long timeout = 0; if (args.length > 2) { timeout = Long.parseLong(args[2]); } try { boolean offered = getQueue().offer(args[1], timeout, TimeUnit.SECONDS); println(offered); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
protected void handleQOffer(String[] args) { long timeout = 0; if (args.length > 2) { timeout = Long.parseLong(args[2]); } try { boolean offered = getQueue().offer(args[1], timeout, TimeUnit.SECONDS); println(offered); } catch (InterruptedException e) { currentThread().interrupt(); e.printStackTrace(); } }
@Override public void onMessage(Message<Object> hzMsg) { // We always queue the message even if we have a message listener. We'll // immediately pull it out of the queue and dispatch in a separate thread. // This is important to prevent slow message handlers from blocking topic // distribution in Hazelcast. if (!queue.offer(hzMsg.getMessageObject())) { log.warning(format("In-memory message buffer full for topic [%s]. " + "Messages will be lost. Consider increaing the speed of " + "the consumer or the message buffer.", msgTopic.getName())); return; } hazelcastMQContext.signalDispatchReady(); }
@Override public void run() { long iter = 0; while (!testContext.isStopped()) { try { Thread.sleep(rand.nextInt(maxIntervalMillis) * consumerCount); produced.incrementAndGet(); workQueue.offer(new Work()); iter++; if (iter % 10 == 0) { log.info(Thread.currentThread().getName() + " prod-id:" + id + " iteration: " + iter + " prodoced:" + produced.get() + " workqueue:" + workQueue.size() + " consumed:" + consumed.get()); } } catch (Exception e) { throw new RuntimeException(e); } } } }
protected void handleQOfferMany(String[] args) { int count = 1; if (args.length > 1) { count = Integer.parseInt(args[1]); } Object value = null; if (args.length > 2) { value = new byte[Integer.parseInt(args[2])]; } long started = Clock.currentTimeMillis(); for (int i = 0; i < count; i++) { if (value == null) { getQueue().offer("obj"); } else { getQueue().offer(value); } } long elapsedMillis = Clock.currentTimeMillis() - started; print("size = " + getQueue().size() + ", " + MILLISECONDS.toSeconds(count / elapsedMillis) + " evt/s"); if (value == null) { println(""); } else if (elapsedMillis > 0) { int b = Integer.parseInt(args[2]); long addedKiloBytes = count * BYTES.toKiloBytes(b); println(", " + MILLISECONDS.toSeconds(addedKiloBytes * 8 / elapsedMillis) + " KBit/s, " + addedKiloBytes + " KB added"); } }
protected void handleQOfferMany(String[] args) { int count = 1; if (args.length > 1) { count = Integer.parseInt(args[1]); } Object value = null; if (args.length > 2) { value = new byte[Integer.parseInt(args[2])]; } long t0 = Clock.currentTimeMillis(); for (int i = 0; i < count; i++) { if (value == null) { getQueue().offer("obj"); } else { getQueue().offer(value); } } long t1 = Clock.currentTimeMillis(); print("size = " + getQueue().size() + ", " + count * ONE_THOUSAND / (t1 - t0) + " evt/s"); if (value == null) { println(""); } else { int b = Integer.parseInt(args[2]); println(", " + (count * ONE_THOUSAND / (t1 - t0)) * (b * BYTE_TO_BIT) / ONE_KB + " Kbit/s, " + count * b / ONE_KB + " KB added"); } }
protected void handleQOfferMany(String[] args) { int count = 1; if (args.length > 1) { count = Integer.parseInt(args[1]); } Object value = null; if (args.length > 2) { value = new byte[Integer.parseInt(args[2])]; } long started = Clock.currentTimeMillis(); for (int i = 0; i < count; i++) { if (value == null) { getQueue().offer("obj"); } else { getQueue().offer(value); } } long elapsedMillis = Clock.currentTimeMillis() - started; print("size = " + getQueue().size() + ", " + MILLISECONDS.toSeconds(count / elapsedMillis) + " evt/s"); if (value == null) { println(""); } else if (elapsedMillis > 0) { int b = Integer.parseInt(args[2]); long addedKiloBytes = count * BYTES.toKiloBytes(b); println(", " + MILLISECONDS.toSeconds(addedKiloBytes * 8 / elapsedMillis) + " KBit/s, " + addedKiloBytes + " KB added"); } }
protected void handleQOfferMany(String[] args) { int count = 1; if (args.length > 1) { count = Integer.parseInt(args[1]); } Object value = null; if (args.length > 2) { value = new byte[Integer.parseInt(args[2])]; } long t0 = Clock.currentTimeMillis(); for (int i = 0; i < count; i++) { if (value == null) { getQueue().offer("obj"); } else { getQueue().offer(value); } } long t1 = Clock.currentTimeMillis(); print("size = " + getQueue().size() + ", " + count * ONE_THOUSAND / (t1 - t0) + " evt/s"); if (value == null) { println(""); } else { int b = Integer.parseInt(args[2]); println(", " + (count * ONE_THOUSAND / (t1 - t0)) * (b * BYTE_TO_BIT) / ONE_KB + " Kbit/s, " + count * b / ONE_KB + " KB added"); } }