当前位置: 首页>>代码示例>>Java>>正文


Java EurekaHttpResponse类代码示例

本文整理汇总了Java中com.netflix.discovery.shared.transport.EurekaHttpResponse的典型用法代码示例。如果您正苦于以下问题:Java EurekaHttpResponse类的具体用法?Java EurekaHttpResponse怎么用?Java EurekaHttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EurekaHttpResponse类属于com.netflix.discovery.shared.transport包,在下文中一共展示了EurekaHttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSimpleDiscovery

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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);
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:24,代码来源:HazelcastClientTestCase.java

示例2: testExternalRegistration

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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));

}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:20,代码来源:HazelcastClientTestCase.java

示例3: testNamespaceRegistration

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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));

}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:26,代码来源:HazelcastClientTestCase.java

示例4: renew

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
/**
 * Renew with the eureka service by making the appropriate REST call
 */
public boolean renew(InstanceInfo instanceInfo) {
	EurekaHttpResponse<InstanceInfo> httpResponse;
	try {
		httpResponse = this.transport.getEurekaHttpClient().sendHeartBeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, null);
		log.debug("EurekaLite_{}/{} - Heartbeat status: {}", instanceInfo.getAppName(), instanceInfo.getId(), httpResponse.getStatusCode());
		if (httpResponse.getStatusCode() == HttpStatus.NOT_FOUND.value()) {
			log.info("EurekaLite_{}/{} - Re-registering apps/{}", instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo.getAppName());
			return register(instanceInfo);
		}
		return httpResponse.getStatusCode() == HttpStatus.OK.value();
	} catch (Exception e) {
		log.error("EurekaLite_"+instanceInfo.getAppName()+"/"+ instanceInfo.getId() + " - was unable to send heartbeat!", e);
		return false;
	}
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:19,代码来源:Eureka.java

示例5: sendHeartBeat

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id,
		InstanceInfo info, InstanceStatus overriddenStatus) {
	String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status="
			+ info.getStatus().toString() + "&lastDirtyTimestamp="
			+ info.getLastDirtyTimestamp().toString() + (overriddenStatus != null
					? "&overriddenstatus=" + overriddenStatus.name() : "");

	ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath,
			HttpMethod.PUT, null, InstanceInfo.class);

	EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
			response.getStatusCodeValue(), InstanceInfo.class)
					.headers(headersOf(response));

	if (response.hasBody())
		eurekaResponseBuilder.entity(response.getBody());

	return eurekaResponseBuilder.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:21,代码来源:RestTemplateEurekaHttpClient.java

示例6: getApplicationsInternal

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:17,代码来源:RestTemplateEurekaHttpClient.java

示例7: testInstanceDown

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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);
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:33,代码来源:HazelcastClientTestCase.java

示例8: generateMockResponse

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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();
    }
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:16,代码来源:HazelcastClientTestCase.java

示例9: register

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
/**
 * Register with the eureka service by making the appropriate REST call.
 */
protected boolean register(InstanceInfo instanceInfo) {
	log.info("EurekaLite_{}/{}: registering service...", instanceInfo.getAppName(), instanceInfo.getId());
	EurekaHttpResponse<Void> httpResponse;
	try {
		httpResponse = this.transport.getEurekaHttpClient().register(instanceInfo);
	} catch (Exception e) {
		log.warn("EurekaLite_"+instanceInfo.getAppName()+"/"+ instanceInfo.getId() + " - registration failed " + e.getMessage(), e);
		throw e;
	}
	if (log.isInfoEnabled()) {
		log.info("EurekaLite_{}/{} - registration status: {}", instanceInfo.getAppName(), instanceInfo.getId(), httpResponse.getStatusCode());
	}
	return httpResponse.getStatusCode() == HttpStatus.NO_CONTENT.value();
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:18,代码来源:Eureka.java

示例10: cancel

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
public void cancel(String appName, String instanceId) {
	try {
		EurekaHttpResponse<Void> httpResponse = this.transport.getEurekaHttpClient().cancel(appName, instanceId);
		log.info("EurekaLite_{}/{} - deregister  status: {}", appName, instanceId, httpResponse.getStatusCode());
	} catch (Exception e) {
		log.error("EurekaLite_"+appName+"/"+ instanceId + " - de-registration failed " + e.getMessage(), e);
	}
	this.transport.shutdown();
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:10,代码来源:Eureka.java

示例11: getRegistration

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
public Registration getRegistration(String appName, String instanceId) {
	EurekaHttpResponse<InstanceInfo> response = this.transport.getEurekaHttpClient().getInstance(appName, instanceId);
	//TODO: error handling and logging
	InstanceInfo instanceInfo = response.getEntity();

	Registration registration = getRegistration(instanceInfo);
	return registration;
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:9,代码来源:Eureka.java

示例12: getRegistrations

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
public List<Registration> getRegistrations(String appName) {
	EurekaHttpResponse<com.netflix.discovery.shared.Application> response = this.transport.getEurekaHttpClient().getApplication(appName);
	//TODO: error handling and logging
	com.netflix.discovery.shared.Application application = response.getEntity();

	return getRegistrations(application);
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:8,代码来源:Eureka.java

示例13: getApplications

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的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;
}
 
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:14,代码来源:Eureka.java

示例14: getInstanceInfo

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
public InstanceInfo getInstanceInfo(String appname, String instanceId) {
	EurekaHttpResponse<InstanceInfo> response = getEurekaHttpClient().getInstance(appname, instanceId);
	HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusCode());
	if (httpStatus.is2xxSuccessful() && response.getEntity() != null) {
		return response.getEntity();
	}
	return null;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:9,代码来源:CloudEurekaClient.java

示例15: register

import com.netflix.discovery.shared.transport.EurekaHttpResponse; //导入依赖的package包/类
@Override
public EurekaHttpResponse<Void> register(InstanceInfo info) {
	String urlPath = serviceUrl + "apps/" + info.getAppName();

	HttpHeaders headers = new HttpHeaders();
	headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip");
	headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

	ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.POST,
			new HttpEntity<InstanceInfo>(info, headers), Void.class);

	return anEurekaHttpResponse(response.getStatusCodeValue())
			.headers(headersOf(response)).build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:15,代码来源:RestTemplateEurekaHttpClient.java


注:本文中的com.netflix.discovery.shared.transport.EurekaHttpResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。