com.alibaba.dubbo.common.store.DataStore Java Examples

The following examples show how to use com.alibaba.dubbo.common.store.DataStore. 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: AbstractServer.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public AbstractServer(URL url, ChannelHandler handler) throws RemotingException {
    super(url, handler);
    localAddress = getUrl().toInetSocketAddress();
    String host = url.getParameter(Constants.ANYHOST_KEY, false) 
                    || NetUtils.isInvalidLocalHost(getUrl().getHost()) 
                    ? NetUtils.ANYHOST : getUrl().getHost();
    bindAddress = new InetSocketAddress(host, getUrl().getPort());
    this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS);
    this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT);
    try {
        doOpen();
        if (logger.isInfoEnabled()) {
            logger.info("Start " + getClass().getSimpleName() + " bind " + getBindAddress() + ", export " + getLocalAddress());
        }
    } catch (Throwable t) {
        throw new RemotingException(url.toInetSocketAddress(), null, "Failed to bind " + getClass().getSimpleName() 
                                    + " on " + getLocalAddress() + ", cause: " + t.getMessage(), t);
    }

    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(DataStore.class)
            .getDefaultExtension().get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Integer.toString(url.getPort()));
}
 
Example #2
Source File: DubboThreadPoolStatusMetrics.java    From watcher with Apache License 2.0 6 votes vote down vote up
@Override
public Object doMonitor(Map<String, Object> params) throws Throwable {
	List<Map<String, Object>> result = Lists.newArrayList();
	DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
	Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);
	if (executors == null || executors.isEmpty()) {
		throw WatcherException.throwIt("no executors found");
	}
	for (Map.Entry<String, Object> entry : executors.entrySet()) {
		String port = entry.getKey();
		ExecutorService executor = (ExecutorService) entry.getValue();
		if (executor != null && executor instanceof ThreadPoolExecutor) {
			ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
			Map<String, Object> threadPoolResult = Maps.newHashMap();
			threadPoolResult.put("maximumPoolSize", tp.getMaximumPoolSize());
			threadPoolResult.put("corePoolSize", tp.getCorePoolSize());
			threadPoolResult.put("largestPoolSize", tp.getLargestPoolSize());
			threadPoolResult.put("activeCount", tp.getActiveCount());
			threadPoolResult.put("queuedTask", tp.getQueue().size());
			threadPoolResult.put("queueRemainingCapacity", tp.getQueue().remainingCapacity());
			threadPoolResult.put("port", port);
			result.add(threadPoolResult);
		}
	}
	return result;
}
 
Example #3
Source File: AbstractServer.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public AbstractServer(URL url, ChannelHandler handler) throws RemotingException {
    super(url, handler);
    localAddress = getUrl().toInetSocketAddress();
    String host = url.getParameter(Constants.ANYHOST_KEY, false) 
                    || NetUtils.isInvalidLocalHost(getUrl().getHost()) 
                    ? NetUtils.ANYHOST : getUrl().getHost();
    bindAddress = new InetSocketAddress(host, getUrl().getPort());
    this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS);
    this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT);
    try {
        doOpen();
        if (logger.isInfoEnabled()) {
            logger.info("Start " + getClass().getSimpleName() + " bind " + getBindAddress() + ", export " + getLocalAddress());
        }
    } catch (Throwable t) {
        throw new RemotingException(url.toInetSocketAddress(), null, "Failed to bind " + getClass().getSimpleName() 
                                    + " on " + getLocalAddress() + ", cause: " + t.getMessage(), t);
    }

    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(DataStore.class)
            .getDefaultExtension().get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Integer.toString(url.getPort()));
}
 
