use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class Main method dataPackageTest.
static void dataPackageTest(int port) throws Exception {
ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
Random random = new Random();
for (int i = 5; i < 100; i++) {
StringBuilder sb = new StringBuilder();
for (int j = 0; j < i * 100; j++) sb.append("(" + random.nextLong() + ")");
Main.Data d = new Main.Data();
d.setData(sb.toString());
client.request(d).get();
}
System.out.println("send finished.");
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_twoway_error_reply.
@Test
public void test_received_request_twoway_error_reply() throws RemotingException {
final Person requestdata = new Person("charles");
final Request request = new Request();
request.setTwoWay(true);
request.setData(requestdata);
final AtomicInteger count = new AtomicInteger(0);
final Channel mchannel = new MockedChannel() {
@Override
public void send(Object message) throws RemotingException {
Response res = (Response) message;
Assert.assertEquals(request.getId(), res.getId());
Assert.assertEquals(request.getVersion(), res.getVersion());
Assert.assertEquals(Response.SERVICE_ERROR, res.getStatus());
Assert.assertNull(res.getResult());
Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
count.incrementAndGet();
}
};
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
throw new BizException();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
Assert.assertEquals(1, count.get());
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class AbstractBenchmarkServer method run.
public void run(String[] args) throws Exception {
if (args == null || args.length != 5) {
throw new IllegalArgumentException("must give three args: listenPort | maxThreads | responseSize | transporter | serialization");
}
int listenPort = Integer.parseInt(args[0]);
int maxThreads = Integer.parseInt(args[1]);
final int responseSize = Integer.parseInt(args[2]);
String transporter = args[3];
String serialization = args[4];
System.out.println(dateFormat.format(new Date()) + " ready to start server,listenPort is: " + listenPort + ",maxThreads is:" + maxThreads + ",responseSize is:" + responseSize + " bytes,transporter is:" + transporter + ",serialization is:" + serialization);
StringBuilder url = new StringBuilder();
url.append("exchange://0.0.0.0:");
url.append(listenPort);
url.append("?transporter=");
url.append(transporter);
url.append("&serialization=");
url.append(serialization);
url.append("&threads=");
url.append(maxThreads);
Exchangers.bind(url.toString(), new ExchangeHandlerAdapter() {
public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
// send response
return new ResponseObject(responseSize);
}
});
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class ClientsPageHandler method handle.
public Page handle(URL url) {
String port = url.getParameter("port");
int p = port == null || port.length() == 0 ? 0 : Integer.parseInt(port);
Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
ExchangeServer server = null;
StringBuilder select = new StringBuilder();
if (servers != null && servers.size() > 0) {
if (servers.size() == 1) {
server = servers.iterator().next();
String address = server.getUrl().getAddress();
select.append(" > " + NetUtils.getHostName(address) + "/" + address);
} else {
select.append(" > <select onchange=\"window.location.href='clients.html?port=' + this.value;\">");
for (ExchangeServer s : servers) {
int sp = s.getUrl().getPort();
select.append("<option value=\">");
select.append(sp);
if (p == 0 && server == null || p == sp) {
server = s;
select.append("\" selected=\"selected");
}
select.append("\">");
select.append(s.getUrl().getAddress());
select.append("</option>");
}
select.append("</select>");
}
}
List<List<String>> rows = new ArrayList<List<String>>();
if (server != null) {
Collection<ExchangeChannel> channels = server.getExchangeChannels();
for (ExchangeChannel c : channels) {
List<String> row = new ArrayList<String>();
String address = NetUtils.toAddressString(c.getRemoteAddress());
row.add(NetUtils.getHostName(address) + "/" + address);
rows.add(row);
}
}
return new Page("<a href=\"servers.html\">Servers</a>" + select.toString() + " > Clients", "Clients (" + rows.size() + ")", new String[] { "Client Address:" }, rows);
}
Aggregations