3333import org .elasticsearch .cluster .service .ClusterService ;
3434import org .elasticsearch .common .inject .Inject ;
3535import org .elasticsearch .common .io .stream .StreamInput ;
36+ import org .elasticsearch .common .io .stream .Writeable ;
3637import org .elasticsearch .index .shard .ShardId ;
3738import org .elasticsearch .threadpool .ThreadPool ;
3839import 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