Java Code Examples for com.alibaba.dubbo.remoting.exchange.Exchangers#bind()
The following examples show how to use
com.alibaba.dubbo.remoting.exchange.Exchangers#bind() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, 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(Constants.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 server; }
Example 2
Source File: ThriftProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private ExchangeServer getServer(URL url) { //默认开启server关闭时发送readonly事件 url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()); String str = url.getParameter(Constants.SERVER_KEY, 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(Constants.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 server; }
Example 3
Source File: Main.java From dubbox with Apache License 2.0 | 5 votes |
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); }
Example 4
Source File: HeartbeatHandlerTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testHeartbeat() throws Exception { URL serverURL = URL.valueOf("header://localhost:55555"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); client = Exchangers.connect(serverURL); Thread.sleep(10000); System.err.println("++++++++++++++ disconnect count " + handler.disconnectCount); System.err.println("++++++++++++++ connect count " + handler.connectCount); Assert.assertTrue(handler.disconnectCount == 0); Assert.assertTrue(handler.connectCount == 1); }
Example 5
Source File: HeartbeatHandlerTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testClientHeartbeat() throws Exception { FakeChannelHandlers.setTestingChannelHandlers(); URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty4"); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); FakeChannelHandlers.resetChannelHandlers(); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); client = Exchangers.connect(serverURL); Thread.sleep(10000); Assert.assertTrue(handler.connectCount > 0); System.out.println("connect count " + handler.connectCount); }
Example 6
Source File: HeartbeatHandlerTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testHeartbeat() throws Exception { URL serverURL = URL.valueOf("header://localhost:55555"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); client = Exchangers.connect(serverURL); Thread.sleep(10000); System.err.println("++++++++++++++ disconnect count " + handler.disconnectCount); System.err.println("++++++++++++++ connect count " + handler.connectCount); Assert.assertTrue(handler.disconnectCount == 0); Assert.assertTrue(handler.connectCount == 1); }
Example 7
Source File: NettyClientTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testServerClose() throws Exception { for (int i = 0; i < 100; i++) { Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?client=netty"), new TelnetServerHandler()); aServer.close(); } }
Example 8
Source File: AbstractBenchmarkServer.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
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() { @Override public Object reply(ExchangeChannel channel, Object message) throws RemotingException { return new ResponseObject(responseSize); // send response } }); }
Example 9
Source File: NettyClientTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testServerClose() throws Exception { for (int i = 0; i < 100; i++) { Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?transporter=netty4"), new TelnetServerHandler()); aServer.close(); } }
Example 10
Source File: NettyStringTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { //int port = (int) (1000 * Math.random() + 10000); int port = 10001; System.out.println(port); server = Exchangers.bind(URL.valueOf("telnet://0.0.0.0:" + port + "?server=netty"), new TelnetServerHandler()); client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty"), new TelnetClientHandler()); }
Example 11
Source File: AbstractExchangeGroup.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public ExchangePeer join(URL url, ExchangeHandler handler) throws RemotingException { ExchangeServer server = servers.get(url); if (server == null) { // TODO 有并发间隙 server = Exchangers.bind(url, handler); servers.put(url, server); dispatcher.addChannelHandler(handler); } return new ExchangeServerPeer(server, clients, this); }
Example 12
Source File: AbstractBenchmarkServer.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
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 { return new ResponseObject(responseSize); // 发送响应 } }); }
Example 13
Source File: Main.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
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); }
Example 14
Source File: HeartbeatHandlerTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testServerHeartbeat() throws Exception { URL serverURL = URL.valueOf("header://localhost:55555"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); FakeChannelHandlers.setTestingChannelHandlers(); serverURL = serverURL.removeParameter(Constants.HEARTBEAT_KEY); client = Exchangers.connect(serverURL); Thread.sleep(10000); Assert.assertTrue(handler.disconnectCount > 0); System.out.println("disconnect count " + handler.disconnectCount); }
Example 15
Source File: ClientReconnectTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public Server startServer(int port) throws RemotingException { final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?server=netty4"; return Exchangers.bind(url, new HandlerAdapter()); }
Example 16
Source File: MinaClientToServerTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Override protected ExchangeServer newServer(int port, Replier<?> receiver) throws RemotingException { return Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=mina"), receiver); }
Example 17
Source File: MinaClientToServerTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
@Override protected ExchangeServer newServer(int port, Replier<?> receiver) throws RemotingException { return Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=mina"), receiver); }
Example 18
Source File: ClientReconnectTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public Server startServer(int port) throws RemotingException{ final String url = "exchange://127.0.0.1:"+port +"/client.reconnect.test"; return Exchangers.bind(url, new HandlerAdapter()); }
Example 19
Source File: NettyClientTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
@BeforeClass public static void setUp() throws Exception { server = Exchangers.bind(URL.valueOf("exchange://localhost:10001?server=netty"), new TelnetServerHandler()); }
Example 20
Source File: NettyClientToServerTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
protected ExchangeServer newServer(int port, Replier<?> receiver) throws RemotingException { return Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=netty4"), receiver); }