Example usage for org.apache.lucene.util Constants WINDOWS

List of usage examples for org.apache.lucene.util Constants WINDOWS

Introduction

In this page you can find the example usage for org.apache.lucene.util Constants WINDOWS.

Prototype

boolean WINDOWS

To view the source code for org.apache.lucene.util Constants WINDOWS.

Click Source Link

Document

True iff running on Windows.

Usage

From source file:com.b2international.index.lucene.Directories.java

License:Apache License

/**
 * Just like {@link #openFile(File)}, but allows you to also specify a custom {@link LockFactory}.
 *///from   ww  w  .j a va  2  s  .  c o m
public static FSDirectory openFile(final Path path, final LockFactory lockFactory) throws IOException {
    if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX || Constants.MAC_OS_X)
            && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {

        return new MMapDirectory(path, lockFactory);
    } else if (Constants.WINDOWS) {
        return new SimpleFSDirectory(path, lockFactory);
    } else {
        return new NIOFSDirectory(path, lockFactory);
    }
}

From source file:com.bluedragon.search.collection.Collection.java

License:Open Source License

private void setDirectory() throws IOException {
    if (directory != null)
        return;/*from ww w .j  a  va2s .  co  m*/

    if (Constants.WINDOWS) {
        directory = new SimpleFSDirectory(FileSystems.getDefault().getPath(collectionpath));
    } else {
        directory = new NIOFSDirectory(FileSystems.getDefault().getPath(collectionpath));
    }

    File touchFile = new File(collectionpath, "openbd.created");
    if (touchFile.exists())
        created = touchFile.lastModified();
    else
        created = System.currentTimeMillis();
}

From source file:com.petalmd.armor.authentication.backend.waffle.WaffleAuthenticationBackend.java

License:Apache License

@Inject
public WaffleAuthenticationBackend(final Settings settings, final IWindowsAuthProvider authProvider) {
    this.settings = settings;

    this.authProvider = authProvider;
    stripDomain = settings.getAsBoolean(ConfigConstants.ARMOR_AUTHENTICATION_WAFFLE_STRIP_DOMAIN, true);

    if (!Constants.WINDOWS) {
        throw new ElasticsearchException(
                "Waffle works only on Windows operating system, not on " + System.getProperty("os.name"));
    }//from  w  w w .  ja  v a  2 s.c  om

}

From source file:com.petalmd.armor.authentication.http.waffle.HTTPWaffleAuthenticator.java

License:Apache License

@Inject
public HTTPWaffleAuthenticator(final Settings settings, final IWindowsAuthProvider authProvider) {
    this.settings = settings;

    this.authProvider = authProvider;

    if (!Constants.WINDOWS) {
        throw new ElasticsearchException(
                "Waffle works only on Windows operating system, not on " + System.getProperty("os.name"));
    }/* w w w. j  av a 2s. c  o m*/

}

From source file:com.petalmd.armor.authorization.waffle.WaffleAuthorizator.java

License:Apache License

@Inject
public WaffleAuthorizator(final Settings settings) {

    this.settings = settings;

    if (!Constants.WINDOWS) {
        throw new ElasticsearchException(
                "Waffle works only on Windows operating system, not on " + System.getProperty("os.name"));
    }/*from ww  w  .j a  v  a  2  s .  c om*/

}

From source file:io.crate.integrationtests.TransportSQLActionClassLifecycleTest.java

License:Apache License

@Test
public void testArithmeticFunctions() throws Exception {
    SQLResponse response = execute("select ((2 * 4 - 2 + 1) / 2) % 3 from sys.cluster");
    assertThat(response.cols()[0], is("(((((2 * 4) - 2) + 1) / 2) % 3)"));
    assertThat((Long) response.rows()[0][0], is(0L));

    response = execute("select ((2 * 4.0 - 2 + 1) / 2) % 3 from sys.cluster");
    assertThat((Double) response.rows()[0][0], is(0.5));

    response = execute("select ? + 2 from sys.cluster", $(1));
    assertThat((Long) response.rows()[0][0], is(3L));

    if (!Constants.WINDOWS) {
        response = execute("select load['1'] + load['5'], load['1'], load['5'] from sys.nodes limit 1");
        assertEquals(response.rows()[0][0], (Double) response.rows()[0][1] + (Double) response.rows()[0][2]);
    }/*from   w  w w  . ja  v  a 2s . c  o  m*/
}

From source file:io.crate.monitor.SysInfo.java

License:Apache License

/**
 * Retrieve system uptime in milliseconds
 * https://en.wikipedia.org/wiki/Uptime//from w w w  . ja va 2s .  c  o m
 */
