当前位置: 首页>>代码示例>>Java>>正文


Java SuppressForbidden类代码示例

本文整理汇总了Java中org.elasticsearch.common.SuppressForbidden的典型用法代码示例。如果您正苦于以下问题:Java SuppressForbidden类的具体用法?Java SuppressForbidden怎么用?Java SuppressForbidden使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SuppressForbidden类属于org.elasticsearch.common包,在下文中一共展示了SuppressForbidden类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "system out is ok for a command line tool")
public static void main(String[] args) throws Exception {
    String type = args[0];
    AbstractBenchmark<?> benchmark = null;
    switch (type) {
        case "transport":
            benchmark = new TransportClientBenchmark();
            break;
        case "rest":
            benchmark = new RestClientBenchmark();
            break;
        default:
            System.err.println("Unknown client type [" + type + "]");
            System.exit(1);
    }
    benchmark.run(Arrays.copyOfRange(args, 1, args.length));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:BenchmarkMain.java

示例2: stopInternal

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@Override
@SuppressForbidden(reason = "debug")
protected void stopInternal() {
    Releasables.close(serverOpenChannels, () -> {
        final List<Tuple<String, Future<?>>> serverBootstrapCloseFutures = new ArrayList<>(serverBootstraps.size());
        for (final Map.Entry<String, ServerBootstrap> entry : serverBootstraps.entrySet()) {
            serverBootstrapCloseFutures.add(
                Tuple.tuple(entry.getKey(), entry.getValue().config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS)));
        }
        for (final Tuple<String, Future<?>> future : serverBootstrapCloseFutures) {
            future.v2().awaitUninterruptibly();
            if (!future.v2().isSuccess()) {
                logger.debug(
                    (Supplier<?>) () -> new ParameterizedMessage(
                        "Error closing server bootstrap for profile [{}]", future.v1()), future.v2().cause());
            }
        }
        serverBootstraps.clear();

        if (bootstrap != null) {
            bootstrap.config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS).awaitUninterruptibly();
            bootstrap = null;
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:Netty4Transport.java

示例3: run

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "system out is ok for a command line tool")
public final void run(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("usage: [search|bulk]");
        System.exit(1);
    }
    switch (args[0]) {
        case "search":
            runSearchBenchmark(args);
            break;
        case "bulk":
            runBulkIndexBenchmark(args);
            break;
        default:
            System.err.println("Unknown benchmark type [" + args[0] + "]");
            System.exit(1);

    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractBenchmark.java

示例4: runTrials

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "system out is ok for a command line tool")
private void runTrials(Runnable runner) {
    int totalWarmupTrialRuns = 1;
    for (int run = 1; run <= totalWarmupTrialRuns; run++) {
        System.out.println("======================");
        System.out.println(" Warmup trial run " + run + "/" + totalWarmupTrialRuns);
        System.out.println("======================");
        runner.run();
    }

    int totalTrialRuns = 5;
    for (int run = 1; run <= totalTrialRuns; run++) {
        System.out.println("================");
        System.out.println(" Trial run " + run + "/" + totalTrialRuns);
        System.out.println("================");

        runner.run();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AbstractBenchmark.java

示例5: runGc

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
/**
 * Requests a full GC and checks whether the GC did actually run after a request. It retries up to 5 times in case the GC did not
 * run in time.
 */
@SuppressForbidden(reason = "we need to request a system GC for the benchmark")
private void runGc() {
    long previousCollections = getTotalGcCount();
    int attempts = 0;
    do {
        // request a full GC ...
        System.gc();
        // ... and give GC a chance to run
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
        attempts++;
    } while (previousCollections == getTotalGcCount() || attempts < 5);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:AbstractBenchmark.java

示例6: initializeNetty

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
/**
 * Netty wants to do some unsafe things like use unsafe and replace a private field. This method disables these things by default, but
 * can be overridden by setting the corresponding system properties.
 */
@SuppressForbidden(reason = "set system properties to configure Netty")
private static void initializeNetty() {
    final String noUnsafeKey = "io.netty.noUnsafe";
    final String noUnsafe = System.getProperty(noUnsafeKey);
    if (noUnsafe == null) {
        // disable Netty from using unsafe
        // while permissions are needed to set this, if a security exception is thrown the permission needed can either be granted or
        // the system property can be set directly before starting the JVM; therefore, we do not catch a security exception here
        System.setProperty(noUnsafeKey, Boolean.toString(true));
    }

    final String noKeySetOptimizationKey = "io.netty.noKeySetOptimization";
    final String noKeySetOptimization = System.getProperty(noKeySetOptimizationKey);
    if (noKeySetOptimization == null) {
        // disable Netty from replacing the selector key set
        // while permissions are needed to set this, if a security exception is thrown the permission needed can either be granted or
        // the system property can be set directly before starting the JVM; therefore, we do not catch a security exception here
        System.setProperty(noKeySetOptimizationKey, Boolean.toString(true));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:PreBuiltTransportClient.java

示例7: testMaxNumShards

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "manipulates system properties for testing")
public void testMaxNumShards() {
    IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () ->
        IndexMetaData.buildNumberOfShardsSetting()
            .get(Settings.builder().put("index.number_of_shards", 1025).build()));
    assertEquals("Failed to parse value [1025] for setting [index.number_of_shards] must be <= 1024", exception.getMessage());

    Integer numShards = IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(Settings.builder().put("index.number_of_shards", 100).build());
    assertEquals(100, numShards.intValue());
    int limit = randomIntBetween(1, 10);
    System.setProperty("es.index.max_number_of_shards", Integer.toString(limit));
    try {
        IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () ->
            IndexMetaData.buildNumberOfShardsSetting()
                .get(Settings.builder().put("index.number_of_shards", 11).build()));
        assertEquals("Failed to parse value [11] for setting [index.number_of_shards] must be <= " + limit, e.getMessage());
    } finally {
        System.clearProperty("es.index.max_number_of_shards");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:EvilSystemPropertyTests.java

示例8: getFileSystem

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
/**
 * Returns a new FileSystem to read REST resources, or null if they
 * are available from classpath.
 */
@SuppressForbidden(reason = "proper use of URL, hack around a JDK bug")
protected static FileSystem getFileSystem() throws IOException {
    // REST suite handling is currently complicated, with lots of filtering and so on
    // For now, to work embedded in a jar, return a ZipFileSystem over the jar contents.
    URL codeLocation = FileUtils.class.getProtectionDomain().getCodeSource().getLocation();
    boolean loadPackaged = RandomizedTest.systemPropertyAsBoolean(REST_LOAD_PACKAGED_TESTS, true);
    if (codeLocation.getFile().endsWith(".jar") && loadPackaged) {
        try {
            // hack around a bug in the zipfilesystem implementation before java 9,
            // its checkWritable was incorrect and it won't work without write permissions.
            // if we add the permission, it will open jars r/w, which is too scary! so copy to a safe r-w location.
            Path tmp = Files.createTempFile(null, ".jar");
            try (InputStream in = FileSystemUtils.openFileURLStream(codeLocation)) {
                Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
            }
            return FileSystems.newFileSystem(new URI("jar:" + tmp.toUri()), Collections.emptyMap());
        } catch (URISyntaxException e) {
            throw new IOException("couldn't open zipfilesystem: ", e);
        }
    } else {
        return null;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:ESClientYamlSuiteTestCase.java

示例9: testReproducible

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@Test
@SuppressForbidden(reason = "repeat is a feature here")
@Repeat(iterations = 10, useConstantSeed = true)
public void testReproducible() throws IOException {
    if (ITER++ == 0) {
        CLUSTER_SEED = cluster().seed();
        for (int i = 0; i < SEQUENCE.length; i++) {
            SEQUENCE[i] = randomLong();
        }
    } else {
        assertEquals(CLUSTER_SEED, Long.valueOf(cluster().seed()));
        for (int i = 0; i < SEQUENCE.length; i++) {
            assertThat(SEQUENCE[i], equalTo(randomLong()));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SuiteScopeClusterIT.java

示例10: getTempDir

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "access temp directory for building index")
protected static synchronized FSDirectory getTempDir() {
    if (tmpBuildDir == null) {
        // Lazy init
        String tempDirPath = System.getProperty("java.io.tmpdir");
        if (tempDirPath == null)  {
            throw new RuntimeException("Java has no temporary folder property (java.io.tmpdir)?");
        }
        try {
            tmpBuildDir = FSDirectory.open(PathUtils.get(tempDirPath));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
    return tmpBuildDir;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:XAnalyzingSuggester.java

示例11: downloadZipAndChecksum

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
/** Downloads a zip from the url, as well as a SHA1 checksum, and checks the checksum. */
@SuppressForbidden(reason = "We use openStream to download plugins")
private Path downloadZipAndChecksum(Terminal terminal, String urlString, Path tmpDir) throws Exception {
    Path zip = downloadZip(terminal, urlString, tmpDir);
    pathsToDeleteOnShutdown.add(zip);
    URL checksumUrl = new URL(urlString + ".sha1");
    final String expectedChecksum;
    try (InputStream in = checksumUrl.openStream()) {
        BufferedReader checksumReader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
        expectedChecksum = checksumReader.readLine();
        if (checksumReader.readLine() != null) {
            throw new UserException(ExitCodes.IO_ERROR, "Invalid checksum file at " + checksumUrl);
        }
    }

    byte[] zipbytes = Files.readAllBytes(zip);
    String gotChecksum = MessageDigests.toHexString(MessageDigests.sha1().digest(zipbytes));
    if (expectedChecksum.equals(gotChecksum) == false) {
        throw new UserException(ExitCodes.IO_ERROR, "SHA1 mismatch, expected " + expectedChecksum + " but got " + gotChecksum);
    }

    return zip;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:InstallPluginCommand.java

示例12: testSegmentInfosTracing

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "System.out.*")
public void testSegmentInfosTracing() {
    // Defaults to not hooking up std out
    assertNull(SegmentInfos.getInfoStream());

    try {
        // False means don't hook up std out
        NodeEnvironment.applySegmentInfosTrace(
                Settings.builder().put(NodeEnvironment.ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING.getKey(), false).build());
        assertNull(SegmentInfos.getInfoStream());

        // But true means hook std out up statically
        NodeEnvironment.applySegmentInfosTrace(
                Settings.builder().put(NodeEnvironment.ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING.getKey(), true).build());
        assertEquals(System.out, SegmentInfos.getInfoStream());
    } finally {
        // Clean up after ourselves
        SegmentInfos.setInfoStream(null);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:NodeEnvironmentTests.java

示例13: resolve

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
/**
 * @param type the ec2 hostname type to discover.
 * @return the appropriate host resolved from ec2 meta-data, or null if it cannot be obtained.
 * @see CustomNameResolver#resolveIfPossible(String)
 */
@SuppressForbidden(reason = "We call getInputStream in doPrivileged and provide SocketPermission")
public InetAddress[] resolve(Ec2HostnameType type) throws IOException {
    InputStream in = null;
    String metadataUrl = AwsEc2ServiceImpl.EC2_METADATA_URL + type.ec2Name;
    try {
        URL url = new URL(metadataUrl);
        logger.debug("obtaining ec2 hostname from ec2 meta-data url {}", url);
        URLConnection urlConnection = SocketAccess.doPrivilegedIOException(url::openConnection);
        urlConnection.setConnectTimeout(2000);
        in = SocketAccess.doPrivilegedIOException(urlConnection::getInputStream);
        BufferedReader urlReader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));

        String metadataResult = urlReader.readLine();
        if (metadataResult == null || metadataResult.length() == 0) {
            throw new IOException("no gce metadata returned from [" + url + "] for [" + type.configName + "]");
        }
        // only one address: because we explicitly ask for only one via the Ec2HostnameType
        return new InetAddress[] { InetAddress.getByName(metadataResult) };
    } catch (IOException e) {
        throw new IOException("IOException caught when fetching InetAddress from [" + metadataUrl + "]", e);
    } finally {
        IOUtils.closeWhileHandlingException(in);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:Ec2NameResolver.java

示例14: isWritable

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
/**
 * Returns true if the path is writable.
 * Acts just like {@link Files#isWritable(Path)}, except won't
 * falsely return false for paths on SUBST'd drive letters
 * See https://bugs.openjdk.java.net/browse/JDK-8034057
 * Note this will set the file modification time (to its already-set value)
 * to test access.
 */
@SuppressForbidden(reason = "works around https://bugs.openjdk.java.net/browse/JDK-8034057")
public static boolean isWritable(Path path) throws IOException {
    boolean v = Files.isWritable(path);
    if (v || Constants.WINDOWS == false) {
        return v;
    }

    // isWritable returned false on windows, the hack begins!!!!!!
    // resetting the modification time is the least destructive/simplest
    // way to check for both files and directories, and fails early just
    // in getting the current value if file doesn't exist, etc
    try {
        Files.setLastModifiedTime(path, Files.getLastModifiedTime(path));
        return true;
    } catch (Throwable e) {
        return false;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:Environment.java

示例15: generateShardId

import org.elasticsearch.common.SuppressForbidden; //导入依赖的package包/类
@SuppressForbidden(reason = "Math#abs is trappy")
private int generateShardId(ClusterState clusterState, String index, String type, String id, @Nullable String routing) {
    IndexMetaData indexMetaData = clusterState.metaData().index(index);
    if (indexMetaData == null) {
        throw new IndexNotFoundException(index);
    }
    final Version createdVersion = indexMetaData.getCreationVersion();
    final HashFunction hashFunction = indexMetaData.getRoutingHashFunction();
    final boolean useType = indexMetaData.getRoutingUseType();

    final int hash;
    if (routing == null) {
        if (!useType) {
            hash = hash(hashFunction, id);
        } else {
            hash = hash(hashFunction, type, id);
        }
    } else {
        hash = hash(hashFunction, routing);
    }
    if (createdVersion.onOrAfter(Version.V_2_0_0_beta1)) {
        return MathUtils.mod(hash, indexMetaData.getNumberOfShards());
    } else {
        return Math.abs(hash % indexMetaData.getNumberOfShards());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:OperationRouting.java


注:本文中的org.elasticsearch.common.SuppressForbidden类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。