com.alibaba.dubbo.remoting.exchange.ExchangeServer Java Examples
The following examples show how to use
com.alibaba.dubbo.remoting.exchange.ExchangeServer.
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: ServersPageHandler.java From dubbox with Apache License 2.0 | 6 votes |
public Page handle(URL url) { List<List<String>> rows = new ArrayList<List<String>>(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); int clientCount = 0; if (servers != null && servers.size() > 0) { for (ExchangeServer s : servers) { List<String> row = new ArrayList<String>(); String address = s.getUrl().getAddress(); row.add(NetUtils.getHostName(address) + "/" + address); int clientSize = s.getExchangeChannels().size(); clientCount += clientSize; row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>"); rows.add(row); } } return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows); }
Example #2
Source File: ThriftProtocol.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { ExchangeServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close dubbo server: " + server.getLocalAddress()); } server.close(getServerShutdownTimeout()); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } // ~ end of if ( server != null ) } // ~ end of loop serverMap }
Example #3
Source File: ThriftProtocol.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #4
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #5
Source File: DubboServerStatusMetrics.java From watcher with Apache License 2.0 | 6 votes |
@Override public Object doMonitor(Map<String, Object> params) throws Throwable { List<Map<String, Object>> result = Lists.newArrayList(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); if (servers == null || servers.size() == 0) { throw WatcherException.throwIt("no server found"); } for (ExchangeServer server : servers) { Map<String, Object> serverResult = Maps.newHashMap(); boolean isBound = server.isBound(); serverResult.put("isBound", isBound); if (isBound) { serverResult.put("clients", server.getChannels().size()); } serverResult.put("port", server.getLocalAddress().getPort()); result.add(serverResult); } return result; }
Example #6
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #7
Source File: ServersPageHandler.java From dubbox with Apache License 2.0 | 6 votes |
public Page handle(URL url) { List<List<String>> rows = new ArrayList<List<String>>(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); int clientCount = 0; if (servers != null && servers.size() > 0) { for (ExchangeServer s : servers) { List<String> row = new ArrayList<String>(); String address = s.getUrl().getAddress(); row.add(NetUtils.getHostName(address) + "/" + address); int clientSize = s.getExchangeChannels().size(); clientCount += clientSize; row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>"); rows.add(row); } } return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows); }
Example #8
Source File: ServersPageHandler.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public Page handle(URL url) { List<List<String>> rows = new ArrayList<List<String>>(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); int clientCount = 0; if (servers != null && servers.size() > 0) { for (ExchangeServer s : servers) { List<String> row = new ArrayList<String>(); String address = s.getUrl().getAddress(); row.add(NetUtils.getHostName(address) + "/" + address); int clientSize = s.getExchangeChannels().size(); clientCount += clientSize; row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>"); rows.add(row); } } return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows); }
Example #9
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { ExchangeServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close dubbo server: " + server.getLocalAddress()); } server.close(getServerShutdownTimeout()); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } // ~ end of if ( server != null ) } // ~ end of loop serverMap }
Example #10
Source File: DubboProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
private void openServer(URL url) { // find server.查询服务地址 String key = url.getAddress(); //client can export a service which's only for server to invoke 客户端可以导出仅供服务器调用的服务 boolean isServer = url.getParameter(Constants.IS_SERVER_KEY, true); // 如果是服务端去本地缓存中查找exchangeServer,如果缓存中没有就创建server存储到本地缓存map中 if (isServer) { ExchangeServer server = serverMap.get(key); if (server == null) { // 创建server=》 serverMap.put(key, createServer(url)); } else { // server supports reset, use together with override 服务器支持重置,与覆盖一起使用 server.reset(url); } } }
Example #11
Source File: ServerStatusChecker.java From dubbo3 with Apache License 2.0 | 6 votes |
public Status check() { Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); if (servers == null || servers.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (ExchangeServer server : servers) { if (! server.isBound()) { level = Status.Level.ERROR; buf.setLength(0); buf.append(server.getLocalAddress()); break; } if (buf.length() > 0) { buf.append(","); } buf.append(server.getLocalAddress()); buf.append("(clients:"); buf.append(server.getChannels().size()); buf.append(")"); } return new Status(level, buf.toString()); }
Example #12
Source File: ServerStatusChecker.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public Status check() { Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); if (servers == null || servers.isEmpty()) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (ExchangeServer server : servers) { if (!server.isBound()) { level = Status.Level.ERROR; buf.setLength(0); buf.append(server.getLocalAddress()); break; } if (buf.length() > 0) { buf.append(","); } buf.append(server.getLocalAddress()); buf.append("(clients:"); buf.append(server.getChannels().size()); buf.append(")"); } return new Status(level, buf.toString()); }
Example #13
Source File: ThriftProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { // enable sending readonly event when server closes by default url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #14
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); ExchangeServer server; try { server = Exchangers.bind(url, handler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #15
Source File: ThriftProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { ExchangeServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close dubbo server: " + server.getLocalAddress()); } server.close(ConfigUtils.getServerShutdownTimeout()); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } // ~ end of if ( server != null ) } // ~ end of loop serverMap }
Example #16
Source File: ServerStatusChecker.java From dubbox with Apache License 2.0 | 6 votes |
public Status check() { Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); if (servers == null || servers.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (ExchangeServer server : servers) { if (! server.isBound()) { level = Status.Level.ERROR; buf.setLength(0); buf.append(server.getLocalAddress()); break; } if (buf.length() > 0) { buf.append(","); } buf.append(server.getLocalAddress()); buf.append("(clients:"); buf.append(server.getChannels().size()); buf.append(")"); } return new Status(level, buf.toString()); }
Example #17
Source File: ServerStatusChecker.java From dubbox with Apache License 2.0 | 6 votes |
public Status check() { Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); if (servers == null || servers.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (ExchangeServer server : servers) { if (! server.isBound()) { level = Status.Level.ERROR; buf.setLength(0); buf.append(server.getLocalAddress()); break; } if (buf.length() > 0) { buf.append(","); } buf.append(server.getLocalAddress()); buf.append("(clients:"); buf.append(server.getChannels().size()); buf.append(")"); } return new Status(level, buf.toString()); }
Example #18
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { ExchangeServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close dubbo server: " + server.getLocalAddress()); } server.close(getServerShutdownTimeout()); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } // ~ end of if ( server != null ) } // ~ end of loop serverMap }
Example #19
Source File: ServerStatusChecker.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public Status check() { Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); if (servers == null || servers.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (ExchangeServer server : servers) { if (! server.isBound()) { level = Status.Level.ERROR; buf.setLength(0); buf.append(server.getLocalAddress()); break; } if (buf.length() > 0) { buf.append(","); } buf.append(server.getLocalAddress()); buf.append("(clients:"); buf.append(server.getChannels().size()); buf.append(")"); } return new Status(level, buf.toString()); }
Example #20
Source File: DubboProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer createServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); //默认开启heartbeat url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT)); String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER); if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) throw new RpcException("Unsupported server type: " + str + ", url: " + url); url = url.addParameter(Constants.CODEC_KEY, Version.isCompatibleVersion() ? COMPATIBLE_CODEC_NAME : DubboCodec.NAME); ExchangeServer server; try { server = Exchangers.bind(url, requestHandler); } catch (RemotingException e) { throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e); } str = url.getParameter(Constants.CLIENT_KEY); if (str != null && str.length() > 0) { Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(); if (!supportedTypes.contains(str)) { throw new RpcException("Unsupported client type: " + str); } } return server; }
Example #21
Source File: ServersPageHandler.java From dubbox with Apache License 2.0 | 6 votes |
public Page handle(URL url) { List<List<String>> rows = new ArrayList<List<String>>(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); int clientCount = 0; if (servers != null && servers.size() > 0) { for (ExchangeServer s : servers) { List<String> row = new ArrayList<String>(); String address = s.getUrl().getAddress(); row.add(NetUtils.getHostName(address) + "/" + address); int clientSize = s.getExchangeChannels().size(); clientCount += clientSize; row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>"); rows.add(row); } } return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows); }
Example #22
Source File: ServersController.java From dubbox with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/clients", method = RequestMethod.GET) public String clients(@RequestParam int port, Model model) { Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); ExchangeServer server = null; String serverAddress = ""; if (servers != null && servers.size() > 0) { for (ExchangeServer s : servers) { int sp = s.getUrl().getPort(); if (port == 0 && server == null || port == sp) { server = s; serverAddress = NetUtils.getHostName(s.getUrl().getAddress()) + "/" + s.getUrl().getAddress(); } } } List<String> rows = new ArrayList<String>(); if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { String address = NetUtils.toAddressString(c.getRemoteAddress()); rows.add(NetUtils.getHostName(address) + "/" + address); } } model.addAttribute("port", port); model.addAttribute("server", serverAddress); model.addAttribute("rows", rows); return "server/clients"; }
Example #23
Source File: ProtocolUtils.java From dubbo3 with Apache License 2.0 | 5 votes |
public static void closeAll() { DubboProtocol.getDubboProtocol().destroy(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); for (ExchangeServer server : servers) { server.close(); } }
Example #24
Source File: ProtocolUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static void closeAll() { DubboProtocol.getDubboProtocol().destroy(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); for (ExchangeServer server : servers) { server.close(); } }
Example #25
Source File: AbstractExchangeGroup.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public ExchangePeer join(URL url, ExchangeHandler handler) throws RemotingException { ExchangeServer server = servers.get(url); if (server == null) { // TODO exist concurrent gap server = Exchangers.bind(url, handler); servers.put(url, server); dispatcher.addChannelHandler(handler); } return new ExchangeServerPeer(server, clients, this); }
Example #26
Source File: DubboProtocol.java From dubbox with Apache License 2.0 | 5 votes |
private void openServer(URL url) { // find server. String key = url.getAddress(); //client 也可以暴露一个只有server可以调用的服务。 boolean isServer = url.getParameter(Constants.IS_SERVER_KEY,true); if (isServer) { ExchangeServer server = serverMap.get(key); if (server == null) { serverMap.put(key, createServer(url)); } else { //server支持reset,配合override功能使用 server.reset(url); } } }
Example #27
Source File: ProtocolUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static void closeAll() { DubboProtocol.getDubboProtocol().destroy(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); for (ExchangeServer server : servers) { server.close(); } }
Example #28
Source File: DubboProtocol.java From dubbox with Apache License 2.0 | 5 votes |
private void openServer(URL url) { // find server. String key = url.getAddress(); //client 也可以暴露一个只有server可以调用的服务。 boolean isServer = url.getParameter(Constants.IS_SERVER_KEY,true); if (isServer) { ExchangeServer server = serverMap.get(key); if (server == null) { serverMap.put(key, createServer(url)); } else { //server支持reset,配合override功能使用 server.reset(url); } } }
Example #29
Source File: ProtocolUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static void closeAll() { DubboProtocol.getDubboProtocol().destroy(); Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers(); for (ExchangeServer server : servers) { server.close(); } }
Example #30
Source File: DubboProtocol.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
private void openServer(URL url) { // find server. String key = url.getAddress(); //client 也可以暴露一个只有server可以调用的服务。 boolean isServer = url.getParameter(Constants.IS_SERVER_KEY,true); if (isServer) { ExchangeServer server = serverMap.get(key); if (server == null) { serverMap.put(key, createServer(url)); } else { //server支持reset,配合override功能使用 server.reset(url); } } }