/** * 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); }
@Override public synchronized void update(final Bulletin bulletin) { ringBuffer.add(bulletin); }
@Override public void taggedConsumeLine(String tag, String line) { synchronized (buffer) { if (null == tag) tag = " "; String date = dateFormat.format(new Date()); String prepend = format("%s|%s", tag, date); String multilineJoin = "\n" + prepend + " "; buffer.add(format("%s %s", prepend, line).replaceAll("\n", multilineJoin)); } }
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); }
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); } }
public void put(DataPointEvent dataPointEvent) throws DatastoreException { if (m_shuttingDown) { throw new DatastoreException("File Queue shutting down"); } byte[] eventBytes = m_eventSerializer.serializeEvent(dataPointEvent); synchronized (m_lock) { long index = -1L; //Add data to bigArray first index = m_bigArray.append(eventBytes); //Then stick it into the in memory queue m_memoryQueue.add(new IndexedEvent(dataPointEvent, index)); //Notify the reader thread if it is waiting for data m_lock.notify(); } }
@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); } }
/** * 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(E element) { return add(element); }
/** * Sending message to the joined channel * @param channel channel name * @param message message */ public void sendMessage(String channel, String message) { log.debug("Adding message for channel [{}] with content [{}] to the queue.", channel, message); ircCommandQueue.add(String.format("PRIVMSG #%s :%s", channel, message)); }
/** * Send IRC Command * * @param command IRC Command * @param args command arguments */ protected void sendCommand(String command, String... args) { ircCommandQueue.add(String.format("%s %s", command.toUpperCase(), String.join(" ", args))); }
/** * Sends a user a private message * * @param targetUser username * @param message message */ public void sendPrivateMessage(String targetUser, String message) { log.debug("Adding private message for user [{}] with content [{}] to the queue.", targetUser, message); ircCommandQueue.add(String.format("PRIVMSG #%s /w %s %s", chatCredential.get().getUserName(), targetUser, message)); }
/** * Send WS Message to subscribe to a topic * * @param request Topic */ public void listenOnTopic(PubSubRequest request) { commandQueue.add(TypeConvert.objectToJson(request)); subscribedTopics.add(request); }
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)"); } }
private String runSbt(final LineConsumer buildLogHandler, final Map<String, String> envVarsForApp, final List<String> arguments) { final CommandLine command = sbtCmd.commandLine(envVarsForApp); for (final String argument : arguments) { command.addArgument(argument); } buildLogHandler.consumeLine("Running sbt " + StringUtils.join(arguments, " ") + " with " + command); final CircularFifoQueue<String> latestBuildLog = new CircularFifoQueue<>(SBT_LINE_BUFFER); final LineConsumer capturingBuildLogHandler = line -> { buildLogHandler.consumeLine(line); latestBuildLog.add(line); }; ProcessStarter.run(capturingBuildLogHandler, envVarsForApp, command, projectRoot, MINUTES.toMillis(20)); for (final String line : latestBuildLog) { final Matcher matcher = ARTIFACT_PATH_REGEX.matcher(line); if (matcher.matches()) { return matcher.group(1); } } throw new RuntimeException("Artifact path not found within last " + SBT_LINE_BUFFER + " lines of build log"); } }
/** * add a valueItem to the history * * @param currentItem */ private void addToHistory(CANValueItem<ValueType> currentItem) { if (currentItem.isAvailable()) { ValueItem<ValueType> historyItem = new ValueItem<ValueType>(); historyItem.available = true; historyItem.timeStamp = currentItem.getTimeStamp(); historyItem.value = currentItem.getValue(); getHistory().add(historyItem); previousHistoryTimeStamp = currentItem.getTimeStamp(); } }
consoleLog.add(line);