use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class ClusteredEventBusTest method testSubsRemovedForKilledNode.
@Test
public void testSubsRemovedForKilledNode() throws Exception {
testSubsRemoved(latch -> {
VertxInternal vi = (VertxInternal) vertices[1];
Promise<Void> promise = vi.getOrCreateContext().promise();
vi.getClusterManager().leave(promise);
promise.future().onComplete(onSuccess(v -> {
latch.countDown();
}));
});
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class LocalEventBusTest method testContextsSend.
@Test
public void testContextsSend() throws Exception {
Set<ContextInternal> contexts = new ConcurrentHashSet<>();
CountDownLatch latch = new CountDownLatch(2);
vertx.eventBus().consumer(ADDRESS1).handler(msg -> {
msg.reply("bar");
contexts.add(((VertxInternal) vertx).getContext());
latch.countDown();
});
vertx.eventBus().request(ADDRESS1, "foo", onSuccess((Message<Object> reply) -> {
assertEquals("bar", reply.body());
contexts.add(((VertxInternal) vertx).getContext());
latch.countDown();
}));
awaitLatch(latch);
assertEquals(2, contexts.size());
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class ChannelProvider method handleProxyConnect.
/**
* A channel provider that connects via a Proxy : HTTP or SOCKS
*/
private void handleProxyConnect(Handler<Channel> handler, SocketAddress remoteAddress, SocketAddress peerAddress, String serverName, boolean ssl, boolean useAlpn, Promise<Channel> channelHandler) {
final VertxInternal vertx = context.owner();
final String proxyHost = proxyOptions.getHost();
final int proxyPort = proxyOptions.getPort();
final String proxyUsername = proxyOptions.getUsername();
final String proxyPassword = proxyOptions.getPassword();
final ProxyType proxyType = proxyOptions.getType();
vertx.resolveAddress(proxyHost, dnsRes -> {
if (dnsRes.succeeded()) {
InetAddress address = dnsRes.result();
InetSocketAddress proxyAddr = new InetSocketAddress(address, proxyPort);
ProxyHandler proxy;
switch(proxyType) {
default:
case HTTP:
proxy = proxyUsername != null && proxyPassword != null ? new HttpProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new HttpProxyHandler(proxyAddr);
break;
case SOCKS5:
proxy = proxyUsername != null && proxyPassword != null ? new Socks5ProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new Socks5ProxyHandler(proxyAddr);
break;
case SOCKS4:
// SOCKS4 only supports a username and could authenticate the user via Ident
proxy = proxyUsername != null ? new Socks4ProxyHandler(proxyAddr, proxyUsername) : new Socks4ProxyHandler(proxyAddr);
break;
}
bootstrap.resolver(NoopAddressResolverGroup.INSTANCE);
java.net.SocketAddress targetAddress = vertx.transport().convert(remoteAddress);
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addFirst("proxy", proxy);
pipeline.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof ProxyConnectionEvent) {
pipeline.remove(proxy);
pipeline.remove(this);
initSSL(handler, peerAddress, serverName, ssl, useAlpn, ch, channelHandler);
connected(handler, ch, ssl, channelHandler);
}
ctx.fireUserEventTriggered(evt);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
channelHandler.setFailure(cause);
}
});
}
});
ChannelFuture future = bootstrap.connect(targetAddress);
future.addListener(res -> {
if (!res.isSuccess()) {
channelHandler.setFailure(res.cause());
}
});
} else {
channelHandler.setFailure(dnsRes.cause());
}
});
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class AsyncResolveConnectHelper method doBind.
public static io.netty.util.concurrent.Future<Channel> doBind(VertxInternal vertx, SocketAddress socketAddress, ServerBootstrap bootstrap) {
Promise<Channel> promise = vertx.getAcceptorEventLoopGroup().next().newPromise();
try {
bootstrap.channelFactory(vertx.transport().serverChannelFactory(socketAddress.isDomainSocket()));
} catch (Exception e) {
promise.setFailure(e);
return promise;
}
if (socketAddress.isDomainSocket()) {
java.net.SocketAddress converted = vertx.transport().convert(socketAddress);
ChannelFuture future = bootstrap.bind(converted);
future.addListener(f -> {
if (f.isSuccess()) {
promise.setSuccess(future.channel());
} else {
promise.setFailure(f.cause());
}
});
} else {
SocketAddressImpl impl = (SocketAddressImpl) socketAddress;
Handler<AsyncResult<InetAddress>> cont = res -> {
if (res.succeeded()) {
// At this point the name is an IP address so there will be no resolve hit
InetSocketAddress t = new InetSocketAddress(res.result(), socketAddress.port());
ChannelFuture future = bootstrap.bind(t);
future.addListener(f -> {
if (f.isSuccess()) {
promise.setSuccess(future.channel());
} else {
promise.setFailure(f.cause());
}
});
} else {
promise.setFailure(res.cause());
}
};
if (impl.ipAddress() != null) {
cont.handle(Future.succeededFuture(impl.ipAddress()));
} else {
vertx.resolveAddress(socketAddress.host(), cont);
}
}
return promise;
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class ComplexHATest method checkDeployments.
protected void checkDeployments() {
int totalDeployed = 0;
for (int i = 0; i < vertices.length; i++) {
VertxInternal v = (VertxInternal) vertices[i];
if (!v.isKilled()) {
totalDeployed += checkHasDeployments(i, i);
}
}
assertEquals(totDeployed, totalDeployed);
}
Aggregations