netty
netty介绍:
Netty是由JBOSS提供的一个java开源框架。Netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户端程序。
测试类
public abstract class ClientToServerTest extends TestCase {
protected static final String LOCALHOST = "127.0.0.1";
protected ExchangeServer server;
protected ExchangeChannel client;
protected WorldHandler handler = new WorldHandler();
protected abstract ExchangeServer newServer(int port, Replier<?> receiver) throws RemotingException;
protected abstract ExchangeChannel newClient(int port) throws RemotingException;
@Override
protected void setUp() throws Exception {
super.setUp();
int port = (int) (1000 * Math.random() + 10000);
server = newServer(port, handler);
client = newClient(port);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
try {
if (server != null)
server.close();
} finally {
if (client != null)
client.close();
}
}
@Test
public void testFuture() throws Exception {
ResponseFuture future = client.request(new World("world"));
Hello result = (Hello)future.get();
System.out.println(result.getName()+" hello world");
Assert.assertEquals("hello,world", result.getName());
}
}Handle处理类
写道
public class WorldHandler implements Replier<World> {
publicClass<World>interest(){
returnWorld.class;
}
publicObjectreply(ExchangeChannelchannel,Worldmsg)throwsRemotingException{
returnnewHello("hello,"+msg.getName());
}
}NettyClientToServerTest类
写道
public class NettyClientToServerTest extends ClientToServerTest {
protectedExchangeServernewServer(intport,Replier<?>receiver)throwsRemotingException{
returnExchangers.bind(URL.valueOf("exchange://localhost:"+port+"?server=netty"),receiver);
}
protectedExchangeChannelnewClient(intport)throwsRemotingException{
returnExchangers.connect(URL.valueOf("exchange://localhost:"+port+"?client=netty"));
}
}相关推荐
fengshantao 2020-10-29
arctan0 2020-10-14
爱传文档 2020-07-28
gzx0 2020-07-05
fengshantao 2020-07-04
fengshantao 2020-07-02
jannal 2020-06-21
arctan0 2020-06-19
arctan0 2020-06-16
gzx0 2020-06-14
fengshantao 2020-06-13
gzx0 2020-06-12
arctan0 2020-06-11
fengshantao 2020-06-11
mbcsdn 2020-05-19
arctan0 2020-05-16
爱传文档 2020-05-08
爱传文档 2020-05-04