Java Code Examples for com.alibaba.dubbo.common.URL#getPort()
The following examples show how to use
com.alibaba.dubbo.common.URL#getPort() .
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: HessianProtocol.java From dubbox with Apache License 2.0 | 6 votes |
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 2
Source File: AbstractCodec.java From dubbox with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 3
Source File: RestfulProtocol.java From dubbo-plus with Apache License 2.0 | 6 votes |
@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 4
Source File: DeprecatedTelnetCodec.java From dubbox with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 5
Source File: WebServiceProtocol.java From dubbox with Apache License 2.0 | 6 votes |
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 6
Source File: HessianProtocol.java From dubbox with Apache License 2.0 | 6 votes |
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 7
Source File: RpcContext.java From dubbo3 with Apache License 2.0 | 6 votes |
/** * is provider side. * * @return provider side. */ public boolean isProviderSide() { URL url = getUrl(); if (url == null) { return false; } InetSocketAddress address = getRemoteAddress(); if (address == null) { return false; } String host; if (address.getAddress() == null) { host = address.getHostName(); } else { host = address.getAddress().getHostAddress(); } return url.getPort() != address.getPort() || !NetUtils.filterLocalHost(url.getIp()).equals(NetUtils.filterLocalHost(host)); }
Example 8
Source File: AvroProtocol.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException { logger.info("impl => " + impl.getClass()); logger.info("type => " + type.getName()); logger.info("url => " + url); final Server server = new NettyServer(new ReflectResponder(type, impl), new InetSocketAddress(url.getHost(), url.getPort())); server.start(); return new Runnable() { public void run() { try { logger.info("Close Avro Server"); server.close(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } }; }
Example 9
Source File: AbstractCodec.java From dubbo3 with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 10
Source File: RpcContext.java From dubbox with Apache License 2.0 | 6 votes |
/** * is consumer side. * * @return consumer side. */ public boolean isConsumerSide() { URL url = getUrl(); if (url == null) { return false; } InetSocketAddress address = getRemoteAddress(); if (address == null) { return false; } String host; if (address.getAddress() == null) { host = address.getHostName(); } else { host = address.getAddress().getHostAddress(); } return url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals(NetUtils.filterLocalHost(host)); }
Example 11
Source File: AbstractCodec.java From dubbox with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 12
Source File: SimpleRegistryService.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void subscribe(URL url, NotifyListener listener) { if (getUrl().getPort() == 0) { URL registryUrl = RpcContext.getContext().getUrl(); if (registryUrl != null && registryUrl.getPort() > 0 && RegistryService.class.getName().equals(registryUrl.getPath())) { super.setUrl(registryUrl); super.register(registryUrl); } } String client = RpcContext.getContext().getRemoteAddressString(); ConcurrentMap<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client); if (clientListeners == null) { remoteSubscribed.putIfAbsent(client, new ConcurrentHashMap<URL, Set<NotifyListener>>()); clientListeners = remoteSubscribed.get(client); } Set<NotifyListener> listeners = clientListeners.get(url); if (listeners == null) { clientListeners.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>()); listeners = clientListeners.get(url); } listeners.add(listener); super.subscribe(url, listener); subscribed(url, listener); }
Example 13
Source File: AbstractCodec.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 14
Source File: DeprecatedTelnetCodec.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 15
Source File: AbstractConfigurator.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } // If override url has port, means it is a provider address. We want to control a specific provider with this override url, it may take effect on the specific provider instance or on consumers holding this provider instance. // 如果覆盖url有端口,则意味着它是提供者地址。我们希望使用此覆盖url控制特定的提供者,它可能对特定的提供者实例或持有此提供者实例的使用者生效。 if (configuratorUrl.getPort() != 0) { if (url.getPort() == configuratorUrl.getPort()) { return configureIfMatch(url.getHost(), url); } } else {// override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0 // 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore; // 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider // 覆盖url没有端口,意味着ip覆盖url指定为消费者地址或0.0.0.0 // / / 1。如果它是一个消费者ip地址,意图是控制一个特定的消费者实例,它必须在消费者端生效,任何接收到这个覆盖url的提供商都应该忽略; /// / 2。如果ip是0.0.0.0,则此覆盖url可用于使用者,也可用于提供者 if (url.getParameter(Constants.SIDE_KEY, Constants.PROVIDER).equals(Constants.CONSUMER)) { return configureIfMatch(NetUtils.getLocalHost(), url);// NetUtils.getLocalHost is the ip address consumer registered to registry. } else if (url.getParameter(Constants.SIDE_KEY, Constants.CONSUMER).equals(Constants.PROVIDER)) { return configureIfMatch(Constants.ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch } } return url; }
Example 16
Source File: AbstractConfigurator.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || url.getHost().equals(configuratorUrl.getHost())) { String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername()); String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) { Set<String> condtionKeys = new HashSet<String>(); condtionKeys.add(Constants.CATEGORY_KEY); condtionKeys.add(Constants.CHECK_KEY); condtionKeys.add(Constants.DYNAMIC_KEY); condtionKeys.add(Constants.ENABLED_KEY); for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { condtionKeys.add(key); if (value != null && ! Constants.ANY_VALUE.equals(value) && ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } } } return doConfigure(url, configuratorUrl.removeParameters(condtionKeys)); } } } return url; }
Example 17
Source File: ServerPeer.java From dubbox with Apache License 2.0 | 5 votes |
@Override public Channel getChannel(InetSocketAddress remoteAddress) { String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName(); int port = remoteAddress.getPort(); Channel channel = super.getChannel(remoteAddress); if (channel == null) { for (Map.Entry<URL, Client> entry : clients.entrySet()) { URL url = entry.getKey(); if (url.getIp().equals(host) && url.getPort() == port) { return entry.getValue(); } } } return channel; }
Example 18
Source File: DubboProtocol.java From dubbox with Apache License 2.0 | 5 votes |
private boolean isClientSide(Channel channel) { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); return url.getPort() == address.getPort() && NetUtils.filterLocalHost(channel.getUrl().getIp()) .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress())); }
Example 19
Source File: HeaderExchangeHandler.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
private static boolean isClientSide(Channel channel) { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); return url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()) .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress())); }
Example 20
Source File: RestProtocol.java From dubbox with Apache License 2.0 | 4 votes |
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); } }; }