本文整理汇总了Java中org.apache.lucene.util.Constants类的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Constants类属于org.apache.lucene.util包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solarisImpl
import org.apache.lucene.util.Constants; //导入依赖的package包/类
static void solarisImpl() {
// first be defensive: we can give nice errors this way, at the very least.
boolean supported = Constants.SUN_OS;
if (supported == false) {
throw new IllegalStateException("bug: should not be trying to initialize priv_set for an unsupported OS");
}
// we couldn't link methods, could be some really ancient Solaris or some bug
if (libc_solaris == null) {
throw new UnsupportedOperationException("priv_set unavailable: could not link methods. requires Solaris 10+");
}
// drop a null-terminated list of privileges
if (libc_solaris.priv_set(PRIV_OFF, PRIV_ALLSETS, PRIV_PROC_FORK, PRIV_PROC_EXEC, null) != 0) {
throw new UnsupportedOperationException("priv_set unavailable: priv_set(): " + JNACLibrary.strerror(Native.getLastError()));
}
logger.debug("Solaris priv_set initialization successful");
}
示例2: init
import org.apache.lucene.util.Constants; //导入依赖的package包/类
/**
* Attempt to drop the capability to execute for the process.
* <p>
* This is best effort and OS and architecture dependent. It may throw any Throwable.
* @return 0 if we can do this for application threads, 1 for the entire process
*/
static int init(Path tmpFile) throws Exception {
if (Constants.LINUX) {
return linuxImpl();
} else if (Constants.MAC_OS_X) {
// try to enable both mechanisms if possible
bsdImpl();
macImpl(tmpFile);
return 1;
} else if (Constants.SUN_OS) {
solarisImpl();
return 1;
} else if (Constants.FREE_BSD || OPENBSD) {
bsdImpl();
return 1;
} else if (Constants.WINDOWS) {
windowsImpl();
return 1;
} else {
throw new UnsupportedOperationException("syscall filtering not supported for OS: '" + Constants.OS_NAME + "'");
}
}
示例3: isWritable
import org.apache.lucene.util.Constants; //导入依赖的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;
}
}
示例4: testIterable
import org.apache.lucene.util.Constants; //导入依赖的package包/类
public void testIterable() throws Exception {
Map<String, Iterable<?>> iterables = new HashMap<>();
iterables.put("{'iter':null}", (Iterable) null);
iterables.put("{'iter':[]}", Collections.emptyList());
iterables.put("{'iter':['a','b']}", Arrays.asList("a", "b"));
final String path = Constants.WINDOWS ? "{'iter':'path\\\\to\\\\file'}" : "{'iter':'path/to/file'}";
iterables.put(path, PathUtils.get("path", "to", "file"));
final String paths = Constants.WINDOWS ? "{'iter':['a\\\\b\\\\c','c\\\\d']}" : "{'iter':['a/b/c','c/d']}";
iterables.put(paths, Arrays.asList(PathUtils.get("a", "b", "c"), PathUtils.get("c", "d")));
for (Map.Entry<String, Iterable<?>> i : iterables.entrySet()) {
final String expected = i.getKey();
assertResult(expected, () -> builder().startObject().field("iter", i.getValue()).endObject());
assertResult(expected, () -> builder().startObject().field("iter").value(i.getValue()).endObject());
}
}
示例5: trySetMaxNumberOfThreads
import org.apache.lucene.util.Constants; //导入依赖的package包/类
static void trySetMaxNumberOfThreads() {
if (Constants.LINUX) {
// this is only valid on Linux and the value *is* different on OS X
// see /usr/include/sys/resource.h on OS X
// on Linux the resource RLIMIT_NPROC means *the number of threads*
// this is in opposition to BSD-derived OSes
final int rlimit_nproc = 6;
final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit();
if (JNACLibrary.getrlimit(rlimit_nproc, rlimit) == 0) {
MAX_NUMBER_OF_THREADS = rlimit.rlim_cur.longValue();
} else {
logger.warn("unable to retrieve max number of threads [" + JNACLibrary.strerror(Native.getLastError()) + "]");
}
}
}
示例6: newFSDirectory
import org.apache.lucene.util.Constants; //导入依赖的package包/类
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException {
final String storeType = indexSettings.get(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.DEFAULT.getSettingsKey());
if (IndexStoreModule.Type.FS.match(storeType) || IndexStoreModule.Type.DEFAULT.match(storeType)) {
final FSDirectory open = FSDirectory.open(location, lockFactory); // use lucene defaults
if (open instanceof MMapDirectory && Constants.WINDOWS == false) {
return newDefaultDir(location, (MMapDirectory) open, lockFactory);
}
return open;
} else if (IndexStoreModule.Type.SIMPLEFS.match(storeType)) {
return new SimpleFSDirectory(location, lockFactory);
} else if (IndexStoreModule.Type.NIOFS.match(storeType)) {
return new NIOFSDirectory(location, lockFactory);
} else if (IndexStoreModule.Type.MMAPFS.match(storeType)) {
return new MMapDirectory(location, lockFactory);
}
throw new IllegalArgumentException("No directory found for type [" + storeType + "]");
}
示例7: testSetMaxSizeVirtualMemory
import org.apache.lucene.util.Constants; //导入依赖的package包/类
public void testSetMaxSizeVirtualMemory() throws IOException {
if (Constants.LINUX) {
final List<String> lines = Files.readAllLines(PathUtils.get("/proc/self/limits"));
if (!lines.isEmpty()) {
for (String line : lines) {
if (line != null && line.startsWith("Max address space")) {
final String[] fields = line.split("\\s+");
final String limit = fields[3];
assertEquals(JNANatives.rlimitToString(JNANatives.MAX_SIZE_VIRTUAL_MEMORY), limit);
return;
}
}
}
fail("should have read max size virtual memory from /proc/self/limits");
} else if (Constants.MAC_OS_X) {
assertThat(JNANatives.MAX_SIZE_VIRTUAL_MEMORY, anyOf(equalTo(Long.MIN_VALUE), greaterThanOrEqualTo(0L)));
} else {
assertThat(JNANatives.MAX_SIZE_VIRTUAL_MEMORY, equalTo(Long.MIN_VALUE));
}
}
示例8: testSetMaximumNumberOfThreads
import org.apache.lucene.util.Constants; //导入依赖的package包/类
public void testSetMaximumNumberOfThreads() throws IOException {
if (Constants.LINUX) {
final List<String> lines = Files.readAllLines(PathUtils.get("/proc/self/limits"));
if (!lines.isEmpty()) {
for (String line : lines) {
if (line != null && line.startsWith("Max processes")) {
final String[] fields = line.split("\\s+");
final long limit = "unlimited".equals(fields[2]) ? JNACLibrary.RLIM_INFINITY : Long.parseLong(fields[2]);
assertThat(JNANatives.MAX_NUMBER_OF_THREADS, equalTo(limit));
return;
}
}
}
fail("should have read max processes from /proc/self/limits");
} else {
assertThat(JNANatives.MAX_NUMBER_OF_THREADS, equalTo(-1L));
}
}
示例9: testPutDocument
import org.apache.lucene.util.Constants; //导入依赖的package包/类
/**
* Create an index and index some docs
*/
public void testPutDocument() {
// TODO: remove when Netty 4.1.5 is upgraded to Netty 4.1.6 including https://github.com/netty/netty/pull/5778
assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9);
Client client = getClient();
// START SNIPPET: java-doc-index-doc-simple
client.prepareIndex(index, "doc", "1") // Index, Type, Id
.setSource("foo", "bar") // Simple document: { "foo" : "bar" }
.get(); // Execute and wait for the result
// END SNIPPET: java-doc-index-doc-simple
// START SNIPPET: java-doc-admin-indices-refresh
// Prepare a refresh action on a given index, execute and wait for the result
client.admin().indices().prepareRefresh(index).get();
// END SNIPPET: java-doc-admin-indices-refresh
// START SNIPPET: java-doc-search-simple
SearchResponse searchResponse = client.prepareSearch(index).get();
assertThat(searchResponse.getHits().getTotalHits(), is(1L));
// END SNIPPET: java-doc-search-simple
}
示例10: testReservedCapture
import org.apache.lucene.util.Constants; //导入依赖的package包/类
public void testReservedCapture() {
assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9);
String compare = "boolean compare(Supplier s, def v) {s.get() == v}";
assertEquals(true, exec(compare + "compare(() -> new ArrayList(), new ArrayList())"));
assertEquals(true, exec(compare + "compare(() -> { new ArrayList() }, new ArrayList())"));
Map<String, Object> params = new HashMap<>();
params.put("key", "value");
params.put("number", 2);
assertEquals(true, exec(compare + "compare(() -> { return params['key'] }, 'value')", params, true));
assertEquals(false, exec(compare + "compare(() -> { return params['nokey'] }, 'value')", params, true));
assertEquals(true, exec(compare + "compare(() -> { return params['nokey'] }, null)", params, true));
assertEquals(true, exec(compare + "compare(() -> { return params['number'] }, 2)", params, true));
assertEquals(false, exec(compare + "compare(() -> { return params['number'] }, 'value')", params, true));
assertEquals(false, exec(compare + "compare(() -> { if (params['number'] == 2) { return params['number'] }" +
"else { return params['key'] } }, 'value')", params, true));
assertEquals(true, exec(compare + "compare(() -> { if (params['number'] == 2) { return params['number'] }" +
"else { return params['key'] } }, 2)", params, true));
assertEquals(true, exec(compare + "compare(() -> { if (params['number'] == 1) { return params['number'] }" +
"else { return params['key'] } }, 'value')", params, true));
assertEquals(false, exec(compare + "compare(() -> { if (params['number'] == 1) { return params['number'] }" +
"else { return params['key'] } }, 2)", params, true));
}
示例11: check
import org.apache.lucene.util.Constants; //导入依赖的package包/类
/**
* Checks that the current JVM is "ok". This means it doesn't have severe bugs that cause data corruption.
*/
static void check() {
if (Boolean.parseBoolean(System.getProperty(JVM_BYPASS))) {
Loggers.getLogger(JVMCheck.class).warn("bypassing jvm version check for version [{}], this can result in data corruption!", fullVersion());
} else if ("Oracle Corporation".equals(Constants.JVM_VENDOR)) {
HotspotBug bug = JVM_BROKEN_HOTSPOT_VERSIONS.get(Constants.JVM_VERSION);
if (bug != null) {
if (bug.workAround != null && ManagementFactory.getRuntimeMXBean().getInputArguments().contains(bug.workAround)) {
Loggers.getLogger(JVMCheck.class).warn(bug.getWarningMessage());
} else {
throw new RuntimeException(bug.getErrorMessage());
}
}
} else if ("IBM Corporation".equals(Constants.JVM_VENDOR)) {
// currently some old JVM versions from IBM will easily result in index corruption.
// 2.8+ seems ok for ES from testing.
float version = Float.POSITIVE_INFINITY;
try {
version = Float.parseFloat(Constants.JVM_VERSION);
} catch (NumberFormatException ignored) {
// this is just a simple best-effort to detect old runtimes,
// if we cannot parse it, we don't fail.
}
if (version < 2.8f) {
StringBuilder sb = new StringBuilder();
sb.append("IBM J9 runtimes < 2.8 suffer from several bugs which can cause data corruption.");
sb.append(System.lineSeparator());
sb.append("Your version: " + fullVersion());
sb.append(System.lineSeparator());
sb.append("Please upgrade the JVM to a recent IBM JDK");
throw new RuntimeException(sb.toString());
}
}
}
示例12: testIterable_AsList
import org.apache.lucene.util.Constants; //导入依赖的package包/类
public void testIterable_AsList() {
assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(true,
exec("List l = new ArrayList(); return l.asList() === l"));
assertEquals(5,
exec("Set l = new HashSet(); l.add(5); return l.asList()[0]"));
}
示例13: testCollection_Collect
import org.apache.lucene.util.Constants; //导入依赖的package包/类
public void testCollection_Collect() {
assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(Arrays.asList(2, 3),
exec("List l = new ArrayList(); l.add(1); l.add(2); l.collect(x -> x + 1)"));
assertEquals(asSet(2, 3),
exec("List l = new ArrayList(); l.add(1); l.add(2); l.collect(new HashSet(), x -> x + 1)"));
}
示例14: trySetMaxSizeVirtualMemory
import org.apache.lucene.util.Constants; //导入依赖的package包/类
static void trySetMaxSizeVirtualMemory() {
if (Constants.LINUX || Constants.MAC_OS_X) {
final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit();
if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_AS, rlimit) == 0) {
MAX_SIZE_VIRTUAL_MEMORY = rlimit.rlim_cur.longValue();
} else {
logger.warn("unable to retrieve max size virtual memory [" + JNACLibrary.strerror(Native.getLastError()) + "]");
}
}
}
示例15: macImpl
import org.apache.lucene.util.Constants; //导入依赖的package包/类
/** try to install our custom rule profile into sandbox_init() to block execution */
private static void macImpl(Path tmpFile) throws IOException {
// first be defensive: we can give nice errors this way, at the very least.
boolean supported = Constants.MAC_OS_X;
if (supported == false) {
throw new IllegalStateException("bug: should not be trying to initialize seatbelt for an unsupported OS");
}
// we couldn't link methods, could be some really ancient OS X (< Leopard) or some bug
if (libc_mac == null) {
throw new UnsupportedOperationException("seatbelt unavailable: could not link methods. requires Leopard or above.");
}
// write rules to a temporary file, which will be passed to sandbox_init()
Path rules = Files.createTempFile(tmpFile, "es", "sb");
Files.write(rules, Collections.singleton(SANDBOX_RULES));
boolean success = false;
try {
PointerByReference errorRef = new PointerByReference();
int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef);
// if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the buffer
if (ret != 0) {
Pointer errorBuf = errorRef.getValue();
RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0));
libc_mac.sandbox_free_error(errorBuf);
throw e;
}
logger.debug("OS X seatbelt initialization successful");
success = true;
} finally {
if (success) {
Files.delete(rules);
} else {
IOUtils.deleteFilesIgnoringExceptions(rules);
}
}
}