/** * Returns a {@link ContentType} from a given {@link XContentType}. * * @param xContentType the {@link XContentType} * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); }
@SuppressForbidden(reason = "Version#parseLeniently() used in a central place") private static final class LenientParser { public static Version parse(String toParse, Version defaultValue) { if (Strings.hasLength(toParse)) { try { return Version.parseLeniently(toParse); } catch (ParseException e) { // pass to default } } return defaultValue; } }
/** * Notify all threads waiting on the monitor on this tracker. These threads should be waiting for the local checkpoint on a specific * allocation ID to catch up to the global checkpoint. */ @SuppressForbidden(reason = "Object#notifyAll waiters for local checkpoint advancement") private synchronized void notifyAllWaiters() { this.notifyAll(); }
@SuppressForbidden(reason = "optimalCapacity is non-negative, therefore the difference cannot be < -Integer.MAX_VALUE") private int getChangeAmount(int optimalCapacity) { assert optimalCapacity >= 0 : "optimal capacity should always be positive, got: " + optimalCapacity; return Math.abs(optimalCapacity - this.capacity); }
@SuppressForbidden(reason = "ThreadLocalRandom is okay when not running tests") private static Random getWithoutSeed() { assert currentMethod == null && getRandomMethod == null : "running under tests but tried to create non-reproducible random"; return ThreadLocalRandom.current(); }
/** * Wait for the local checkpoint to advance to the global checkpoint. * * @throws InterruptedException if this thread was interrupted before of during waiting */ @SuppressForbidden(reason = "Object#wait for local checkpoint advancement") private synchronized void waitForLocalCheckpointToAdvance() throws InterruptedException { this.wait(); }
@SuppressForbidden(reason = "System#err") private static void closeSysError() { System.err.close(); }
@SuppressForbidden(reason = "need path to construct environment") private static Path getConfigPath(final String pathConf) { return Paths.get(pathConf); }
@SuppressForbidden(reason = "System#out") private static void closeSystOut() { System.out.close(); }
@SuppressForbidden(reason="file arg for cli") private Path getPath(String file) { return PathUtils.get(file); } }
@SuppressForbidden(reason = "halt") @Override public Void run() { // we halt to prevent shutdown hooks from running Runtime.getRuntime().halt(status); return null; }
@SuppressForbidden(reason = "only exposing the method as a passthrough") public ZonedDateTime truncatedTo(TemporalUnit unit) { return dt.truncatedTo(unit); }
@SuppressForbidden(reason = "access /proc/sys/vm/max_map_count") private Path getProcSysVmMaxMapCountPath() { return PathUtils.get("/proc/sys/vm/max_map_count"); }
/** * Returns the line from {@code memory.usage_in_bytes} for the control group to which the Elasticsearch process belongs for the * {@code memory} subsystem. This line represents the total current memory usage by processes in the cgroup (in bytes). * * @param controlGroup the control group to which the Elasticsearch process belongs for the {@code memory} subsystem * @return the line from {@code memory.usage_in_bytes} * @throws IOException if an I/O exception occurs reading {@code memory.usage_in_bytes} for the control group */ @SuppressForbidden(reason = "access /sys/fs/cgroup/memory") String readSysFsCgroupMemoryUsageInBytes(final String controlGroup) throws IOException { return readSingleLine(PathUtils.get("/sys/fs/cgroup/memory", controlGroup, "memory.usage_in_bytes")); }
@SuppressForbidden(reason = "ClassLoader.getDefinedPackage not available yet") public Object readResolve() { // TODO minJava >= 9 : use ClassLoader.getDefinedPackage and remove @SuppressForbidden return inPackage(Package.getPackage(packageName)); } }
/** * Returns the line from {@code cpuacct.usage} for the control group to which the Elasticsearch process belongs for the {@code cpuacct} * subsystem. This line represents the total CPU time in nanoseconds consumed by all tasks in the same control group. * * @param controlGroup the control group to which the Elasticsearch process belongs for the {@code cpuacct} subsystem * @return the line from {@code cpuacct.usage} * @throws IOException if an I/O exception occurs reading {@code cpuacct.usage} for the control group */ @SuppressForbidden(reason = "access /sys/fs/cgroup/cpuacct") String readSysFsCgroupCpuAcctCpuAcctUsage(final String controlGroup) throws IOException { return readSingleLine(PathUtils.get("/sys/fs/cgroup/cpuacct", controlGroup, "cpuacct.usage")); }
@SuppressForbidden(reason = "System.out.*") static void applySegmentInfosTrace(Settings settings) { if (ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING.get(settings)) { SegmentInfos.setInfoStream(System.out); } }
/** * Returns the line from {@code memory.limit_in_bytes} for the control group to which the Elasticsearch process belongs for the * {@code memory} subsystem. This line represents the maximum amount of user memory (including file cache). * * @param controlGroup the control group to which the Elasticsearch process belongs for the {@code memory} subsystem * @return the line from {@code memory.limit_in_bytes} * @throws IOException if an I/O exception occurs reading {@code memory.limit_in_bytes} for the control group */ @SuppressForbidden(reason = "access /sys/fs/cgroup/memory") String readSysFsCgroupMemoryLimitInBytes(final String controlGroup) throws IOException { return readSingleLine(PathUtils.get("/sys/fs/cgroup/memory", controlGroup, "memory.limit_in_bytes")); }
/** * The line from {@code /proc/loadavg}. The first three fields are the load averages averaged over 1, 5, and 15 minutes. The fourth * field is two numbers separated by a slash, the first is the number of currently runnable scheduling entities, the second is the * number of scheduling entities on the system. The fifth field is the PID of the most recently created process. * * @return the line from {@code /proc/loadavg} or {@code null} */ @SuppressForbidden(reason = "access /proc/loadavg") String readProcLoadavg() throws IOException { return readSingleLine(PathUtils.get("/proc/loadavg")); }
/** * Returns the line from {@code cpu.cfs_period_us} for the control group to which the Elasticsearch process belongs for the {@code cpu} * subsystem. This line represents the period of time in microseconds for how frequently the control group's access to CPU resources * will be reallocated. * * @param controlGroup the control group to which the Elasticsearch process belongs for the {@code cpu} subsystem * @return the line from {@code cpu.cfs_period_us} * @throws IOException if an I/O exception occurs reading {@code cpu.cfs_period_us} for the control group */ @SuppressForbidden(reason = "access /sys/fs/cgroup/cpu") String readSysFsCgroupCpuAcctCpuCfsPeriod(final String controlGroup) throws IOException { return readSingleLine(PathUtils.get("/sys/fs/cgroup/cpu", controlGroup, "cpu.cfs_period_us")); }