RestHighLevelClientConInterceptor implements InstanceConstructorInterceptor { @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { RestClientBuilder restClientBuilder = (RestClientBuilder) allArguments[0]; RestClient restClient = restClientBuilder.build(); RestClientEnhanceInfo restClientEnhanceInfo = new RestClientEnhanceInfo(); List<Node> nodeList = restClient.getNodes(); for (Node node : nodeList) { restClientEnhanceInfo.addHttpHost(node.getHost()); } objInst.setSkyWalkingDynamicField(restClientEnhanceInfo); }  @Override void onConstruct(EnhancedInstance objInst, Object[] allArguments);  }
@Test public void testConstruct() throws Throwable { final EnhancedInstance objInst = new EnhancedInstance() { private Object object = null; @Override public Object getSkyWalkingDynamicField() { return object; } @Override public void setSkyWalkingDynamicField(Object value) { this.object = value; } }; restHighLevelClientConInterceptor = new RestHighLevelClientConInterceptor(); restHighLevelClientConInterceptor.onConstruct(objInst, allArguments); assertThat(objInst.getSkyWalkingDynamicField() instanceof RestClientEnhanceInfo, is(true)); assertThat(((RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField()).getPeers(), is("127.0.0.1:9200,127.0.0.1:9300")); }