本文整理汇总了Java中com.netflix.discovery.shared.Applications类的典型用法代码示例。如果您正苦于以下问题:Java Applications类的具体用法?Java Applications怎么用?Java Applications使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Applications类属于com.netflix.discovery.shared包,在下文中一共展示了Applications类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleDiscovery
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Test
public void testSimpleDiscovery(){
ArgumentCaptor<InstanceInfo> captor = ArgumentCaptor.forClass(InstanceInfo.class);
EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
when(requestHandler.getApplications()).thenReturn(response);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
verify(requestHandler, timeout(5000).times(2)).register(captor.capture());
response = generateMockResponse(captor.getAllValues());
when(requestHandler.getApplications()).thenReturn(response);
assertClusterSizeEventually(2, hz1);
assertClusterSizeEventually(2, hz2);
HazelcastInstance client = factory.newHazelcastClient();
reset(requestHandler);
when(requestHandler.getApplications()).thenReturn(response);
verify(requestHandler, timeout(1000).times(0)).register(Matchers.<InstanceInfo>any());
assertClusterSizeEventually(2, client);
}
示例2: testExternalRegistration
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Test
public void testExternalRegistration(){
EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
when(requestHandler.getApplications()).thenReturn(response);
Config config = new XmlConfigBuilder().build();
DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
DiscoveryStrategyConfig strategyConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
strategyConfig.addProperty("self-registration", "false");
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
assertClusterSizeEventually(2, hz1);
assertClusterSizeEventually(2, hz2);
verify(requestHandler, after(5000).never()).register(any(InstanceInfo.class));
}
示例3: testNamespaceRegistration
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Test
public void testNamespaceRegistration(){
final String appName = "other";
final String namespace = "hz";
configure(namespace, appName);
EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList(), appName);
when(requestHandler.getApplications()).thenReturn(response);
Config config = new XmlConfigBuilder().build();
DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
DiscoveryStrategyConfig strategyConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
strategyConfig.addProperty("namespace", namespace);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
assertClusterSizeEventually(1, hz1);
ArgumentCaptor<InstanceInfo> captor = ArgumentCaptor.forClass(InstanceInfo.class);
verify(requestHandler, timeout(5000).atLeastOnce()).register(captor.capture());
String actual = captor.getValue().getAppName().toLowerCase();
assertThat(actual, is(appName));
}
示例4: mappingJacksonHttpMessageConverter
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
/**
* Provides the serialization configurations required by the Eureka Server. JSON
* content exchanged with eureka requires a root node matching the entity being
* serialized or deserialized. Achived with
* {@link SerializationFeature.WRAP_ROOT_VALUE} and
* {@link DeserializationFeature.UNWRAP_ROOT_VALUE}.
* {@link PropertyNamingStrategy.SnakeCaseStrategy} is applied to the underlying
* {@link ObjectMapper}.
*
*
* @return
*/
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
SimpleModule jsonModule = new SimpleModule();
jsonModule.setSerializerModifier(createJsonSerializerModifier());//keyFormatter, compact));
converter.getObjectMapper().registerModule(jsonModule);
converter.getObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, true);
converter.getObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE,
true);
converter.getObjectMapper().addMixIn(Applications.class, ApplicationsJsonMixIn.class);
converter.getObjectMapper().addMixIn(InstanceInfo.class, InstanceInfoJsonMixIn.class);
// converter.getObjectMapper().addMixIn(DataCenterInfo.class, DataCenterInfoXmlMixIn.class);
// converter.getObjectMapper().addMixIn(InstanceInfo.PortWrapper.class, PortWrapperXmlMixIn.class);
// converter.getObjectMapper().addMixIn(Application.class, ApplicationXmlMixIn.class);
// converter.getObjectMapper().addMixIn(Applications.class, ApplicationsXmlMixIn.class);
return converter;
}
示例5: getApplicationsInternal
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath,
String[] regions) {
String url = serviceUrl + urlPath;
if (regions != null && regions.length > 0)
urlPath = (urlPath.contains("?") ? "&" : "?") + "regions="
+ StringUtil.join(regions);
ResponseEntity<EurekaApplications> response = restTemplate.exchange(url,
HttpMethod.GET, null, EurekaApplications.class);
return anEurekaHttpResponse(response.getStatusCodeValue(),
response.getStatusCode().value() == HttpStatus.OK.value()
&& response.hasBody() ? (Applications) response.getBody() : null)
.headers(headersOf(response)).build();
}
示例6: getServices
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Override
public List<String> getServices() {
Applications applications = this.eurekaClient.getApplications();
if (applications == null) {
return Collections.emptyList();
}
List<Application> registered = applications.getRegisteredApplications();
List<String> names = new ArrayList<>();
for (Application app : registered) {
if (app.getInstances().isEmpty()) {
continue;
}
names.add(app.getName().toLowerCase());
}
return names;
}
示例7: getEurekaDetails
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@GET
public Response getEurekaDetails() {
List<EurekaInstanceInfo> instanceInfoList = new ArrayList<EurekaInstanceInfo>();
DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient();
if (null != discoveryClient) {
Applications apps = discoveryClient.getApplications();
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo inst : app.getInstances()) {
instanceInfoList.add(new EurekaInstanceInfo(inst.getAppName(), inst.getId(), inst.getStatus().name(), inst.getIPAddr(), inst.getHostName()));
}
}
}
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
Gson gson = gsonBuilder.create();
String response = gson.toJson(new KaryonAdminResponse(instanceInfoList));
return Response.ok(response).build();
}
示例8: testInstanceDown
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Test
public void testInstanceDown(){
ArgumentCaptor<InstanceInfo> captor = ArgumentCaptor.forClass(InstanceInfo.class);
EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
when(requestHandler.getApplications()).thenReturn(response);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
verify(requestHandler, timeout(5000).times(2)).register(captor.capture());
response = generateMockResponse(captor.getAllValues());
when(requestHandler.getApplications()).thenReturn(response);
hz1.shutdown();
ArgumentCaptor<String> id = ArgumentCaptor.forClass(String.class);
verify(requestHandler, timeout(5000).times(1)).cancel(anyString(), id.capture());
reset(requestHandler);
for(InstanceInfo info : captor.getAllValues()){
if(info.getId().equals(id.getValue())){
captor.getAllValues().remove(info);
break;
}
}
response = generateMockResponse(captor.getAllValues());
when(requestHandler.getApplications()).thenReturn(response);
assertClusterSizeEventually(1, hz2);
}
示例9: generateMockResponse
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
private EurekaHttpResponse<Applications> generateMockResponse(List<InstanceInfo> infoList, String appName){
Application application = new Application();
application.setName(appName);
for(InstanceInfo info : infoList){
application.addInstance(info);
}
Applications applications = new Applications();
applications.addApplication(application);
return anEurekaHttpResponse(200, applications)
.type(MediaType.APPLICATION_JSON_TYPE)
.build();
}
示例10: getApplications
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
public Map<String, List<Registration>> getApplications() {
//TODO: support regions
EurekaHttpResponse<Applications> response = this.transport.getEurekaHttpClient().getApplications();
List<com.netflix.discovery.shared.Application> applications = response.getEntity().getRegisteredApplications();
LinkedHashMap<String, List<Registration>> map = new LinkedHashMap<>();
for (com.netflix.discovery.shared.Application application : applications) {
List<Registration> registrations = getRegistrations(application);
map.put(application.getName(), registrations);
}
return map;
}
示例11: getApplications
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
private Map<String, Object> getApplications() {
Applications applications = this.eurekaClient.getApplications();
if (applications == null) {
return Collections.emptyMap();
}
Map<String, Object> result = new HashMap<>();
for (Application application : applications.getRegisteredApplications()) {
result.put(application.getName(), application.getInstances().size());
}
return result;
}
示例12: getClusterNames
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Override
public List<String> getClusterNames() {
Applications applications = eurekaClient.getApplications();
List<Application> registeredApplications = applications.getRegisteredApplications();
List<String> appNames = new ArrayList<>(registeredApplications.size());
for (Application application : registeredApplications) {
appNames.add(application.getName());
}
log.trace("Using clusters names: " + appNames);
return appNames;
}
示例13: shouldProvideAllClustersNames
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Test
public void shouldProvideAllClustersNames() throws Exception {
Applications applications = registeredApplications(asList(application("service1"),
application("service2"), application("service3")));
when(eurekaClient.getApplications()).thenReturn(applications);
List<String> clusterNames = provider.getClusterNames();
assertThat(clusterNames).containsOnly("service1", "service2", "service3");
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:11,代码来源:EurekaBasedTurbineClustersProviderTest.java
示例14: CloudJacksonCodec
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public CloudJacksonCodec() {
super();
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
SimpleModule module = new SimpleModule("eureka1.x", VERSION);
module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer());
module.addSerializer(InstanceInfo.class, new CloudInstanceInfoSerializer());
module.addSerializer(Application.class, new ApplicationSerializer());
module.addSerializer(Applications.class, new ApplicationsSerializer(
this.getVersionDeltaKey(), this.getAppHashCodeKey()));
module.addDeserializer(DataCenterInfo.class,
new DataCenterInfoDeserializer());
module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer());
module.addDeserializer(InstanceInfo.class,
new CloudInstanceInfoDeserializer(mapper));
module.addDeserializer(Application.class,
new ApplicationDeserializer(mapper));
module.addDeserializer(Applications.class, new ApplicationsDeserializer(
mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey()));
mapper.registerModule(module);
HashMap<Class<?>, ObjectReader> readers = new HashMap<>();
readers.put(InstanceInfo.class, mapper.reader().withType(InstanceInfo.class)
.withRootName("instance"));
readers.put(Application.class, mapper.reader().withType(Application.class)
.withRootName("application"));
readers.put(Applications.class, mapper.reader().withType(Applications.class)
.withRootName("applications"));
setField("objectReaderByClass", readers);
HashMap<Class<?>, ObjectWriter> writers = new HashMap<>();
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class)
.withRootName("instance"));
writers.put(Application.class, mapper.writer().withType(Application.class)
.withRootName("application"));
writers.put(Applications.class, mapper.writer().withType(Applications.class)
.withRootName("applications"));
setField("objectWriterByClass", writers);
setField("mapper", mapper);
}
示例15: testInstanceRegistration
import com.netflix.discovery.shared.Applications; //导入依赖的package包/类
@Test
public void testInstanceRegistration(){
EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
when(requestHandler.getApplications()).thenReturn(response);
factory.newHazelcastInstance();
ArgumentCaptor<InstanceInfo> captor = ArgumentCaptor.forClass(InstanceInfo.class);
verify(requestHandler, timeout(5000).times(1)).register(captor.capture());
assertNotNull(captor.getAllValues());
assertEquals(captor.getAllValues().size(), 1);
InstanceInfo actual = captor.getValue();
assertEquals(actual.getAppName().toLowerCase(), APP_NAME);
}