public int estimateSourceDistributedTaskCount() { return numberOfNodes.getAsInt(); } }
public int getRowNum() { return rowNumPointer.getAsInt(); }
public int orElseGet(IntSupplier other) { return this != emptyInstance ? value : other.getAsInt(); }
private synchronized int maybeCompute(IntSupplier supplier) { if (!initialized) { value = requireNonNull(supplier.getAsInt()); initialized = true; } return value; }
@Override public void initRead() { this.lastClosedTxId = closedTxIdSupplier.getAsInt(); }
private CompactionCompleteTracker getCompleteTracker(CompactionLifeCycleTracker tracker, IntSupplier numberOfStores) { if (tracker == CompactionLifeCycleTracker.DUMMY) { // a simple optimization to avoid creating unnecessary objects as usually we do not care about // the life cycle of a compaction. return DUMMY_COMPLETE_TRACKER; } else { return new AggregatingCompleteTracker(tracker, numberOfStores.getAsInt()); } }
<T> int finallyClose(IntSupplier is) { try { return is.getAsInt(); } finally { close(); } }
@Override public boolean next(IntPredicate consumer) { while (consumer.test(s.getAsInt())) { // go on } return true; } }
/** * Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such * key-value pair. * * @param key the key for the configuration property * @param defaultValueSupplier the supplier for the default value; may be null * @return the integer value, or null if the key is null, there is no such key-value pair in the configuration, the * {@code defaultValueSupplier} reference is null, or there is a key-value pair in the configuration but the value * could not be parsed as an integer */ default Integer getInteger(String key, IntSupplier defaultValueSupplier) { String value = getString(key); if (value != null) { try { return Integer.valueOf(value); } catch (NumberFormatException e) {} } return defaultValueSupplier != null ? defaultValueSupplier.getAsInt() : null; }
if (key.isReadable()) ((IntSupplier)key.attachment()).getAsInt();
@Override public String toString() { return "RowPointer{" + "indexNum=" + indexNum + ", rowNumber=" + rowNumPointer.getAsInt() + ", timestamp=" + getTimestamp() + ", dimensions=" + getDimensionNamesToValuesForDebug() + ", metrics=" + getMetricNamesToValuesForDebug() + '}'; } }
protected int finallyCloseInt(IntSupplier is) { try { return is.getAsInt(); } catch (Exception e) { LOGGER.error(e); throw e; } finally { close(); } }
if (key.isReadable()) ((IntSupplier)key.attachment()).getAsInt();
@Test public void invokeSuppliersShouldCatchSupplierErrorsAndReturnCount() { IntSupplier supplier1 = mock(IntSupplier.class); when(supplier1.getAsInt()).thenThrow(NullPointerException.class); stats.setIntSupplier(4, supplier1); assertEquals(1, stats.invokeSuppliers()); verify(supplier1).getAsInt(); }
for (Map.Entry<Integer, IntSupplier> entry : intSuppliers.entrySet()) { try { _setInt(entry.getKey(), entry.getValue().getAsInt()); } catch (Throwable t) { logSupplierError(t, entry.getKey(), entry.getValue());
int servletPort = portSupplier.getAsInt(); int containerRmiPort = portSupplier.getAsInt(); int tomcatAjpPort = portSupplier.getAsInt(); config.setProperty(ServletPropertySet.PORT, Integer.toString(servletPort)); config.setProperty(GeneralPropertySet.RMI_PORT, Integer.toString(containerRmiPort)); config.setProperty(TomcatPropertySet.AJP_PORT, Integer.toString(tomcatAjpPort)); config.setProperty(GeneralPropertySet.PORT_OFFSET, "0"); int jvmJmxPort = portSupplier.getAsInt(); String jvmArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + jvmJmxPort; if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9)) {
@Test public void badSupplierParamShouldThrowError() { IntSupplier supplier1 = mock(IntSupplier.class); when(supplier1.getAsInt()).thenReturn(23); thrown.expect(IllegalArgumentException.class); stats.setIntSupplier(23, supplier1); } }
@Test public void invokeSuppliersShouldLogErrorOnlyOnce() { Logger logger = mock(Logger.class); StatisticsImpl.logger = logger; IntSupplier supplier1 = mock(IntSupplier.class); when(supplier1.getAsInt()).thenThrow(NullPointerException.class); stats.setIntSupplier(4, supplier1); assertEquals(1, stats.invokeSuppliers()); // String message, Object p0, Object p1, Object p2 verify(logger, times(1)).warn(anyString(), isNull(), anyInt(), isA(NullPointerException.class)); assertEquals(1, stats.invokeSuppliers()); // Make sure the logger isn't invoked again verify(logger, times(1)).warn(anyString(), isNull(), anyInt(), isA(NullPointerException.class)); }
@Test public void shouldPollSuppliersForDocumentStat() { stats.addDocumentsSupplier(() -> 5); stats.addDocumentsSupplier(() -> 3); int documentsId = type.nameToId("documents"); ArgumentCaptor<IntSupplier> documentsSupplierCaptor = ArgumentCaptor.forClass(IntSupplier.class); verify(statistics).setIntSupplier(eq(documentsId), documentsSupplierCaptor.capture()); IntSupplier documentsSuppler = documentsSupplierCaptor.getValue(); assertEquals(8, documentsSuppler.getAsInt()); }