@Test public void testMonitorFactoryGroupCache() throws Exception { URL url1 = URL.valueOf("dubbo: URL url2 = URL.valueOf("dubbo: Monitor monitor1 = monitorFactory.getMonitor(url1); Monitor monitor2 = monitorFactory.getMonitor(url2); if (monitor1 == null || monitor2 == null) { Thread.sleep(2000); monitor1 = monitorFactory.getMonitor(url1); monitor2 = monitorFactory.getMonitor(url2); } Assert.assertNotSame(monitor1, monitor2); }
@Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl)); listenableFutureTask.addListener(new MonitorListener(key)); executor.execute(listenableFutureTask); FUTURES.put(key, listenableFutureTask); return null; } finally { LOCK.unlock(); } }
AbstractMonitorFactory implements MonitorFactory { @Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl)); listenableFutureTask.addListener(new MonitorListener(key)); executor.execute(listenableFutureTask); FUTURES.put(key, listenableFutureTask); return null; } finally { LOCK.unlock(); } } }
AbstractMonitorFactory implements MonitorFactory { @Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl)); listenableFutureTask.addListener(new MonitorListener(key)); executor.execute(listenableFutureTask); FUTURES.put(key, listenableFutureTask); return null; } finally { LOCK.unlock(); } }  }
AbstractMonitorFactory implements MonitorFactory { @Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl)); listenableFutureTask.addListener(new MonitorListener(key)); executor.execute(listenableFutureTask); FUTURES.put(key, listenableFutureTask); return null; } finally { LOCK.unlock(); } }  static Collection<Monitor> getMonitors(); @Override Monitor getMonitor(URL url); }
AbstractMonitorFactory implements MonitorFactory { @Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl)); listenableFutureTask.addListener(new MonitorListener(key)); executor.execute(listenableFutureTask); FUTURES.put(key, listenableFutureTask); return null; } finally { LOCK.unlock(); } }  static Collection<Monitor> getMonitors(); @Override Monitor getMonitor(URL url);  }