Skip to content

Commit 06b3130

Browse files
authored
Add elasticsearch-nio jar for base nio classes (#27801)
This is related to #27802. This commit adds a jar called elasticsearch-nio that contains the base nio classes that will be used for the tcp nio transport and eventually the http nio transport. The jar does not depend on elasticsearch:core, so all references to core have been removed.
1 parent 8bd7a19 commit 06b3130

File tree

57 files changed

+694
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+694
-346
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ subprojects {
177177
"org.elasticsearch:rest-api-spec:${version}": ':rest-api-spec',
178178
"org.elasticsearch:elasticsearch:${version}": ':core',
179179
"org.elasticsearch:elasticsearch-cli:${version}": ':core:cli',
180+
"org.elasticsearch:elasticsearch-nio:${version}": ':libs:elasticsearch-nio',
180181
"org.elasticsearch.client:elasticsearch-rest-client:${version}": ':client:rest',
181182
"org.elasticsearch.client:elasticsearch-rest-client-sniffer:${version}": ':client:sniffer',
182183
"org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}": ':client:rest-high-level',

core/src/main/java/org/elasticsearch/action/support/AdapterActionFuture.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919

2020
package org.elasticsearch.action.support;
2121

22-
import org.elasticsearch.ElasticsearchException;
2322
import org.elasticsearch.ElasticsearchTimeoutException;
2423
import org.elasticsearch.action.ActionFuture;
2524
import org.elasticsearch.action.ActionListener;
2625
import org.elasticsearch.common.unit.TimeValue;
2726
import org.elasticsearch.common.util.concurrent.BaseFuture;
28-
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
27+
import org.elasticsearch.common.util.concurrent.FutureUtils;
2928

3029
import java.util.concurrent.ExecutionException;
3130
import java.util.concurrent.TimeUnit;
@@ -35,14 +34,7 @@ public abstract class AdapterActionFuture<T, L> extends BaseFuture<T> implements
3534

3635
@Override
3736
public T actionGet() {
38-
try {
39-
return get();
40-
} catch (InterruptedException e) {
41-
Thread.currentThread().interrupt();
42-
throw new IllegalStateException("Future got interrupted", e);
43-
} catch (ExecutionException e) {
44-
throw rethrowExecutionException(e);
45-
}
37+
return FutureUtils.get(this);
4638
}
4739

4840
@Override
@@ -62,33 +54,7 @@ public T actionGet(TimeValue timeout) {
6254

6355
@Override
6456
public T actionGet(long timeout, TimeUnit unit) {
65-
try {
66-
return get(timeout, unit);
67-
} catch (TimeoutException e) {
68-
throw new ElasticsearchTimeoutException(e);
69-
} catch (InterruptedException e) {
70-
Thread.currentThread().interrupt();
71-
throw new IllegalStateException("Future got interrupted", e);
72-
} catch (ExecutionException e) {
73-
throw rethrowExecutionException(e);
74-
}
75-
}
76-
77-
static RuntimeException rethrowExecutionException(ExecutionException e) {
78-
if (e.getCause() instanceof ElasticsearchException) {
79-
ElasticsearchException esEx = (ElasticsearchException) e.getCause();
80-
Throwable root = esEx.unwrapCause();
81-
if (root instanceof ElasticsearchException) {
82-
return (ElasticsearchException) root;
83-
} else if (root instanceof RuntimeException) {
84-
return (RuntimeException) root;
85-
}
86-
return new UncategorizedExecutionException("Failed execution", root);
87-
} else if (e.getCause() instanceof RuntimeException) {
88-
return (RuntimeException) e.getCause();
89-
} else {
90-
return new UncategorizedExecutionException("Failed execution", e);
91-
}
57+
return FutureUtils.get(this, timeout, unit);
9258
}
9359

9460
@Override

core/src/main/java/org/elasticsearch/common/util/concurrent/FutureUtils.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@
1919

2020
package org.elasticsearch.common.util.concurrent;
2121

22+
import org.elasticsearch.ElasticsearchException;
23+
import org.elasticsearch.ElasticsearchTimeoutException;
24+
import org.elasticsearch.action.support.AdapterActionFuture;
2225
import org.elasticsearch.common.SuppressForbidden;
2326

27+
import java.util.concurrent.ExecutionException;
2428
import java.util.concurrent.Future;
29+
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.TimeoutException;
2531

2632
public class FutureUtils {
2733

@@ -33,4 +39,60 @@ public static boolean cancel(Future<?> toCancel) {
3339
return false;
3440
}
3541

42+
/**
43+
* Calls {@link Future#get()} without the checked exceptions.
44+
*
45+
* @param future to dereference
46+
* @param <T> the type returned
47+
* @return the value of the future
48+
*/
49+
public static <T> T get(Future<T> future) {
50+
try {
51+
return future.get();
52+
} catch (InterruptedException e) {
53+
Thread.currentThread().interrupt();
54+
throw new IllegalStateException("Future got interrupted", e);
55+
} catch (ExecutionException e) {
56+
throw rethrowExecutionException(e);
57+
}
58+
}
59+
60+
/**
61+
* Calls {@link Future#get(long, TimeUnit)} without the checked exceptions.
62+
*
63+
* @param future to dereference
64+
* @param timeout to wait
65+
* @param unit for timeout
66+
* @param <T> the type returned
67+
* @return the value of the future
68+
*/
69+
public static <T> T get(Future<T> future, long timeout, TimeUnit unit) {
70+
try {
71+
return future.get(timeout, unit);
72+
} catch (TimeoutException e) {
73+
throw new ElasticsearchTimeoutException(e);
74+
} catch (InterruptedException e) {
75+
Thread.currentThread().interrupt();
76+
throw new IllegalStateException("Future got interrupted", e);
77+
} catch (ExecutionException e) {
78+
throw FutureUtils.rethrowExecutionException(e);
79+
}
80+
}
81+
82+
public static RuntimeException rethrowExecutionException(ExecutionException e) {
83+
if (e.getCause() instanceof ElasticsearchException) {
84+
ElasticsearchException esEx = (ElasticsearchException) e.getCause();
85+
Throwable root = esEx.unwrapCause();
86+
if (root instanceof ElasticsearchException) {
87+
return (ElasticsearchException) root;
88+
} else if (root instanceof RuntimeException) {
89+
return (RuntimeException) root;
90+
}
91+
return new UncategorizedExecutionException("Failed execution", root);
92+
} else if (e.getCause() instanceof RuntimeException) {
93+
return (RuntimeException) e.getCause();
94+
} else {
95+
return new UncategorizedExecutionException("Failed execution", e);
96+
}
97+
}
3698
}

core/src/main/resources/org/elasticsearch/bootstrap/test-framework.policy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ grant codeBase "${codebase.mocksocket}" {
6363
permission java.net.SocketPermission "*", "accept,connect";
6464
};
6565

66+
grant codeBase "${codebase.elasticsearch-nio}" {
67+
// elasticsearch-nio makes and accepts socket connections
68+
permission java.net.SocketPermission "*", "accept,connect";
69+
};
70+
6671
grant codeBase "${codebase.elasticsearch-rest-client}" {
6772
// rest makes socket connections for rest tests
6873
permission java.net.SocketPermission "*", "connect";

libs/elasticsearch-nio/build.gradle

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.elasticsearch.gradle.precommit.PrecommitTasks
21+
22+
apply plugin: 'elasticsearch.build'
23+
apply plugin: 'nebula.maven-base-publish'
24+
apply plugin: 'nebula.maven-scm'
25+
26+
archivesBaseName = 'elasticsearch-nio'
27+
28+
publishing {
29+
publications {
30+
nebula {
31+
artifactId = archivesBaseName
32+
}
33+
}
34+
}
35+
36+
dependencies {
37+
compile "org.apache.logging.log4j:log4j-api:${versions.log4j}"
38+
39+
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
40+
testCompile "junit:junit:${versions.junit}"
41+
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
42+
testCompile("org.elasticsearch.test:framework:${version}") {
43+
exclude group: 'org.elasticsearch', module: 'elasticsearch-nio'
44+
}
45+
}
46+
47+
forbiddenApisMain {
48+
// elasticsearch-nio does not depend on core, so only jdk signatures should be checked
49+
// es-all is not checked as we connect and accept sockets
50+
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
51+
}
52+
53+
//JarHell is part of es core, which we don't want to pull in
54+
jarHell.enabled=false
55+
56+
thirdPartyAudit.excludes = [
57+
'org/osgi/framework/AdaptPermission',
58+
'org/osgi/framework/AdminPermission',
59+
'org/osgi/framework/Bundle',
60+
'org/osgi/framework/BundleActivator',
61+
'org/osgi/framework/BundleContext',
62+
'org/osgi/framework/BundleEvent',
63+
'org/osgi/framework/SynchronousBundleListener',
64+
'org/osgi/framework/wiring/BundleWire',
65+
'org/osgi/framework/wiring/BundleWiring'
66+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7a2999229464e7a324aa503c0a52ec0f05efe7bd

0 commit comments

Comments
 (0)