com.netflix.eureka.EurekaServerContextHolder Java Examples
The following examples show how to use
com.netflix.eureka.EurekaServerContextHolder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EurekaServerBootstrap.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
protected void initEurekaServerContext() throws Exception { // For backward compatibility JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH); XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH); if (isAws(this.applicationInfoManager.getInfo())) { this.awsBinder = new AwsBinderDelegate(this.eurekaServerConfig, this.eurekaClientConfig, this.registry, this.applicationInfoManager); this.awsBinder.start(); } EurekaServerContextHolder.initialize(this.serverContext); log.info("Initialized server context"); // Copy registry from neighboring eureka node int registryCount = this.registry.syncUp(); this.registry.openForTraffic(this.applicationInfoManager, registryCount); // Register all monitoring statistics. EurekaMonitors.registerAllStats(); }
Example #2
Source File: EurekaServerBootstrap.java From didi-eureka-server with MIT License | 6 votes |
protected void initEurekaServerContext() throws Exception { // For backward compatibility JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH); XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH); if (isAws(this.applicationInfoManager.getInfo())) { this.awsBinder = new AwsBinderDelegate(this.eurekaServerConfig, this.eurekaClientConfig, this.registry, this.applicationInfoManager); this.awsBinder.start(); } EurekaServerContextHolder.initialize(this.serverContext); log.info("Initialized server context"); // Copy registry from neighboring eureka node int registryCount = this.registry.syncUp(); this.registry.openForTraffic(this.applicationInfoManager, registryCount); // Register all monitoring statistics. EurekaMonitors.registerAllStats(); }
Example #3
Source File: TxServiceImpl.java From tx-lcn with Apache License 2.0 | 6 votes |
@Override public TxState getState() { TxState state = new TxState(); String ipAddress = EurekaServerContextHolder.getInstance().getServerContext().getApplicationInfoManager().getEurekaInstanceConfig().getIpAddress(); if(!isIp(ipAddress)){ ipAddress = "127.0.0.1"; } state.setIp(ipAddress); state.setPort(Constants.socketPort); state.setMaxConnection(SocketManager.getInstance().getMaxConnection()); state.setNowConnection(SocketManager.getInstance().getNowConnection()); state.setRedisSaveMaxTime(redis_save_max_time); state.setTransactionNettyDelayTime(transaction_netty_delay_time); state.setTransactionNettyHeartTime(transaction_netty_heart_time); state.setSlbList(getServices()); return state; }
Example #4
Source File: TxManagerInfoServiceImpl.java From Raincat with GNU Lesser General Public License v3.0 | 6 votes |
@Override public TxManagerInfo findTxManagerInfo() { TxManagerInfo txManagerInfo = new TxManagerInfo(); //设置ip为eureka 上注册的TxManager ip String ip = EurekaServerContextHolder.getInstance() .getServerContext().getApplicationInfoManager() .getEurekaInstanceConfig().getIpAddress(); txManagerInfo.setIp(ip); txManagerInfo.setPort(nettyConfig.getPort()); txManagerInfo.setMaxConnection(SocketManager.getInstance().getMaxConnection()); txManagerInfo.setNowConnection(SocketManager.getInstance().getNowConnection()); txManagerInfo.setTransactionWaitMaxTime(transactionWaitMaxTime); txManagerInfo.setRedisSaveMaxTime(redisSaveMaxTime); txManagerInfo.setClusterInfoList(findEurekaService()); return txManagerInfo; }
Example #5
Source File: EurekaStateChangeListener.java From mPaaS with Apache License 2.0 | 5 votes |
/** * 服务实例注册事件 * @param event */ @EventListener public void listen(EurekaInstanceRegisteredEvent event) { /** * 获取当前已注册的所有服务器实例 */ int total = EurekaServerContextHolder.getInstance().getServerContext().getRegistry().getSortedApplications().size(); // event.getInstanceInfo().getActionType() log.info("服务实例[{}]注册成功,当前服务器已注册服务实例数量[{}]", event.getInstanceInfo().getAppName(), total); }
Example #6
Source File: EurekaControllerTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class); when(peerEurekaNodes.getPeerNodesView()) .thenReturn(Collections.<PeerEurekaNode>emptyList()); InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test") .setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)) .build(); this.infoManager = mock(ApplicationInfoManager.class); this.original = ApplicationInfoManager.getInstance(); setInstance(this.infoManager); when(this.infoManager.getInfo()).thenReturn(instanceInfo); Application myapp = new Application("myapp"); myapp.addInstance(InstanceInfo.Builder.newBuilder().setAppName("myapp") .setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)) .setInstanceId("myapp:1").build()); ArrayList<Application> applications = new ArrayList<>(); applications.add(myapp); PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class); when(registry.getSortedApplications()).thenReturn(applications); EurekaServerContext serverContext = mock(EurekaServerContext.class); EurekaServerContextHolder.initialize(serverContext); when(serverContext.getRegistry()).thenReturn(registry); when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes); when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager); }
Example #7
Source File: EurekaControllerTest.java From didi-eureka-server with MIT License | 5 votes |
@Before public void setup() throws Exception { PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class); when(peerEurekaNodes.getPeerNodesView()).thenReturn(Collections.<PeerEurekaNode>emptyList()); InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder() .setAppName("test") .setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)) .build(); this.infoManager = mock(ApplicationInfoManager.class); this.original = ApplicationInfoManager.getInstance(); setInstance(this.infoManager); when(this.infoManager.getInfo()).thenReturn(instanceInfo); Application myapp = new Application("myapp"); myapp.addInstance(InstanceInfo.Builder.newBuilder() .setAppName("myapp") .setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)) .setInstanceId("myapp:1") .build()); ArrayList<Application> applications = new ArrayList<>(); applications.add(myapp); PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class); when(registry.getSortedApplications()).thenReturn(applications); EurekaServerContext serverContext = mock(EurekaServerContext.class); EurekaServerContextHolder.initialize(serverContext); when(serverContext.getRegistry()).thenReturn(registry); when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes); when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager); }
Example #8
Source File: EurekaUtil.java From redis-manager with Apache License 2.0 | 5 votes |
/** * 获取eureka注册节点 * * @return List<AnalyzeInstance> */ public static List<AnalyzeInstance> getRegisterNodes() { PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry(); Applications applications = registry.getApplications(); List<AnalyzeInstance> analyzes = new ArrayList<>(); applications.getRegisteredApplications().forEach((registeredApplication) -> { registeredApplication.getInstances().forEach((instance) -> { AnalyzeInstance analyzeInstance = new AnalyzeInstance(instance.getIPAddr(), instance.getPort()); analyzes.add(analyzeInstance); }); }); return analyzes; }
Example #9
Source File: GatewayNotifierTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() { EurekaServerContext context = mock(EurekaServerContext.class); registry = mock(AwsInstanceRegistry.class); when(context.getRegistry()).thenReturn(registry); EurekaServerContextHolder.initialize(context); restTemplate = mock(RestTemplate.class); messageService = mock(MessageService.class); gatewayNotifierSync = new GatewayNotifierSync(restTemplate, messageService); }
Example #10
Source File: MetadataDefaultsServiceTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() { mockRegistry = mock(PeerAwareInstanceRegistry.class); doAnswer(x -> { EurekaInstanceRegisteredEvent event = mock(EurekaInstanceRegisteredEvent.class); when(event.getInstanceInfo()).thenReturn(x.getArgument(0)); eurekaInstanceRegisteredListener.listen(event); return mockRegistry; }).when(mockRegistry).register(any(), anyBoolean()); EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class); when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry); EurekaServerContextHolder.initialize(mockEurekaServerContext); }
Example #11
Source File: StaticServicesRegistrationServiceTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Test public void testFindServicesInDirectoryNoFiles() { EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class); EurekaServerContextHolder.initialize(mockEurekaServerContext); ServiceDefinitionProcessor serviceDefinitionProcessor = new ServiceDefinitionProcessor(); StaticServicesRegistrationService registrationService = new StaticServicesRegistrationService(serviceDefinitionProcessor, new MetadataDefaultsService()); StaticRegistrationResult result = registrationService.registerServices(folder.getRoot().getAbsolutePath()); assertEquals(0, result.getInstances().size()); }
Example #12
Source File: StaticServicesRegistrationServiceTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() { mockRegistry = mock(PeerAwareInstanceRegistry.class); EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class); when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry); EurekaServerContextHolder.initialize(mockEurekaServerContext); }
Example #13
Source File: EurekaUtil.java From RCT with Apache License 2.0 | 5 votes |
/** * 获取eureka注册节点 * * @return List<AnalyzeInstance> */ public static List<AnalyzeInstance> getRegisterNodes() { PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry(); Applications applications = registry.getApplications(); List<AnalyzeInstance> analyzes = new ArrayList<>(); applications.getRegisteredApplications().forEach((registeredApplication) -> { registeredApplication.getInstances().forEach((instance) -> { AnalyzeInstance analyzeInstance = new AnalyzeInstance(instance.getIPAddr(), instance.getPort()); analyzes.add(analyzeInstance); }); }); return analyzes; }
Example #14
Source File: EurekaResource.java From jhipster-microservices-example with Apache License 2.0 | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #15
Source File: EurekaController.java From didi-eureka-server with MIT License | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #16
Source File: GatewayNotifier.java From api-layer with Eclipse Public License 2.0 | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #17
Source File: StaticServicesRegistrationService.java From api-layer with Eclipse Public License 2.0 | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #18
Source File: EurekaResource.java From jhipster-registry with Apache License 2.0 | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #19
Source File: InstanceInfoMeta.java From onetwo with Apache License 2.0 | 4 votes |
static public EurekaServerContext getEurekaServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #20
Source File: EurekaController.java From spring-cloud-netflix with Apache License 2.0 | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }
Example #21
Source File: EurekaResource.java From flair-registry with Apache License 2.0 | 4 votes |
private EurekaServerContext getServerContext() { return EurekaServerContextHolder.getInstance().getServerContext(); }