use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel 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(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL);
final int threads = PerformanceUtils.getIntProperty(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
final int iothreads = PerformanceUtils.getIntProperty(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS);
final int buffer = PerformanceUtils.getIntProperty(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
final String channelHandler = PerformanceUtils.getProperty(Constants.DISPATCHER_KEY, ExecutionDispatcher.NAME);
// 启动服务器
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 Object reply(ExchangeChannel channel, Object request) throws RemotingException {
if ("environment".equals(request)) {
return PerformanceUtils.getEnvironment();
}
if ("scene".equals(request)) {
List<String> scene = new ArrayList<String>();
scene.add("Transporter: " + transporter);
scene.add("Service Threads: " + threads);
return scene;
}
return request;
}
});
return server;
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class Main method startServer.
private static void startServer(int port) throws Exception {
ReplierDispatcher dispatcher = new ReplierDispatcher();
dispatcher.addReplier(RpcMessage.class, new RpcMessageHandler());
dispatcher.addReplier(Object.class, new Replier<Object>() {
public Object reply(ExchangeChannel channel, Object msg) {
for (int i = 0; i < 10000; i++) System.currentTimeMillis();
System.out.println("handle:" + msg + ";thread:" + Thread.currentThread().getName());
return new StringMessage("hello world");
}
});
Exchangers.bind(URL.valueOf("dubbo://localhost:" + port), dispatcher);
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class NettyClientTest method main.
public static void main(String[] args) throws RemotingException, InterruptedException {
ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty&heartbeat=1000"));
Thread.sleep(60 * 1000 * 50);
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class HeaderExchangeHandler method connected.
public void connected(Channel channel) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.connected(exchangeChannel);
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class HeaderExchangeHandler method disconnected.
public void disconnected(Channel channel) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.disconnected(exchangeChannel);
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
Aggregations