Java源码示例:com.alibaba.dubbo.monitor.Monitor

示例1
protected Monitor createMonitor(final URL url) {
    return new Monitor() {

        public URL getUrl() {
            return url;
        }

        @Override
        public boolean isAvailable() {
            return true;
        }

        @Override
        public void destroy() {
        }

        public void collect(URL statistics) {
        }

        public List<URL> lookup(URL query) {
            return null;
        }

    };
}
 
示例2
@Override
public Monitor getMonitor(final URL url) {
    return new Monitor() {
        public URL getUrl() {
            return url;
        }

        @Override
        public boolean isAvailable() {
            return true;
        }

        @Override
        public void destroy() {
        }

        public void collect(URL statistics) {
            MonitorFilterTest.this.lastStatistics = statistics;
        }

        public List<URL> lookup(URL query) {
            return Arrays.asList(MonitorFilterTest.this.lastStatistics);
        }
    };
}
 
示例3
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false),
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
示例4
@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(Constants.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(Constants.REFERENCE_FILTER_KEY), containsString("testFilter"));
}
 
示例5
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
示例6
protected Monitor createMonitor(final URL url) {
        return new Monitor() {

public URL getUrl() {
	return url;
}

public boolean isAvailable() {
	return true;
}

            public void destroy() {
            }
            
public void collect(URL statistics) {
}

public List<URL> lookup(URL query) {
	return null;
}
            
        };
    }
 
示例7
public Monitor getMonitor(final URL url) {
        return new Monitor() {
            public URL getUrl() {
                return url;
            }
            public boolean isAvailable() {
                return true;
            }
            public void destroy() {
            }
            public void collect(URL statistics) {
                MonitorFilterTest.this.lastStatistics = statistics;
            }
public List<URL> lookup(URL query) {
	return Arrays.asList(MonitorFilterTest.this.lastStatistics);
}
        };
    }
 
示例8
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
示例9
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
示例10
protected Monitor createMonitor(final URL url) {
        return new Monitor() {

public URL getUrl() {
	return url;
}

public boolean isAvailable() {
	return true;
}

            public void destroy() {
            }
            
public void collect(URL statistics) {
}

public List<URL> lookup(URL query) {
	return null;
}
            
        };
    }
 
示例11
public Monitor getMonitor(final URL url) {
        return new Monitor() {
            public URL getUrl() {
                return url;
            }
            public boolean isAvailable() {
                return true;
            }
            public void destroy() {
            }
            public void collect(URL statistics) {
                MonitorFilterTest.this.lastStatistics = statistics;
            }
public List<URL> lookup(URL query) {
	return Arrays.asList(MonitorFilterTest.this.lastStatistics);
}
        };
    }
 
示例12
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
示例13
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
示例14
protected Monitor createMonitor(final URL url) {
        return new Monitor() {

public URL getUrl() {
	return url;
}

public boolean isAvailable() {
	return true;
}

            public void destroy() {
            }
            
public void collect(URL statistics) {
}

public List<URL> lookup(URL query) {
	return null;
}
            
        };
    }
 
示例15
public Monitor getMonitor(final URL url) {
        return new Monitor() {
            public URL getUrl() {
                return url;
            }
            public boolean isAvailable() {
                return true;
            }
            public void destroy() {
            }
            public void collect(URL statistics) {
                MonitorFilterTest.this.lastStatistics = statistics;
            }
public List<URL> lookup(URL query) {
	return Arrays.asList(MonitorFilterTest.this.lastStatistics);
}
        };
    }
 
示例16
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
示例17
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
示例18
protected Monitor createMonitor(final URL url) {
        return new Monitor() {

public URL getUrl() {
	return url;
}

public boolean isAvailable() {
	return true;
}

            public void destroy() {
            }
            
public void collect(URL statistics) {
}

public List<URL> lookup(URL query) {
	return null;
}
            
        };
    }
 
示例19
public Monitor getMonitor(final URL url) {
        return new Monitor() {
            public URL getUrl() {
                return url;
            }
            public boolean isAvailable() {
                return true;
            }
            public void destroy() {
            }
            public void collect(URL statistics) {
                MonitorFilterTest.this.lastStatistics = statistics;
            }
public List<URL> lookup(URL query) {
	return Arrays.asList(MonitorFilterTest.this.lastStatistics);
}
        };
    }
 
示例20
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
示例21
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
示例22
protected Monitor createMonitor(final URL url) {
        return new Monitor() {

public URL getUrl() {
	return url;
}

public boolean isAvailable() {
	return true;
}

            public void destroy() {
            }
            
public void collect(URL statistics) {
}

public List<URL> lookup(URL query) {
	return null;
}
            
        };
    }
 
示例23
public Monitor getMonitor(final URL url) {
        return new Monitor() {
            public URL getUrl() {
                return url;
            }
            public boolean isAvailable() {
                return true;
            }
            public void destroy() {
            }
            public void collect(URL statistics) {
                MonitorFilterTest.this.lastStatistics = statistics;
            }
public List<URL> lookup(URL query) {
	return Arrays.asList(MonitorFilterTest.this.lastStatistics);
}
        };
    }
 
示例24
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
示例25
@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 {
        // unlock
        LOCK.unlock();
    }
}
 
示例26
@Test
public void testMonitorFactoryCache() throws Exception {
    URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":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);
    }
    Assert.assertEquals(monitor1, monitor2);
}
 
示例27
@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);
    }
    Assert.assertEquals(monitor1, monitor2);
}
 
示例28
@Test
public void testMonitorFactoryGroupCache() throws Exception {
    URL url1 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=aaa");
    URL url2 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=bbb");
    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);
}
 
示例29
@Test
public void testSafeFailForMonitorCollectFail() {
    MonitorFilter monitorFilter = new MonitorFilter();
    MonitorFactory mockMonitorFactory = mock(MonitorFactory.class);
    Monitor mockMonitor = mock(Monitor.class);
    Mockito.doThrow(new RuntimeException()).when(mockMonitor).collect(any(URL.class));

    monitorFilter.setMonitorFactory(mockMonitorFactory);
    given(mockMonitorFactory.getMonitor(any(URL.class))).willReturn(mockMonitor);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);

    monitorFilter.invoke(serviceInvoker, invocation);
}
 
示例30
@Test
public void testMonitorFactoryCache() throws Exception {
    URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233");
    Monitor monitor1 = monitorFactory.getMonitor(url);
    Monitor monitor2 = monitorFactory.getMonitor(url);
    Assert.assertEquals(monitor1, monitor2);
}