@Test public void testGetApp() throws InterruptedException, IllegalAccessException, NoSuchFieldException { RadarClientConfig config = new RadarClientConfig(rgUrl); config.setHost("1.1.1.1"); DiscoveryClient client = DiscoveryClient.getInstance(); client.setConfig(config); Field field = client.getClass().getDeclaredField("config"); field.setAccessible(true); field.set(client, config); Assert.assertEquals(0L, client.getApp("1111").getVersion()); Thread.sleep(3000); Assert.assertNotNull(client.getData().get("1111")); }
public RadarApp getApp(String appId) { if (appId == null || appId.length() == 0 || appId.trim().length() == 0) { return null; } if (!appCache.containsKey(appId)) { lock.lock(); try { if (!appCache.containsKey(appId)) { try { Map<String, RadarApp> appMap = queryApps(Arrays.asList(appId)); if (appMap != null && appMap.containsKey(appId)) { appCache.put(appId, appMap.get(appId)); appVersion.put(appId, appMap.get(appId).getVersion()); fireEvent(appMap); return appMap.get(appId); } } catch (Exception e) { } return null; } } finally { lock.unlock(); } } return appCache.get(appId); }
DiscoveryClient { public RadarApp getApp(String appId) { if (appId == null || appId.length() == 0 || appId.trim().length() == 0) { return null; } if (!appCache.containsKey(appId)) { lock.lock(); try { if (!appCache.containsKey(appId)) { try { Map<String, RadarApp> appMap = queryApps(Arrays.asList(appId)); if (appMap != null && appMap.containsKey(appId)) { appCache.put(appId, appMap.get(appId)); appVersion.put(appId, appMap.get(appId).getVersion()); fireEvent(appMap); return appMap.get(appId); } } catch (Exception e) { } return null; } } finally { lock.unlock(); } } return appCache.get(appId); } }
DiscoveryClient { public RadarApp getApp(String appId) { if (appId == null || appId.length() == 0 || appId.trim().length() == 0) { return null; } if (!appCache.containsKey(appId)) { lock.lock(); try { if (!appCache.containsKey(appId)) { try { Map<String, RadarApp> appMap = queryApps(Arrays.asList(appId)); if (appMap != null && appMap.containsKey(appId)) { appCache.put(appId, appMap.get(appId)); appVersion.put(appId, appMap.get(appId).getVersion()); fireEvent(appMap); return appMap.get(appId); } } catch (Exception e) { } return null; } } finally { lock.unlock(); } } return appCache.get(appId); } private  DiscoveryClient(); }
DiscoveryClient { public RadarApp getApp(String appId) { if (appId == null || appId.length() == 0 || appId.trim().length() == 0) { return null; } if (!appCache.containsKey(appId)) { lock.lock(); try { if (!appCache.containsKey(appId)) { try { Map<String, RadarApp> appMap = queryApps(Arrays.asList(appId)); if (appMap != null && appMap.containsKey(appId)) { appCache.put(appId, appMap.get(appId)); appVersion.put(appId, appMap.get(appId).getVersion()); fireEvent(appMap); return appMap.get(appId); } } catch (Exception e) { } return null; } } finally { lock.unlock(); } } return appCache.get(appId); } private  DiscoveryClient(); static DiscoveryClient getInstance(); RadarInstance getInstanceRadar(); RadarClientConfig getConfig(); void setConfig(RadarClientConfig config); boolean isConfiged(); boolean isRegistered(); Map<String, RadarApp> getData(); void register(RadarInstance instanceRadar); synchronized void addAppChangedListener(AppChangedListener changeListener); Map<String, RadarApp> getApps(List<String> appIds); Map<String, RadarApp> getApps(); RadarApp getApp(String appId); void deregister(); AdjustResponse adjust(Boolean isUp); }
DiscoveryClient { public RadarApp getApp(String appId) { if (appId == null || appId.length() == 0 || appId.trim().length() == 0) { return null; } if (!appCache.containsKey(appId)) { lock.lock(); try { if (!appCache.containsKey(appId)) { try { Map<String, RadarApp> appMap = queryApps(Arrays.asList(appId)); if (appMap != null && appMap.containsKey(appId)) { appCache.put(appId, appMap.get(appId)); appVersion.put(appId, appMap.get(appId).getVersion()); fireEvent(appMap); return appMap.get(appId); } } catch (Exception e) { } return null; } } finally { lock.unlock(); } } return appCache.get(appId); } private  DiscoveryClient(); static DiscoveryClient getInstance(); RadarInstance getInstanceRadar(); RadarClientConfig getConfig(); void setConfig(RadarClientConfig config); boolean isConfiged(); boolean isRegistered(); Map<String, RadarApp> getData(); void register(RadarInstance instanceRadar); synchronized void addAppChangedListener(AppChangedListener changeListener); Map<String, RadarApp> getApps(List<String> appIds); Map<String, RadarApp> getApps(); RadarApp getApp(String appId); void deregister(); AdjustResponse adjust(Boolean isUp);  }