Skip to content

Commit 0be15ef

Browse files
committed
es 7.2.0 support
1 parent 75c531d commit 0be15ef

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.ansj</groupId>
66
<artifactId>elasticsearch-analysis-ansj</artifactId>
7-
<version>7.1.1.0</version>
7+
<version>7.2.0.0</version>
88
<description>elasticsearch analysis by ansj</description>
99
<name>elasticsearch-analysis-ansj</name>
1010
<url>http://maven.nlpcn.org</url>
@@ -21,7 +21,7 @@
2121
<runSuite>**/MainTestSuite.class</runSuite>
2222
<elasticsearch.plugin.name>elasticsearch-analysis-ansj</elasticsearch.plugin.name>
2323
<elasticsearch.plugin.java.version>1.8</elasticsearch.plugin.java.version>
24-
<elasticsearch.version>7.1.1</elasticsearch.version>
24+
<elasticsearch.version>7.2.0</elasticsearch.version>
2525
<elasticsearch.plugin.classname>org.ansj.elasticsearch.plugin.AnalysisAnsjPlugin</elasticsearch.plugin.classname>
2626
</properties>
2727

src/main/java/org/ansj/elasticsearch/action/AnsjAction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ public AnsjResponse newResponse() {
2222

2323
@Override
2424
public Writeable.Reader<AnsjResponse> getResponseReader() {
25-
return in -> {
26-
AnsjResponse response = new AnsjResponse();
27-
response.readFrom(in);
28-
return response;
29-
};
25+
return AnsjResponse::new;
3026
}
3127
}

src/main/java/org/ansj/elasticsearch/action/AnsjResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public AnsjResponse(Map<String, ?> map) {
2626
this.map.putAll(map);
2727
}
2828

29+
public AnsjResponse(StreamInput in) throws IOException {
30+
readFrom(in);
31+
}
32+
2933
public AnsjResponse put(String key, Object value) {
3034
map.put(key, value);
3135
return this;

src/main/java/org/ansj/elasticsearch/action/TransportAnsjAction.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.cluster.service.ClusterService;
3434
import org.elasticsearch.common.inject.Inject;
3535
import org.elasticsearch.common.io.stream.StreamInput;
36+
import org.elasticsearch.common.io.stream.Writeable;
3637
import org.elasticsearch.index.shard.ShardId;
3738
import org.elasticsearch.threadpool.ThreadPool;
3839
import org.elasticsearch.transport.TransportException;
@@ -245,7 +246,8 @@ private AnsjResponse flushConfigAll() {
245246

246247
final CountDownLatch countDownLatch = new CountDownLatch(nodes.getSize());
247248

248-
final Map<String, String> result = new HashMap<>();
249+
final Map<String, String> result = new HashMap<>(16);
250+
final Writeable.Reader<AnsjResponse> reader = getResponseReader();
249251

250252
for (final DiscoveryNode node : nodes) {
251253

@@ -254,9 +256,7 @@ private AnsjResponse flushConfigAll() {
254256
TransportResponseHandler<AnsjResponse> rep = new TransportResponseHandler<AnsjResponse>() {
255257
@Override
256258
public AnsjResponse read(StreamInput in) throws IOException {
257-
AnsjResponse instance = newResponse();
258-
instance.readFrom(in);
259-
return instance;
259+
return reader.read(in);
260260
}
261261

262262
@Override
@@ -315,7 +315,8 @@ private AnsjResponse flushDicAll(AnsjRequest request) {
315315

316316
final CountDownLatch countDownLatch = new CountDownLatch(nodes.getSize());
317317

318-
final Map<String, String> result = new HashMap<>();
318+
final Map<String, String> result = new HashMap<>(16);
319+
final Writeable.Reader<AnsjResponse> reader = getResponseReader();
319320

320321
for (final DiscoveryNode node : nodes) {
321322

@@ -324,9 +325,7 @@ private AnsjResponse flushDicAll(AnsjRequest request) {
324325
transportService.sendRequest(node, AnsjAction.NAME, req, new TransportResponseHandler<AnsjResponse>() {
325326
@Override
326327
public AnsjResponse read(StreamInput in) throws IOException {
327-
AnsjResponse instance = newResponse();
328-
instance.readFrom(in);
329-
return instance;
328+
return reader.read(in);
330329
}
331330

332331
@Override
@@ -398,7 +397,7 @@ private AnsjResponse flushDic(AnsjRequest request) {
398397
CrfLibrary.reload(key);
399398
return null;
400399
});
401-
} else if (key.equals("ansj_config")) {
400+
} else if ("ansj_config".equals(key)) {
402401
this.cfg.reloadConfig();
403402
} else {
404403
return new AnsjResponse().put("status", "not find any by " + key);
@@ -414,8 +413,8 @@ private AnsjResponse flushDic(AnsjRequest request) {
414413
}
415414

416415
@Override
417-
protected AnsjResponse newResponse() {
418-
return new AnsjResponse();
416+
protected Writeable.Reader<AnsjResponse> getResponseReader() {
417+
return AnsjResponse::new;
419418
}
420419

421420
@Override

0 commit comments

Comments
 (0)