Java Code Examples for com.alibaba.dubbo.common.URL#getIp()

The following examples show how to use com.alibaba.dubbo.common.URL#getIp() . 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: JsonRpcProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler(url.getParameter("cors", false)));
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    JsonRpcServer skeleton = new JsonRpcServer(impl, type);
    skeletonMap.put(path, skeleton);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 2
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 3
Source File: HessianProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new HessianHandler());
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    HessianSkeleton skeleton = new HessianSkeleton(impl, type);
    skeletonMap.put(path, skeleton);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 4
Source File: RestfulProtocol.java    From dubbo-plus with Apache License 2.0 6 votes vote down vote up
@Override
protected <T> Runnable doExport(T impl, Class<T> type, final URL url) throws RpcException {
    String contextPath = ConfigUtils.getProperty("dubbo.protocol.restful.contextpath","/");
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = SERVER_MAPPER.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new RestfulHandler(SERVICE_MAPPING_CONTAINER,contextPath));
        SERVER_MAPPER.put(addr, server);
    }
    SERVICE_MAPPING_CONTAINER.registerService(url,type,impl);
    return new Runnable() {
        @Override
        public void run() {
            SERVICE_MAPPING_CONTAINER.unregisterService(url);
        }
    };
}
 
Example 5
Source File: JsonRpcProtocol.java    From dubbo-rpc-jsonrpc with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler(url.getParameter("cors", false)));
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    JsonRpcServer skeleton = new JsonRpcServer(impl, type);
    skeletonMap.put(path, skeleton);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 6
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
            //serverFactoryBean.destroy(); //升级到cxf 3后编译失败,暂时注掉 - 杨俊明
            if (serverFactoryBean.getServer() != null) {
                serverFactoryBean.getServer().destroy();
            }
        }
    };
}
 
Example 7
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 8
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
        	serverFactoryBean.destroy();
        }
    };
}
 
Example 9
Source File: WebServiceProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
        	serverFactoryBean.destroy();
        }
    };
}
 
Example 10
Source File: HttpProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 11
Source File: HessianProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new HessianHandler());
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    HessianSkeleton skeleton = new HessianSkeleton(impl, type);
    skeletonMap.put(path, skeleton);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 12
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
        	serverFactoryBean.destroy();
        }
    };
}
 
Example 13
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example 14
Source File: ConsulRegistry.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public ConsulRegistry(URL url) {
	super(url);
	if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}
	String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
	if (!group.startsWith(Constants.PATH_SEPARATOR)) {
		group = Constants.PATH_SEPARATOR + group;
	}
	if (!group.endsWith(Constants.PATH_SEPARATOR)) {
		group = group + Constants.PATH_SEPARATOR;
	}
	this.root = group;
	String host = url.getIp();
	int port = url.getPort() != 0 ? url.getPort() : DEFAULT_CONSUL_PORT;
	this.consulClient = new ConsulClient(host, port);
	this.ttl = 16000L;
	keepAliveFuture = keepAliveExecutor.scheduleWithFixedDelay(new Runnable() {
		public void run() {
			try {
				keepAlive(); // 确保服务在consul的status为passing
			} catch (Throwable t) { // 防御性容错
				logger.error("Unexpected exception occur at defer consul keep alive time, cause: " + t.getMessage(),
						t);
			}
		}
	}, ttl / 2, ttl / 2, TimeUnit.MILLISECONDS);
}
 
Example 15
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
private RemoteCoordinator getParticipantByRemoteAddr(Invoker<?> invoker, InvocationDef invocationDef) {
	RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();

	URL targetUrl = invoker.getUrl();
	String targetAddr = targetUrl.getIp();
	int targetPort = targetUrl.getPort();

	RemoteAddr remoteAddr = new RemoteAddr();
	remoteAddr.setServerHost(targetAddr);
	remoteAddr.setServerPort(targetPort);

	if (participantRegistry.containsPhysicalInstance(remoteAddr) == false) {
		this.initializeRemoteParticipantIfNecessary(remoteAddr);
	}

	RemoteNode invocationContext = new RemoteNode();
	invocationContext.setServerHost(targetAddr);
	invocationContext.setServerPort(targetPort);

	RemoteCoordinator remoteCoordinator = participantRegistry.getPhysicalInstance(remoteAddr);

	DubboRemoteCoordinator dubboCoordinator = new DubboRemoteCoordinator();
	dubboCoordinator.setInvocationContext(invocationContext);
	dubboCoordinator.setRemoteCoordinator(remoteCoordinator);
	dubboCoordinator.setCoordinatorType(DubboRemoteCoordinator.KEY_PARTICIPANT_TYPE_EXACT);

	RemoteCoordinator participant = (RemoteCoordinator) Proxy.newProxyInstance(
			DubboRemoteCoordinator.class.getClassLoader(), new Class[] { RemoteCoordinator.class }, dubboCoordinator);
	dubboCoordinator.setProxyCoordinator(participant);

	return participant;
}
 
Example 16
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private RemoteCoordinator getParticipantByRemoteAddr(Invoker<?> invoker, InvocationDef invocationDef) {
	RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();

	URL targetUrl = invoker.getUrl();
	String targetAddr = targetUrl.getIp();
	int targetPort = targetUrl.getPort();

	RemoteAddr remoteAddr = new RemoteAddr();
	remoteAddr.setServerHost(targetAddr);
	remoteAddr.setServerPort(targetPort);

	if (participantRegistry.containsPhysicalInstance(remoteAddr) == false) {
		this.initializePhysicalInstanceIfNecessary(remoteAddr);
	} // end-if (participantRegistry.containsPhysicalInstance(remoteAddr) == false)

	RemoteNode invocationContext = new RemoteNode();
	invocationContext.setServerHost(targetAddr);
	invocationContext.setServerPort(targetPort);

	RemoteCoordinator remoteCoordinator = participantRegistry.getPhysicalInstance(remoteAddr);

	DubboRemoteCoordinator dubboCoordinator = new DubboRemoteCoordinator();
	dubboCoordinator.setInvocationContext(invocationContext);
	dubboCoordinator.setRemoteCoordinator(remoteCoordinator);
	dubboCoordinator.setCoordinatorType(DubboRemoteCoordinator.KEY_PARTICIPANT_TYPE_EXACT);

	RemoteCoordinator participant = (RemoteCoordinator) Proxy.newProxyInstance(
			DubboRemoteCoordinator.class.getClassLoader(), new Class[] { RemoteCoordinator.class }, dubboCoordinator);
	dubboCoordinator.setProxyCoordinator(participant);

	return participant;
}
 
Example 17
Source File: RestProtocol.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
Example 18
Source File: RestProtocol.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
Example 19
Source File: RestProtocol.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
Example 20
Source File: RestProtocol.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}