use of com.alibaba.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class DubboInvokerAvilableTest method getClients.
private ExchangeClient[] getClients(DubboInvoker<?> invoker) throws Exception {
Field field = DubboInvoker.class.getDeclaredField("clients");
field.setAccessible(true);
ExchangeClient[] clients = (ExchangeClient[]) field.get(invoker);
Assert.assertEquals(1, clients.length);
return clients;
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class ReferenceCountExchangeClientTest method getClient.
private ExchangeClient getClient(Invoker<?> invoker) {
if (invoker.getUrl().getParameter(Constants.CONNECTIONS_KEY, 1) == 1) {
return getInvokerClient(invoker);
} else {
ReferenceCountExchangeClient client = getReferenceClient(invoker);
try {
Field clientField = ReferenceCountExchangeClient.class.getDeclaredField("client");
clientField.setAccessible(true);
return (ExchangeClient) clientField.get(client);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
throw new RuntimeException(e);
}
}
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class PortTelnetHandlerTest method testListClient.
/**
* In NAT network scenario, server's channel.getRemoteAddress() possibly get the address of network gateway, or
* the address converted by NAT. In this case, check port only.
*/
@Test
public void testListClient() throws Exception {
ExchangeClient client1 = Exchangers.connect("dubbo://127.0.0.1:20887/demo");
ExchangeClient client2 = Exchangers.connect("dubbo://127.0.0.1:20887/demo");
Thread.sleep(5000);
String result = port.telnet(null, "-l 20887");
String client1Addr = client1.getLocalAddress().toString();
String client2Addr = client2.getLocalAddress().toString();
System.out.printf("Result: %s %n", result);
System.out.printf("Client 1 Address %s %n", client1Addr);
System.out.printf("Client 2 Address %s %n", client2Addr);
assertTrue(result.contains(String.valueOf(client1.getLocalAddress().getPort())));
assertTrue(result.contains(String.valueOf(client2.getLocalAddress().getPort())));
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class ThriftInvoker method doInvoke.
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
RpcInvocation inv = (RpcInvocation) invocation;
final String methodName;
methodName = invocation.getMethodName();
inv.setAttachment(Constants.PATH_KEY, getUrl().getPath());
// for thrift codec
inv.setAttachment(ThriftCodec.PARAMETER_CLASS_NAME_GENERATOR, getUrl().getParameter(ThriftCodec.PARAMETER_CLASS_NAME_GENERATOR, DubboClassNameGenerator.NAME));
ExchangeClient currentClient;
if (clients.length == 1) {
currentClient = clients[0];
} else {
currentClient = clients[index.getAndIncrement() % clients.length];
}
try {
int timeout = getUrl().getMethodParameter(methodName, Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
RpcContext.getContext().setFuture(null);
return (Result) currentClient.request(inv, timeout).get();
} catch (TimeoutException e) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, e.getMessage(), e);
} catch (RemotingException e) {
throw new RpcException(RpcException.NETWORK_EXCEPTION, e.getMessage(), e);
}
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeClient in project dubbo by alibaba.
the class ExchangeServerPeer method getExchangeChannel.
@Override
public ExchangeChannel getExchangeChannel(InetSocketAddress remoteAddress) {
String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName();
int port = remoteAddress.getPort();
ExchangeChannel channel = super.getExchangeChannel(remoteAddress);
if (channel == null) {
for (Map.Entry<URL, ExchangeClient> entry : clients.entrySet()) {
URL url = entry.getKey();
if (url.getIp().equals(host) && url.getPort() == port) {
return entry.getValue();
}
}
}
return channel;
}
Aggregations