/** * Returns true if this queue is empty; false otherwise. * * @return true if this queue is empty */ @Override public boolean isEmpty() { return size() == 0; }
/** * Returns {@code true} if the capacity limit of this queue has been reached, * i.e. the number of elements stored in the queue equals its maximum size. * * @return {@code true} if the capacity limit has been reached, {@code false} otherwise * @since 4.1 */ public boolean isAtFullCapacity() { return size() == maxElements; }
@Override protected int getAvailableDataPointEvents() { return m_memoryQueue.size(); }
/** * Write the queue out using a custom routine. * * @param out the output stream * @throws IOException if an I/O error occurs while writing to the output stream */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(size()); for (final E e : this) { out.writeObject(e); } }
/** * Returns the element at the specified position in this queue. * * @param index the position of the element in the queue * @return the element at position {@code index} * @throws NoSuchElementException if the requested position is outside the range [0, size) */ public E get(final int index) { final int sz = size(); if (index < 0 || index >= sz) { throw new NoSuchElementException( String.format("The specified index (%1$d) is outside the available range [0, %2$d)", Integer.valueOf(index), Integer.valueOf(sz))); } final int idx = (start + index) % maxElements; return elements[idx]; }
private void estimateBlockSize(List<TransactionReceipt> receipts, long number) { if (receipts.isEmpty()) return; long blockSize = receipts.stream().mapToLong(TransactionReceipt::estimateMemSize).sum(); synchronized (lastBlockSizes) { lastBlockSizes.add(blockSize); estimatedBlockSize = lastBlockSizes.stream().mapToLong(Long::longValue).sum() / lastBlockSizes.size(); } if (number % 1000 == 0) logger.debug("ReceiptsDownloader: estimated block size: {}", estimatedBlockSize); }
protected void estimateBlockSize(Collection<BlockWrapper> blockWrappers) { if (blockWrappers.isEmpty()) return; synchronized (lastBlockSizes) { blockWrappers.forEach(b -> lastBlockSizes.add(b.estimateMemSize())); estimatedBlockSize = lastBlockSizes.stream().mapToLong(Long::longValue).sum() / lastBlockSizes.size(); } logger.debug("{}: estimated block size: {}", name, estimatedBlockSize); }
/** * Estimates block size in bytes. * Block memory size can depend on the underlying logic, * hence ancestors should call this method on their own, * preferably after actions that impact on block memory size (like RLP parsing, signature recover) are done */ protected void estimateBlockSize(BlockWrapper blockWrapper) { synchronized (lastBlockSizes) { lastBlockSizes.add(blockWrapper.estimateMemSize()); estimatedBlockSize = lastBlockSizes.stream().mapToLong(Long::longValue).sum() / lastBlockSizes.size(); } logger.debug("{}: estimated block size: {}", name, estimatedBlockSize); }
if (onBlockBuffer.size() < onBlockBuffer.maxSize()) { replayComplete = true; } else {
@Override public synchronized void onBlock(BlockSummary blockSummary) { if (replayComplete) { if (onBlockBuffer.isEmpty()) { listener.onBlock(blockSummary); } else { logger.info("Replaying cached " + onBlockBuffer.size() + " blocks..."); boolean lastBlockFound = lastReplayedBlock == null || onBlockBuffer.size() < onBlockBuffer.maxSize(); for (BlockSummary block : onBlockBuffer) { if (!lastBlockFound) { lastBlockFound = FastByteComparisons.equal(block.getBlock().getHash(), lastReplayedBlock.getHash()); } else { listener.onBlock(block); } } onBlockBuffer.clear(); listener.onBlock(blockSummary); logger.info("Cache replay complete. Switching to online mode."); } } else { onBlockBuffer.add(blockSummary); } }
/** * Returns true if this queue is empty; false otherwise. * * @return true if this queue is empty */ @Override public boolean isEmpty() { return size() == 0; }
/** * Returns {@code true} if the capacity limit of this queue has been reached, * i.e. the number of elements stored in the queue equals its maximum size. * * @return {@code true} if the capacity limit has been reached, {@code false} otherwise * @since 4.1 */ public boolean isAtFullCapacity() { return size() == maxElements; }
/** * Write the queue out using a custom routine. * * @param out the output stream * @throws IOException if an I/O error occurs while writing to the output stream */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(size()); for (final E e : this) { out.writeObject(e); } }
/** * Returns the element at the specified position in this queue. * * @param index the position of the element in the queue * @return the element at position {@code index} * @throws NoSuchElementException if the requested position is outside the range [0, size) */ public E get(final int index) { final int sz = size(); if (index < 0 || index >= sz) { throw new NoSuchElementException( String.format(Locale.US, "The specified index (%1$d) is outside the available range [0, %2$d)", Integer.valueOf(index), Integer.valueOf(sz))); } final int idx = (start + index) % maxElements; return elements[idx]; }
try { if (ircCommandQueue.size() > 0) { if (connectionState.equals(TMIConnectionState.CONNECTED)) {
if (commandQueue.size() > 0) { if (connectionState.equals(TMIConnectionState.CONNECTED)) {
@Test @DisplayName("Tests sending and receiving channel messages") public void sendTwitchChannelMessage() { // listen for events in channel List<ChannelMessageEvent> channelMessages = new ArrayList<>(); twitchChat.joinChannel("twitch4j"); twitchChat.getEventManager().onEvent(ChannelMessageEvent.class).subscribe(event -> { channelMessages.add(event); log.debug(event.toString()); }); // send message to channel twitchChat.sendMessage("twitch4j", "Hello @twitch4j"); // sleep a second and look of the message was sended TestUtils.sleepFor(1000); // check if the message was send and received assertTrue(twitchChat.ircCommandQueue.size() == 0, "Can't find the message we send in the received messages!"); }