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

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

Introduction

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

Prototype

boolean MAC_OS_X

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

Click Source Link

Document

True iff running on Mac OS X

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}.
 *///w  ww  .  ja va2  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:io.crate.monitor.SysInfo.java

License:Apache License

/**
 * Retrieve system uptime in milliseconds
 * https://en.wikipedia.org/wiki/Uptime/*w  w  w  . j  a v a  2  s. co 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:org.apache.cassandra.utils.CLibrary.java

License:Apache License

public static String rlimitToString(long value) {
    assert Constants.LINUX || Constants.MAC_OS_X;
    if (value == CLibrary.RLIM_INFINITY) {
        return "unlimited";
    } else {/*  w  w w .  jav a  2s  . com*/
        // TODO, on java 8 use Long.toUnsignedString, since thats what it is.
        return Long.toUnsignedString(value);
    }
}

From source file:org.apache.solr.cloud.TestMiniSolrCloudClusterSSL.java

License:Apache License

public void testSslAndClientAuth() throws Exception {
    assumeFalse("SOLR-9039: SSL w/clientAuth does not work on MAC_OS_X", Constants.MAC_OS_X);

    final SSLTestConfig sslConfig = new SSLTestConfig(true, true);

    HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider());
    System.setProperty(ZkStateReader.URL_SCHEME, "https");
    checkClusterWithNodeReplacement(sslConfig);
}

From source file:org.apache.solr.update.processor.ScriptEngineTest.java

License:Apache License

@BeforeClass
public static void beforeClass() throws Exception {
    assumeFalse("https://twitter.com/UweSays/status/260487231880433664 / SOLR-4233: OS X bogusly starts AWT!",
            Constants.MAC_OS_X);
    Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
    Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript"));
}

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

License:Apache License

static List<Check> checks(final Settings settings) {
    final List<Check> checks = new ArrayList<>();
    checks.add(new HeapSizeCheck());
    final FileDescriptorCheck fileDescriptorCheck = Constants.MAC_OS_X ? new OsXFileDescriptorCheck()
            : new FileDescriptorCheck();
    checks.add(fileDescriptorCheck);//from  w  ww.j av a  2 s.c o  m
    checks.add(new MlockallCheck(BootstrapSettings.MEMORY_LOCK_SETTING.get(settings)));
    if (Constants.LINUX) {
        checks.add(new MaxNumberOfThreadsCheck());
    }
    if (Constants.LINUX || Constants.MAC_OS_X) {
        checks.add(new MaxSizeVirtualMemoryCheck());
    }
    if (Constants.LINUX) {
        checks.add(new MaxMapCountCheck());
    }
    checks.add(new ClientJvmCheck());
    checks.add(new OnErrorCheck());
    checks.add(new OnOutOfMemoryErrorCheck());
    return Collections.unmodifiableList(checks);
}

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

License:Apache License

static List<BootstrapCheck> checks(final Settings settings) {
    final List<BootstrapCheck> checks = new ArrayList<>();
    checks.add(new HeapSizeCheck());
    final FileDescriptorCheck fileDescriptorCheck = Constants.MAC_OS_X ? new OsXFileDescriptorCheck()
            : new FileDescriptorCheck();
    checks.add(fileDescriptorCheck);//from ww w .  ja va  2s.co m
    checks.add(new MlockallCheck(BootstrapSettings.MEMORY_LOCK_SETTING.get(settings)));
    if (Constants.LINUX) {
        checks.add(new MaxNumberOfThreadsCheck());
    }
    if (Constants.LINUX || Constants.MAC_OS_X) {
        checks.add(new MaxSizeVirtualMemoryCheck());
    }
    if (Constants.LINUX) {
        checks.add(new MaxMapCountCheck());
    }
    checks.add(new ClientJvmCheck());
    checks.add(new UseSerialGCCheck());
    checks.add(new SystemCallFilterCheck(BootstrapSettings.SYSTEM_CALL_FILTER_SETTING.get(settings)));
    checks.add(new OnErrorCheck());
    checks.add(new OnOutOfMemoryErrorCheck());
    checks.add(new G1GCCheck());
    return Collections.unmodifiableList(checks);
}

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

License:Apache License

public void testMaxSizeVirtualMemory() throws NodeValidationException {
    final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
    final AtomicLong maxSizeVirtualMemory = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
    final BootstrapChecks.MaxSizeVirtualMemoryCheck check = new BootstrapChecks.MaxSizeVirtualMemoryCheck() {
        @Override/*from   ww w  .ja v  a  2 s . c  o  m*/
        long getMaxSizeVirtualMemory() {
            return maxSizeVirtualMemory.get();
        }

        @Override
        long getRlimInfinity() {
            return rlimInfinity;
        }
    };

    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks
            .check(defaultContext, true, Collections.singletonList(check), "testMaxSizeVirtualMemory"));
    assertThat(e.getMessage(), containsString("max size virtual memory"));

    maxSizeVirtualMemory.set(rlimInfinity);

    BootstrapChecks.check(defaultContext, true, Collections.singletonList(check), "testMaxSizeVirtualMemory");

    // nothing should happen if max size virtual memory is not available
    maxSizeVirtualMemory.set(Long.MIN_VALUE);
    BootstrapChecks.check(defaultContext, true, Collections.singletonList(check), "testMaxSizeVirtualMemory");
}

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

License:Apache License

public void testMaxFileSizeCheck() throws NodeValidationException {
    final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
    final AtomicLong maxFileSize = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
    final BootstrapChecks.MaxFileSizeCheck check = new BootstrapChecks.MaxFileSizeCheck() {
        @Override/* ww  w.j a  va 2s. c o m*/
        long getMaxFileSize() {
            return maxFileSize.get();
        }

        @Override
        long getRlimInfinity() {
            return rlimInfinity;
        }
    };

    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks
            .check(defaultContext, true, Collections.singletonList(check), "testMaxFileSize"));
    assertThat(e.getMessage(), containsString("max file size"));

    maxFileSize.set(rlimInfinity);

    BootstrapChecks.check(defaultContext, true, Collections.singletonList(check), "testMaxFileSize");

    // nothing should happen if max file size is not available
    maxFileSize.set(Long.MIN_VALUE);
    BootstrapChecks.check(defaultContext, true, Collections.singletonList(check), "testMaxFileSize");
}

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

License:Apache License

public void testMaxSizeVirtualMemory() {
    final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
    final AtomicLong maxSizeVirtualMemory = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
    final BootstrapCheck.MaxSizeVirtualMemoryCheck check = new BootstrapCheck.MaxSizeVirtualMemoryCheck() {
        @Override//  ww  w . ja  v  a 2  s.  co  m
        long getMaxSizeVirtualMemory() {
            return maxSizeVirtualMemory.get();
        }

        @Override
        long getRlimInfinity() {
            return rlimInfinity;
        }
    };

    final RuntimeException e = expectThrows(RuntimeException.class, () -> BootstrapCheck.check(true, false,
            Collections.singletonList(check), "testMaxSizeVirtualMemory"));
    assertThat(e.getMessage(), containsString("max size virtual memory"));

    maxSizeVirtualMemory.set(rlimInfinity);

    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxSizeVirtualMemory");

    // nothing should happen if max size virtual memory is not
    // available
    maxSizeVirtualMemory.set(Long.MIN_VALUE);
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxSizeVirtualMemory");
}