io.vertx.core.impl.VertxImpl Java Examples

The following examples show how to use io.vertx.core.impl.VertxImpl. 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: TestHttpClientPoolFactory.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void createClientPool(@Mocked VertxInternal vertx, @Mocked ContextInternal context,
    @Mocked HttpClient httpClient) {
  new Expectations(VertxImpl.class) {
    {
      context.owner();
      result = vertx;
      vertx.createHttpClient(httpClientOptions);
      result = httpClient;
    }
  };
  HttpClientWithContext pool = factory.createClientPool(context);

  Assert.assertSame(context, pool.context());
  Assert.assertSame(httpClient, pool.getHttpClient());
}
 
Example #2
Source File: TestClientPoolManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void findByContext_otherVertx(@Mocked VertxImpl otherVertx, @Mocked Context otherContext) {
  HttpClientWithContext pool = new HttpClientWithContext(null, null);
  pools.add(pool);

  new Expectations() {
    {
      Vertx.currentContext();
      result = otherContext;
      otherContext.owner();
      result = otherVertx;
    }
  };

  Assert.assertSame(pool, poolMgr.findByContext());
}
 
Example #3
Source File: DeployKonduitServing.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInference(VertxOptions vertxOptions, DeploymentOptions deploymentOptions, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    Vertx vertx = Vertx.vertx(vertxOptions);

    vertx.deployVerticle(clazz(), deploymentOptions, handler -> {
        if (handler.failed()) {
            log.error("Unable to deploy verticle {}", className(), handler.cause());

            if (eventHandler != null) {
                eventHandler.handle(Future.failedFuture(handler.cause()));
            }

            vertx.close();
        } else {
            log.info("Deployed verticle {}", className());
            if (eventHandler != null) {
                VertxImpl vertxImpl = (VertxImpl) vertx;
                DeploymentOptions inferenceDeploymentOptions = vertxImpl.getDeployment(handler.result()).deploymentOptions();

                try {
                    InferenceConfiguration inferenceConfiguration = ObjectMappers.fromJson(inferenceDeploymentOptions.getConfig().encode(), InferenceConfiguration.class);
                    eventHandler.handle(Future.succeededFuture(inferenceConfiguration));
                } catch (Exception exception){
                    log.debug("Unable to parse json configuration into an InferenceConfiguration object. " +
                            "This can be ignored if the verticle isn't an InferenceVerticle.", exception); // TODO: this is done for supporting other verticles in the future. For instance, 'ConverterVerticle'.
                    eventHandler.handle(Future.succeededFuture());
                }
            }
        }
    });
}
 
Example #4
Source File: VertxCoreRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public Supplier<EventLoopGroup> bossSupplier() {
    return new Supplier<EventLoopGroup>() {
        @Override
        public EventLoopGroup get() {
            return ((VertxImpl) vertx.get()).getAcceptorEventLoopGroup();
        }
    };
}
 
Example #5
Source File: VertxHttpProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Workaround for https://github.com/quarkusio/quarkus/issues/4720 by filtering Vertx multiple instance warning in dev
 * mode.
 */
@BuildStep
void filterMultipleVertxInstancesWarning(LaunchModeBuildItem launchModeBuildItem,
        BuildProducer<LogCleanupFilterBuildItem> logCleanupFilterBuildItemBuildProducer) {
    if (launchModeBuildItem.getLaunchMode().equals(LaunchMode.DEVELOPMENT)) {
        logCleanupFilterBuildItemBuildProducer.produce(new LogCleanupFilterBuildItem(VertxImpl.class.getName(),
                "You're already on a Vert.x context, are you sure you want to create a new Vertx instance"));
    }
}
 
Example #6
Source File: VertxUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private static void enhanceVertx(String name, Vertx vertx) {
  if (StringUtils.isEmpty(name)) {
    return;
  }
  Field field = ReflectionUtils.findField(VertxImpl.class, "eventLoopThreadFactory");
  field.setAccessible(true);
  VertxThreadFactory eventLoopThreadFactory = (VertxThreadFactory) ReflectionUtils.getField(field, vertx);

  field = ReflectionUtils.findField(eventLoopThreadFactory.getClass(), "prefix");
  field.setAccessible(true);

  String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory);
  ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix);
}
 
Example #7
Source File: TestClientPoolManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void createClientPool(@Mocked HttpClientWithContext pool) {
  new Expectations(VertxImpl.class) {
    {
      factory.createClientPool(context);
      result = pool;
    }
  };

  Assert.assertSame(pool, poolMgr.createClientPool(context));
  Assert.assertSame(pool, context.get(id));
  Assert.assertThat(pools, Matchers.contains(pool));
}
 
Example #8
Source File: ProxyHandler.java    From nassh-relay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handle(final RoutingContext context) {
    logger.debug("got request");
    final HttpServerRequest request = context.request();
    final HttpServerResponse response = context.response();
    response.putHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
    response.putHeader("Pragma", "no-cache");
    if (request.params().contains("host") && request.params().contains("port")) {
        AuthSession authPreSession = null;
        if (authentication) {
            authPreSession = WebHelper.validateCookie(context);
            if (authPreSession == null) {
                response.setStatusCode(410);
                response.end("session invalid");
                return;
            }
        }
        final AuthSession authSession = authPreSession;
        final String host = request.params().get("host");
        final int port = Integer.parseInt(request.params().get("port"));
        final UUID sid = UUID.randomUUID();
        final String clienthost = RequestHelper.getRemoteHost(request);
        if (sessions.size() >= sessionlimit) {
            response.setStatusCode(410);
            response.end("session limit reached");
            logger.warn("ssh session limit of " + sessionlimit + " reached");
            return;
        }
        ((VertxImpl) vertx).resolveAddress(host, result -> {
            if (result.succeeded()) {
                final InetAddress address = result.result();
                vertx.<Boolean>executeBlocking(promise -> {
                    final boolean isAllowed = AccessHelper.isHostAllowed(accessList, whiteList, blackList, address, authSession);
                    promise.complete(isAllowed);
                }, false, res -> {
                    if (res.succeeded()) {
                        if (!res.result()) {
                            response.setStatusCode(410);
                            response.end("host not allowed");
                            logger.warn("client " + clienthost + " " + (authSession == null ? "" : "(" + authSession + ")") + " tried to access " + address.getHostAddress() + " but was not allowed");
                        } else {
                            connectTcpEndpoint(sid, address.getHostAddress(), port, clienthost).future().onComplete(ar -> {
                                if (ar.succeeded()) {
                                    response.setStatusCode(200);
                                    response.end(sid.toString());
                                } else {
                                    response.setStatusCode(500);
                                    response.end("could not init ssh session");
                                }
                            });
                        }
                    } else {
                        logger.error(res.cause().getMessage(), res.cause());
                        response.setStatusCode(500);
                        response.end("internal server error");
                    }
                });
            } else {
                response.setStatusCode(410);
                response.end("invalid host");
            }
        });
    } else {
        response.setStatusCode(410);
        response.end("error");
    }
}