Example #4
Source File: AbstractServer.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public AbstractServer(URL url, ChannelHandler handler) throws RemotingException {
    super(url, handler);
    localAddress = getUrl().toInetSocketAddress();
    String host = url.getParameter(Constants.ANYHOST_KEY, false) 
                    || NetUtils.isInvalidLocalHost(getUrl().getHost()) 
                    ? NetUtils.ANYHOST : getUrl().getHost();
    bindAddress = new InetSocketAddress(host, getUrl().getPort());
    this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS);
    this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT);
    try {
        doOpen();
        if (logger.isInfoEnabled()) {
            logger.info("Start " + getClass().getSimpleName() + " bind " + getBindAddress() + ", export " + getLocalAddress());
        }
    } catch (Throwable t) {
        throw new RemotingException(url.toInetSocketAddress(), null, "Failed to bind " + getClass().getSimpleName() 
                                    + " on " + getLocalAddress() + ", cause: " + t.getMessage(), t);
    }

    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(DataStore.class)
            .getDefaultExtension().get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Integer.toString(url.getPort()));
}
 
Example #5
Source File: WrappedChannelHandler.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example #6
Source File: ThreadPoolStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example #7
Source File: WrappedChannelHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example #8
Source File: DubboThreadPoolStatusHealthCheck.java    From watcher with Apache License 2.0 5 votes vote down vote up
@Override
protected Result check() throws Exception {
	DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
	Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);
	for (Map.Entry<String, Object> entry : executors.entrySet()) {
		ExecutorService executor = (ExecutorService) entry.getValue();
		if (executor != null && executor instanceof ThreadPoolExecutor) {
			ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
			int activeCount = tp.getActiveCount();
			int maximumPoolSize = tp.getMaximumPoolSize();
			boolean ok = maximumPoolSize - activeCount > 1;
			if (ok) {
				return Result.healthy();
			} else {
				int remainingCapacity = tp.getQueue().remainingCapacity();
				ok = remainingCapacity > 1;
				if (ok) {
					return Result.healthy();
				} else {
					return Result.unhealthy("maximumPoolSize:%s,activeCount:%s,remainingCapacity:%s", maximumPoolSize, activeCount,
						remainingCapacity);
				}
			}
		}
	}
	return Result.healthy();
}
 
Example #9
Source File: ThreadPoolStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example #10
Source File: WrappedChannelHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example #11
Source File: ThreadPoolStatusChecker.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example #12
Source File: WrappedChannelHandler.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
        this.handler = handler;
        this.url = url;
//        线程池,协议和provider中如果有threadpool参数配置线程池的形式就用这个,没有配置就是用默认的fixed
        executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

        String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
        if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
            componentKey = Constants.CONSUMER_SIDE;
        }
        DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
        dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
    }
 
Example #13
Source File: ThreadPoolStatusChecker.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example #14
Source File: WrappedChannelHandler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example #15
Source File: ThreadPoolStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example #16
Source File: WrappedChannelHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example #17
Source File: ThreadPoolStatusChecker.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for (Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if (!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if (msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example #18
Source File: AbstractServer.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public AbstractServer(URL url, ChannelHandler handler) throws RemotingException {
        super(url, handler);
        localAddress = getUrl().toInetSocketAddress();

//        获取bind.ip参数值,默认从url中查询host属性
        String bindIp = getUrl().getParameter(Constants.BIND_IP_KEY, getUrl().getHost());
//        获取bind.port参数值,默认从url中查询port属性
        int bindPort = getUrl().getParameter(Constants.BIND_PORT_KEY, getUrl().getPort());
//        查询anyhost参数值,默认false
        if (url.getParameter(Constants.ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) {
            bindIp = NetUtils.ANYHOST;
        }
        bindAddress = new InetSocketAddress(bindIp, bindPort);
//        查询accepts参数,服务端可以接收处理的最大线程数,默认0不限制
        this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS);
//        idle.timeout 空闲超时时间,默认600s
        this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT);
        try {
//            创建server
            doOpen();
            if (logger.isInfoEnabled()) {
                logger.info("Start " + getClass().getSimpleName() + " bind " + getBindAddress() + ", export " + getLocalAddress());
            }
        } catch (Throwable t) {
            throw new RemotingException(url.toInetSocketAddress(), null, "Failed to bind " + getClass().getSimpleName()
                    + " on " + getLocalAddress() + ", cause: " + t.getMessage(), t);
        }
        //fixme replace this with better method
        DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
        executor = (ExecutorService) dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Integer.toString(url.getPort()));
    }