Search in sources :

Example 16 with ExchangeChannel

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.");
}
Also used : Random(java.util.Random) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Example 17 with ExchangeChannel

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());
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Channel(com.alibaba.dubbo.remoting.Channel) HeaderExchangeHandler(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) Request(com.alibaba.dubbo.remoting.exchange.Request) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) HeaderExchangeHandler(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) ExchangeHandler(com.alibaba.dubbo.remoting.exchange.ExchangeHandler) Test(org.junit.Test)

Example 18 with ExchangeChannel

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);
        }
    });
}
Also used : ExchangeHandlerAdapter(com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) RemotingException(com.alibaba.dubbo.remoting.RemotingException) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Date(java.util.Date)

Example 19 with ExchangeChannel

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(" &gt; " + NetUtils.getHostName(address) + "/" + address);
        } else {
            select.append(" &gt; <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() + " &gt; Clients", "Clients (" + rows.size() + ")", new String[] { "Client Address:" }, rows);
}
Also used : ArrayList(java.util.ArrayList) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer) List(java.util.List) ArrayList(java.util.ArrayList) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Page(com.alibaba.dubbo.container.page.Page)

Aggregations

ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)19 Request (com.alibaba.dubbo.remoting.exchange.Request)6 Channel (com.alibaba.dubbo.remoting.Channel)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)4 Response (com.alibaba.dubbo.remoting.exchange.Response)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)3 HeaderExchangeHandler (com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)3 ExecutionException (com.alibaba.dubbo.remoting.ExecutionException)2 ExchangeHandler (com.alibaba.dubbo.remoting.exchange.ExchangeHandler)2 ExchangeHandlerAdapter (com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 URL (com.alibaba.dubbo.common.URL)1 Page (com.alibaba.dubbo.container.page.Page)1 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)1 ResponseFuture (com.alibaba.dubbo.remoting.exchange.ResponseFuture)1 ReplierDispatcher (com.alibaba.dubbo.remoting.exchange.support.ReplierDispatcher)1 Date (java.util.Date)1