@Override public void run() { triggered = true; synchronized (closeAtShutdown) { closeAtShutdown.forEach(IOUtils::closeQuietly); } }
/** * Store un-initialized variables in a temporary stack for future use. */ private void storePrevScopeUninitializedVariableData() { final ScopeData scopeData = scopeStack.peek(); final Deque<DetailAST> prevScopeUninitializedVariableData = new ArrayDeque<>(); scopeData.uninitializedVariables.forEach(prevScopeUninitializedVariableData::push); prevScopeUninitializedVariables.push(prevScopeUninitializedVariableData); }
/** * Update current scope data uninitialized variable according to the whole scope data. * @param prevScopeUninitializedVariableData variable for previous stack of uninitialized * variables * @noinspection MethodParameterNamingConvention */ private void updateAllUninitializedVariables( Deque<DetailAST> prevScopeUninitializedVariableData) { // Check for only previous scope updateUninitializedVariables(prevScopeUninitializedVariableData); // Check for rest of the scope prevScopeUninitializedVariables.forEach(this::updateUninitializedVariables); }
@Override public void clear() { overlays.values().forEach(ControlWidget::onClosed); overlays.clear(); hudScreenLayer.clear(); screens.forEach(ControlWidget::onClosed); screens.clear(); screenLookup.clear(); focus = null; forceReleaseMouse = false; }
public void startProcessor(String processor){ getEventProcessor(processor).start(); this.startHandlers.forEach(consumer -> consumer.accept(processor)); }
public void pauseProcessor(String processor){ getEventProcessor(processor).shutDown(); this.pauseHandlers.forEach(consumer -> consumer.accept(processor)); }
@Override public List<String> params(final String name) { Builder<String> builder = ImmutableList.builder(); // query params Deque<String> query = exchange.getQueryParameters().get(name); if (query != null) { query.forEach(builder::add); } // form params Optional.ofNullable(parseForm().get(name)).ifPresent(values -> values.forEach(value -> { if (!value.isFile()) { builder.add(value.getValue()); } })); return builder.build(); }
@Override public void visitToken(DetailAST ast) { final int tokenType = ast.getType(); if (tokenType == TokenTypes.CLASS_DEF || tokenType == TokenTypes.METHOD_DEF || tokenType == TokenTypes.CTOR_DEF || tokenType == TokenTypes.STATIC_INIT || tokenType == TokenTypes.INSTANCE_INIT) { //add a counter for this class/method counters.push(new Counter()); } //check if token is countable if (isCountable(ast)) { //increment the stacked counters counters.forEach(Counter::increment); } }
@Override public List<NativeUpload> files(final String name) { Builder<NativeUpload> builder = ImmutableList.builder(); Deque<FormValue> values = parseForm().get(name); if (values != null) { values.forEach(value -> { if (value.isFile()) { builder.add(new UndertowUpload(value)); } }); } return builder.build(); }
@Override public void invalidate() { assetManager.getLoadedAssets(UIElement.class).forEach(UIElement::dispose); boolean hudVisible = isHUDVisible(); if (hudVisible) { setHUDVisible(false); } Deque<ResourceUrn> reverseUrns = new LinkedList<>(); Map<UIScreenLayer, ResourceUrn> inverseLookup = screenLookup.inverse(); for (UIScreenLayer screen : screens) { screen.onClosed(); reverseUrns.addFirst(inverseLookup.get(screen)); } screens.clear(); screenLookup.clear(); reverseUrns.forEach(this::pushScreen); if (hudVisible) { setHUDVisible(true); } } @Override
/** * Verifies that concurrent sensor add, remove, updates and read don't result * in errors or deadlock. */ @Test public void testConcurrentReadUpdate() throws Exception { final Random random = new Random(); final Deque<Sensor> sensors = new ConcurrentLinkedDeque<>(); metrics = new Metrics(new MockTime(10)); SensorCreator sensorCreator = new SensorCreator(metrics); final AtomicBoolean alive = new AtomicBoolean(true); executorService = Executors.newSingleThreadExecutor(); executorService.submit(new ConcurrentMetricOperation(alive, "record", () -> sensors.forEach(sensor -> sensor.record(random.nextInt(10000))))); for (int i = 0; i < 10000; i++) { if (sensors.size() > 5) { Sensor sensor = random.nextBoolean() ? sensors.removeFirst() : sensors.removeLast(); metrics.removeSensor(sensor.name()); } StatType statType = StatType.forId(random.nextInt(StatType.values().length)); sensors.add(sensorCreator.createSensor(statType, i)); for (Sensor sensor : sensors) { for (KafkaMetric metric : sensor.metrics()) { assertNotNull("Invalid metric value", metric.metricValue()); } } } alive.set(false); }
() -> sensors.forEach(sensor -> sensor.record(random.nextInt(10000))))); Future<?> readFuture = executorService.submit(new ConcurrentMetricOperation(alive, "read", () -> sensors.forEach(sensor -> sensor.metrics().forEach(metric -> assertNotNull("Invalid metric value", metric.metricValue()))))); Future<?> reportFuture = executorService.submit(new ConcurrentMetricOperation(alive, "report",
@Override public void run() { triggered = true; synchronized (closeAtShutdown) { closeAtShutdown.forEach(IOUtils::closeQuietly); } }
private static List<Hook> asHooks(Deque<List<Hook>> hookQueue) { List<Hook> result = new LinkedList<>(); hookQueue.forEach(result::addAll); return result; }
public synchronized void addConsumer(Consumer<Event> eventConsumer) { events.forEach(eventConsumer); consumers.add(eventConsumer); }
private void increaseAndCheckNestedLevel(Tree tree) { if (stack.size() == max) { PreciseIssue issue = addPreciseIssue(tree, String.format("Refactor this code to not nest more than %s rulesets.", max)); stack.forEach(t -> issue.secondary(t, "+1")); } stack.push(tree); }
private void increaseAndCheckNestedLevel(Tree tree) { if (stack.size() == max) { PreciseIssue issue = addPreciseIssue(tree, String.format("Refactor this code to not nest more than %s rulesets.", max)); stack.forEach(t -> issue.secondary(t, "+1")); } stack.push(tree); }
private void leaveFunction(FunctionTree tree) { Deque<SyntaxToken> thisFunctionReturns = returnStatementCounter.pop(); if (thisFunctionReturns.size() > max) { String message = String.format(MESSAGE, thisFunctionReturns.size(), max); PreciseIssue issue = context().newIssue(this, tree.functionToken(), message); thisFunctionReturns.forEach(returnToken -> issue.secondary(returnToken, null)); } } }
public ActorFuture<Void> onChannelClosed(TransportChannel channel) { return actor.call( () -> { final ChannelWriteQueue sendQueue = channelMap.remove(channel.getStreamId()); if (sendQueue != null) { channelList.remove(sendQueue); // re-submit pending requests so that they can be retried sendQueue.pendingWrites.forEach(Batch::onChannelClosed); } }); }
private void enterFunction(FunctionTree tree) { nestedStack.push(tree.functionToken()); if (nestedStack.size() == max + 1) { PreciseIssue issue = context().newIssue(this, tree.functionToken(), String.format(MESSAGE, max)); nestedStack.forEach(secondary -> issue.secondary(secondary, "Nesting +1")); } }