static long getSystemUptime() {
    long uptime = -1L;
    if (Constants.WINDOWS) {
        List<String> lines = SysInfo.sysCall(new String[] { "net", "stats", "srv" }, "");
        for (String line : lines) {
            if (line.startsWith("Statistics since")) {
                SimpleDateFormat format = new SimpleDateFormat("'Statistics since' MM/dd/yyyy hh:mm:ss a",
                        Locale.ROOT);
                try {
                    Date bootTime = format.parse(line);
                    return System.currentTimeMillis() - bootTime.getTime();
                } catch (ParseException e) {
                    LOGGER.debug("Failed to parse uptime: {}", e.getMessage());
                }
            }
        }
    } else if (Constants.LINUX) {
        File procUptime = new File("/proc/uptime");
        if (procUptime.exists()) {
            try {
                List<String> lines = Files.readAllLines(procUptime.toPath());
                if (!lines.isEmpty()) {
                    String[] parts = lines.get(0).split(" ");
                    if (parts.length == 2) {
                        Double uptimeMillis = Float.parseFloat(parts[1]) * 1000.0;
                        return uptimeMillis.longValue();
                    }
                }
            } catch (IOException e) {
                LOGGER.debug("Failed to read '{}': {}", procUptime.getAbsolutePath(), e.getMessage());
            }
        }
    } else if (Constants.MAC_OS_X) {
        Pattern pattern = Pattern.compile("kern.boottime: \\{ sec = (\\d+), usec = (\\d+) \\} .*");
        List<String> lines = SysInfo.sysCall(new String[] { "sysctl", "kern.boottime" }, "");
        for (String line : lines) {
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                return Long.parseLong(matcher.group(1)) * 1000L;
            }
        }
    }
    return uptime;
}

From source file:oldes.OldElasticsearch.java

License:Apache License

public static void main(String[] args) throws IOException {
    Path baseDir = Paths.get(args[0]);
    Path unzipDir = Paths.get(args[1]);

    // 0.90 must be explicitly foregrounded
    boolean explicitlyForeground;
    switch (args[2]) {
    case "true":
        explicitlyForeground = true;/* w  w  w .ja v  a2  s .  c  o m*/
        break;
    case "false":
        explicitlyForeground = false;
        break;
    default:
        System.err.println("the third argument must be true or false");
        System.exit(1);
        return;
    }

    Iterator<Path> children = Files.list(unzipDir).iterator();
    if (false == children.hasNext()) {
        System.err.println("expected the es directory to contain a single child directory but contained none.");
        System.exit(1);
    }
    Path esDir = children.next();
    if (children.hasNext()) {
        System.err.println("expected the es directory to contains a single child directory but contained ["
                + esDir + "] and [" + children.next() + "].");
        System.exit(1);
    }
    if (false == Files.isDirectory(esDir)) {
        System.err.println(
                "expected the es directory to contains a single child directory but contained a single child file.");
        System.exit(1);
    }

    Path bin = esDir.resolve("bin").resolve("elasticsearch" + (Constants.WINDOWS ? ".bat" : ""));
    Path config = esDir.resolve("config").resolve("elasticsearch.yml");

    Files.write(config, Arrays.asList("http.port: 0", "transport.tcp.port: 0", "network.host: 127.0.0.1"),
            StandardCharsets.UTF_8);

    List<String> command = new ArrayList<>();
    command.add(bin.toString());
    if (explicitlyForeground) {
        command.add("-f");
    }
    command.add("-p");
    command.add("../pid");
    ProcessBuilder subprocess = new ProcessBuilder(command);
    Process process = subprocess.start();
    System.out.println("Running " + command);

    int pid = 0;
    int port = 0;

    Pattern pidPattern = Pattern.compile("pid\\[(\\d+)\\]");
    Pattern httpPortPattern = Pattern.compile("\\[http\\s+\\].+bound_address.+127\\.0\\.0\\.1:(\\d+)");
    try (BufferedReader stdout = new BufferedReader(
            new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
        String line;
        while ((line = stdout.readLine()) != null && (pid == 0 || port == 0)) {
            System.out.println(line);
            Matcher m = pidPattern.matcher(line);
            if (m.find()) {
                pid = Integer.parseInt(m.group(1));
                System.out.println("Found pid:  " + pid);
                continue;
            }
            m = httpPortPattern.matcher(line);
            if (m.find()) {
                port = Integer.parseInt(m.group(1));
                System.out.println("Found port:  " + port);
                continue;
            }
        }
    }

    if (port == 0) {
        System.err.println("port not found");
        System.exit(1);
    }

    Path tmp = Files.createTempFile(baseDir, null, null);
    Files.write(tmp, Integer.toString(port).getBytes(StandardCharsets.UTF_8));
    Files.move(tmp, baseDir.resolve("ports"), StandardCopyOption.ATOMIC_MOVE);
}

From source file:org.apache.cassandra.utils.CLibrary.java

License:Apache License

/** Returns true if user is root, false if not, or if we don't know */
public static boolean definitelyRunningAsRoot() {
    if (Constants.WINDOWS) {
        return false; // don't know
    }// w w w . j  a  v a  2  s . c o  m
    try {
        return geteuid() == 0;
    } catch (UnsatisfiedLinkError e) {
        // this will have already been logged by Kernel32Library, no need to repeat it
        return false;
    }
}

From source file:org.apache.jackrabbit.core.integration.InterruptedQueryTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    if (Constants.WINDOWS) {
        return;//from   w w  w .  j av  a  2  s  . c  om
    }
    deleteAll();
    FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("repository-with-SimpleFSDirectory.xml"),
            new File(getTestDir(), "repository.xml"));
    repo = RepositoryImpl.create(RepositoryConfig.create(getTestDir()));
    session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
}