Search in sources :

Example 1 with ExchangeServer

use of org.apache.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class DubboProtocol method createServer.

private ProtocolServer createServer(URL url) {
    url = URLBuilder.from(url).addParameterIfAbsent(CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()).addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT)).addParameter(CODEC_KEY, DubboCodec.NAME).build();
    String str = url.getParameter(SERVER_KEY, 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, requestHandler);
    } catch (RemotingException e) {
        throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
    }
    str = url.getParameter(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 new DubboProtocolServer(server);
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException) RemotingException(org.apache.dubbo.remoting.RemotingException) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) Transporter(org.apache.dubbo.remoting.Transporter)

Example 2 with ExchangeServer

use of org.apache.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class ThriftProtocol method getServer.

private ProtocolServer getServer(URL url) {
    // enable sending readonly event when server closes by default
    url = url.addParameterIfAbsent(CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
    String str = url.getParameter(SERVER_KEY, org.apache.dubbo.rpc.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(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 new ThriftProtocolServer(server);
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException) RemotingException(org.apache.dubbo.remoting.RemotingException) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) Transporter(org.apache.dubbo.remoting.Transporter)

Example 3 with ExchangeServer

use of org.apache.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class PerformanceServerTest method statServer.

private static ExchangeServer statServer() throws Exception {
    final int port = PerformanceUtils.getIntProperty("port", 9911);
    final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
    final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
    final String threadpool = PerformanceUtils.getProperty(THREADPOOL_KEY, DEFAULT_THREADPOOL);
    final int threads = PerformanceUtils.getIntProperty(THREADS_KEY, DEFAULT_THREADS);
    final int iothreads = PerformanceUtils.getIntProperty(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS);
    final int buffer = PerformanceUtils.getIntProperty(BUFFER_KEY, DEFAULT_BUFFER_SIZE);
    final String channelHandler = PerformanceUtils.getProperty(Constants.DISPATCHER_KEY, ExecutionDispatcher.NAME);
    // Start server
    ExchangeServer server = Exchangers.bind("exchange://0.0.0.0:" + port + "?transporter=" + transporter + "&serialization=" + serialization + "&threadpool=" + threadpool + "&threads=" + threads + "&iothreads=" + iothreads + "&buffer=" + buffer + "&channel.handler=" + channelHandler, new ExchangeHandlerAdapter() {

        public String telnet(Channel channel, String message) throws RemotingException {
            return "echo: " + message + "\r\ntelnet> ";
        }

        public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
            if ("environment".equals(request)) {
                return CompletableFuture.completedFuture(PerformanceUtils.getEnvironment());
            }
            if ("scene".equals(request)) {
                List<String> scene = new ArrayList<String>();
                scene.add("Transporter: " + transporter);
                scene.add("Service Threads: " + threads);
                return CompletableFuture.completedFuture(scene);
            }
            return CompletableFuture.completedFuture(request);
        }
    });
    return server;
}
Also used : ExchangeHandlerAdapter(org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) CompletableFuture(java.util.concurrent.CompletableFuture) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ExchangeServer

use of org.apache.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class PortTelnetHandler method telnet.

@Override
public String telnet(Channel channel, String message) {
    StringBuilder buf = new StringBuilder();
    String port = null;
    boolean detail = false;
    if (message.length() > 0) {
        String[] parts = message.split("\\s+");
        for (String part : parts) {
            if ("-l".equals(part)) {
                detail = true;
            } else {
                if (!StringUtils.isInteger(part)) {
                    return "Illegal port " + part + ", must be integer.";
                }
                port = part;
            }
        }
    }
    if (port == null || port.length() == 0) {
        for (ProtocolServer server : DubboProtocol.getDubboProtocol().getServers()) {
            if (buf.length() > 0) {
                buf.append("\r\n");
            }
            if (detail) {
                buf.append(server.getUrl().getProtocol()).append("://").append(server.getUrl().getAddress());
            } else {
                buf.append(server.getUrl().getPort());
            }
        }
    } else {
        int p = Integer.parseInt(port);
        ProtocolServer protocolServer = null;
        for (ProtocolServer s : DubboProtocol.getDubboProtocol().getServers()) {
            if (p == s.getUrl().getPort()) {
                protocolServer = s;
                break;
            }
        }
        if (protocolServer != null) {
            ExchangeServer server = (ExchangeServer) protocolServer.getRemotingServer();
            Collection<ExchangeChannel> channels = server.getExchangeChannels();
            for (ExchangeChannel c : channels) {
                if (buf.length() > 0) {
                    buf.append("\r\n");
                }
                if (detail) {
                    buf.append(c.getRemoteAddress()).append(" -> ").append(c.getLocalAddress());
                } else {
                    buf.append(c.getRemoteAddress());
                }
            }
        } else {
            buf.append("No such port ").append(port);
        }
    }
    return buf.toString();
}
Also used : ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 5 with ExchangeServer

use of org.apache.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class AbstractExchangeGroup method join.

@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);
}
Also used : ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer)

Aggregations

ExchangeServer (org.apache.dubbo.remoting.exchange.ExchangeServer)6 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)3 RemotingException (org.apache.dubbo.remoting.RemotingException)2 Transporter (org.apache.dubbo.remoting.Transporter)2 ExchangeHandlerAdapter (org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)2 RpcException (org.apache.dubbo.rpc.RpcException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ProtocolServer (org.apache.dubbo.rpc.ProtocolServer)1