Example usage for org.apache.lucene.util StringHelper randomId

List of usage examples for org.apache.lucene.util StringHelper randomId

Introduction

In this page you can find the example usage for org.apache.lucene.util StringHelper randomId.

Prototype

public static byte[] randomId() 

Source Link

Document

Generates a non-cryptographic globally unique id.

Usage

From source file:org.apache.solr.util.IdUtils.java

License:Apache License

/**
 * Generate a short random id (see {@link StringHelper#randomId()}).
 *//*w ww .j a v  a 2s  . c o m*/
public static final String randomId() {
    return StringHelper.idToString(StringHelper.randomId());
}

From source file:org.elasticsearch.bootstrap.Bootstrap.java

License:Apache License

/** initialize native resources */
public static void initializeNatives(Path tmpFile, boolean mlockAll, boolean seccomp, boolean ctrlHandler) {
    final ESLogger logger = Loggers.getLogger(Bootstrap.class);

    // check if the user is running as root, and bail
    if (Natives.definitelyRunningAsRoot()) {
        if (Boolean.parseBoolean(System.getProperty("es.insecure.allow.root"))) {
            logger.warn("running as ROOT user. this is a bad idea!");
        } else {/*w  w w  . ja  v  a  2  s .  com*/
            throw new RuntimeException("don't run elasticsearch as root.");
        }
    }

    // enable secure computing mode
    if (seccomp) {
        Natives.trySeccomp(tmpFile);
    }

    // mlockall if requested
    if (mlockAll) {
        if (Constants.WINDOWS) {
            Natives.tryVirtualLock();
        } else {
            Natives.tryMlockall();
        }
    }

    // listener for windows close event
    if (ctrlHandler) {
        Natives.addConsoleCtrlHandler(new ConsoleCtrlHandler() {
            @Override
            public boolean handle(int code) {
                if (CTRL_CLOSE_EVENT == code) {
                    logger.info("running graceful exit on windows");
                    Bootstrap.stop();
                    return true;
                }
                return false;
            }
        });
    }

    // force remainder of JNA to be loaded (if available).
    try {
        JNAKernel32Library.getInstance();
    } catch (Throwable ignored) {
        // we've already logged this.
    }

    // init lucene random seed. it will use /dev/urandom where available:
    StringHelper.randomId();
}

From source file:org.elasticsearch.bootstrap.BootstrapProxy.java

License:Apache License

/**
 * initialize native resources//w  w w . jav a2 s .  com
 */
static void initializeNatives(Path tmpFile, boolean mlockAll, boolean seccomp, boolean ctrlHandler) {
    final Logger logger = Loggers.getLogger(BootstrapProxy.class);

    // check if the user is running as root, and bail
    if (Natives.definitelyRunningAsRoot()) {
        throw new RuntimeException("can not run crate as root");
    }

    // enable secure computing mode
    if (seccomp) {
        Natives.trySeccomp(tmpFile);
    }

    // mlockall if requested
    if (mlockAll) {
        if (Constants.WINDOWS) {
            Natives.tryVirtualLock();
        } else {
            Natives.tryMlockall();
        }
    }

    // listener for windows close event
    if (ctrlHandler) {
        Natives.addConsoleCtrlHandler(code -> {
            if (ConsoleCtrlHandler.CTRL_CLOSE_EVENT == code) {
                logger.info("running graceful exit on windows");
                try {
                    BootstrapProxy.stop();
                } catch (IOException e) {
                    throw new ElasticsearchException("failed to stop node", e);
                }
                return true;
            }
            return false;
        });
    }

    // force remainder of JNA to be loaded (if available).
    try {
        JNAKernel32Library.getInstance();
    } catch (Exception ignored) {
        // we've already logged this.
    }

    Natives.trySetMaxNumberOfThreads();
    Natives.trySetMaxSizeVirtualMemory();

    // init lucene random seed. it will use /dev/urandom where available:
    StringHelper.randomId();
}

From source file:org.elasticsearch.bootstrap.Security.java

License:Apache License

/** 
 * Initializes securitymanager for the environment
 * Can only happen once!//  www.  j a va 2 s .c o  m
 */
static void configure(Environment environment) throws IOException {
    // init lucene random seed. it will use /dev/urandom where available.
    StringHelper.randomId();
    InputStream config = Security.class.getResourceAsStream(POLICY_RESOURCE);
    if (config == null) {
        throw new NoSuchFileException(POLICY_RESOURCE);
    }
    Path newConfig = processTemplate(config, environment);
    System.setProperty("java.security.policy", newConfig.toString());
    System.setSecurityManager(new SecurityManager());
    IOUtils.deleteFilesIgnoringExceptions(newConfig); // TODO: maybe log something if it fails?
}

From source file:org.sonar.search.SearchServer.java

License:Open Source License

private static void initBootstrap() {
    // init lucene random seed. it will use /dev/urandom where available:
    StringHelper.randomId();
}