use of org.apache.dubbo.monitor.Monitor in project dubbo by alibaba.
the class AbstractMonitorFactory method getMonitor.
@Override
public Monitor getMonitor(URL url) {
url = url.setPath(MonitorService.class.getName()).addParameter(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;
future = EXECUTOR.submit(() -> {
try {
Monitor m = createMonitor(monitorUrl);
MONITORS.put(key, m);
FUTURES.remove(key);
return m;
} catch (Throwable e) {
logger.warn("Create monitor failed, monitor data will not be collected until you fix this problem. monitorUrl: " + monitorUrl, e);
return null;
}
});
FUTURES.put(key, future);
return null;
} finally {
// unlock
LOCK.unlock();
}
}
use of org.apache.dubbo.monitor.Monitor in project dubbo by alibaba.
the class AbstractMonitorFactoryTest method testMonitorFactoryIpCache.
@Test
public void testMonitorFactoryIpCache() throws Exception {
URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233");
Monitor monitor1 = monitorFactory.getMonitor(url);
Monitor monitor2 = monitorFactory.getMonitor(url);
if (monitor1 == null || monitor2 == null) {
Thread.sleep(2000);
monitor1 = monitorFactory.getMonitor(url);
monitor2 = monitorFactory.getMonitor(url);
}
Assertions.assertEquals(monitor1, monitor2);
}
use of org.apache.dubbo.monitor.Monitor in project dubbo by alibaba.
the class DubboMonitorFactoryTest method testCreateMonitor.
@Test
public void testCreateMonitor() {
URL urlWithoutPath = URL.valueOf("http://10.10.10.11");
Monitor monitor = dubboMonitorFactory.createMonitor(urlWithoutPath);
assertThat(monitor, not(nullValue()));
URL urlWithFilterKey = URL.valueOf("http://10.10.10.11/").addParameter(REFERENCE_FILTER_KEY, "testFilter");
monitor = dubboMonitorFactory.createMonitor(urlWithFilterKey);
assertThat(monitor, not(nullValue()));
ArgumentCaptor<Invoker> invokerArgumentCaptor = ArgumentCaptor.forClass(Invoker.class);
verify(proxyFactory, atLeastOnce()).getProxy(invokerArgumentCaptor.capture());
Invoker invoker = invokerArgumentCaptor.getValue();
assertThat(invoker.getUrl().getParameter(REFERENCE_FILTER_KEY), containsString("testFilter"));
}
Aggregations