/** * Adds the given element to this queue. If the queue is full, the least recently added * element is discarded so that a new element can be inserted. * * @param element the element to add * @return true, always * @throws NullPointerException if the given element is null */ @Override public boolean offer(final E element) { return add(element); }
@Inject public FileQueueProcessor( DataPointEventSerializer eventSerializer, BigArray bigArray, @Named(QUEUE_PROCESSOR) ExecutorService executor, @Named(BATCH_SIZE) int batchSize, @Named(MEMORY_QUEUE_SIZE) int memoryQueueSize, @Named(SECONDS_TILL_CHECKPOINT) int secondsTillCheckpoint, @Named(MINIMUM_BATCH_SIZE) int minimumBatchSize, @Named(MINIMUM_BATCH_WAIT) int minBatchWait) { super(executor, batchSize, minimumBatchSize, minBatchWait); m_bigArray = bigArray; m_memoryQueue = new CircularFifoQueue<>(memoryQueueSize); m_eventSerializer = eventSerializer; m_nextIndex = m_bigArray.getTailIndex(); m_secondsTillCheckpoint = secondsTillCheckpoint; m_shuttingDown = false; }
@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); } }
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); }
private void addNodeEvent(final NodeIdentifier nodeId, final Severity severity, final String message) { final NodeEvent event = new Event(nodeId.toString(), message, severity); final CircularFifoQueue<NodeEvent> eventQueue = nodeEvents.computeIfAbsent(nodeId, id -> new CircularFifoQueue<>()); synchronized (eventQueue) { eventQueue.add(event); } }
System.out.println("ra: window: " + window); CircularFifoQueue<Measurement> slidingWindow = new CircularFifoQueue(window); slidingWindow.add(dset.get(i)); Iterator itr = slidingWindow.iterator(); while(itr.hasNext()) { Measurement m = (Measurement) itr.next(); PerformanceIssueType piTType = PerformanceIssueType.THRESHOLD_EXCEEDED; PerformanceIssue performanceIssue = new PerformanceIssue(piTType); long fromTime = slidingWindow.get(0).getTime(); performanceIssue.setFrom(fromTime); long toTime = slidingWindow.get(window - 1).getTime(); performanceIssue.setTo(toTime); if(!PerformanceIssueType.OK.equals(piType)){ PerformanceIssue performanceIssue = new PerformanceIssue(piType); long fromTime = slidingWindow.get(0).getTime(); performanceIssue.setFrom(fromTime); long toTime = slidingWindow.get(window-1).getTime(); performanceIssue.setTo(toTime); slidingWindow.add(dset.get(i));
public void flushToServer() { if (buffer.isEmpty()) { return; } List sent = new ArrayList(); try { synchronized (buffer) { while (!buffer.isEmpty()) { sent.add(buffer.remove()); } } StringBuilder result = new StringBuilder(); for (Object string : sent) { result.append(string); result.append("\n"); } consoleAppender.append(result.toString()); } catch (IOException e) { LOGGER.warn("Could not send console output to server", e); synchronized (buffer) { sent.addAll(buffer); buffer.clear(); buffer.addAll(sent); } } }
/** * Returns true if this queue is empty; false otherwise. * * @return true if this queue is empty */ @Override public boolean isEmpty() { return size() == 0; }
public void submitNewBuild(Build build) { if (this.maxSubmittedBuilds == -1) { throw new RuntimeException("You must set maxSubmittedBuilds before running this."); } if (this.nbSubmittedBuilds < this.maxSubmittedBuilds) { // we do not reached the maximum yet // we check if we already inspected this build if (!this.observedBuilds.contains(build.getId())) { // it's not the case: we add the build to the lists this.observedBuilds.add(build.getId()); this.waitingBuilds.add(build); // must be synchronized to avoid concurrent access synchronized (this) { this.nbSubmittedBuilds++; } LOGGER.info("New build submitted (id: "+build.getId()+") Total: "+this.nbSubmittedBuilds+" | Limit: "+maxSubmittedBuilds+")"); } } else { LOGGER.debug("Build submission ignored. (maximum reached)"); } }
/** * Adds the given element to this queue. If the queue is full, the least recently added * element is discarded so that a new element can be inserted. * * @param element the element to add * @return true, always * @throws NullPointerException if the given element is null */ @Override public boolean add(final E element) { if (null == element) { throw new NullPointerException("Attempted to add null object to queue"); } if (isAtFullCapacity()) { remove(); } elements[end++] = element; if (end >= maxElements) { end = 0; } if (end == start) { full = true; } return true; }
@Override public E peek() { if (isEmpty()) { return null; } return elements[start]; }
CircularFifoQueue.this.remove(); lastReturnedIndex = -1; return;
/** * Constructor that creates a queue from the specified collection. * The collection size also sets the queue size. * * @param coll the collection to copy into the queue, may not be null * @throws NullPointerException if the collection is null */ public CircularFifoQueue(final Collection<? extends E> coll) { this(coll.size()); addAll(coll); }
public synchronized Set<Bulletin> getBulletins() { final Set<Bulletin> response = new HashSet<>(ringBuffer); ringBuffer.clear(); return response; } }
/** * 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); }