public static void config(String graphiteHost, int port, TimeUnit tu, int period, VertxOptions vopt, String hostName) { final String registryName = "okapi"; MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName); DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions(); metricsOpt.setEnabled(true).setRegistryName(registryName); vopt.setMetricsOptions(metricsOpt); Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, port)); final String prefix = "folio.okapi." + hostName ; GraphiteReporter reporter = GraphiteReporter.forRegistry(registry) .prefixedWith(prefix) .build(graphite); reporter.start(period, tu); logger.info("Metrics remote:" + graphiteHost + ":" + port + " this:" + prefix); }
public VertxImplEx(String name, VertxOptions vertxOptions) { super(vertxOptions); if (StringUtils.isEmpty(name)) { return; } Field field = ReflectionUtils.findField(VertxImpl.class, "eventLoopThreadFactory"); field.setAccessible(true); VertxThreadFactory eventLoopThreadFactory = (VertxThreadFactory) ReflectionUtils.getField(field, this); field = ReflectionUtils.findField(eventLoopThreadFactory.getClass(), "prefix"); field.setAccessible(true); String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory); ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix); }
@Test public void testInit() { boolean status = false; try { new MockUp<VertxUtils>() { @Mock public Vertx init(VertxOptions vertxOptions) { return null; } @Mock public <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException { return true; } }; instance.init(); } catch (Exception e) { status = true; } Assert.assertFalse(status); }
public static void main(String... args) { //Note to self // run this demo in HA mode, deploy this verticle on a separate node and combine it with demo6 final JsonObject config = Config.fromFile("config/demo7.json"); VertxOptions opts = new VertxOptions().setClustered(true); Vertx.clusteredVertx(opts, result -> { if (result.succeeded()) { LOG.info("Cluster running"); Vertx vertx = result.result(); vertx.deployVerticle(BitcoinAdjustedData.class.getName(), new DeploymentOptions().setConfig(config).setWorker(false)); } else { LOG.error("Clusterin failed"); throw new RuntimeException(result.cause()); } }); }
public static void main(String... args) { final JsonObject config = Config.fromFile("config/demo6.json"); Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new JSPercentilesDatasource(), new DeploymentOptions().setConfig(config)); /* Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config)); */ VertxOptions opts = new VertxOptions().setClustered(true); Vertx.clusteredVertx(opts, result -> { if(result.succeeded()){ LOG.info("Cluster running"); Vertx cvertx = result.result(); cvertx.deployVerticle(new JSPercentilesDatasource(), new DeploymentOptions().setConfig(config)); } else { LOG.error("Clustering failed"); throw new RuntimeException(result.cause()); } }); }
public static void main(String... args) { final JsonObject config = Config.fromFile("config/demo6.json"); /* Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config)); */ VertxOptions opts = new VertxOptions().setClustered(true); Vertx.clusteredVertx(opts, result -> { if(result.succeeded()){ LOG.info("Cluster running"); Vertx vertx = result.result(); vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config)); } else { LOG.error("Clustering failed"); throw new RuntimeException(result.cause()); } }); }
public static void main(String... args) { VertxOptions options = new VertxOptions().setClustered(true) .setHAEnabled(true) .setHAGroup("dev"); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); deployVerticles(vertx); LOG.info("Vertx Cluster running"); } else { LOG.error("Creating Vertx cluster failed", res.cause()); } }); }
@Provides @Singleton public Vertx provideVertx(ApplicationConfiguration applicationConfiguration) { VertxOptions vertxOptions = new VertxOptions() .setMaxEventLoopExecuteTime(applicationConfiguration.getMaxEventLoopExecutionTime()) .setWarningExceptionTime(20L * 1000 * 1000000) .setMaxWorkerExecuteTime(applicationConfiguration.getMaxWorkerExecutionTime()) .setWorkerPoolSize(applicationConfiguration.getWorkerPoolSize()); // see // https://github.com/vert-x3/vertx-dropwizard-metrics/blob/master/src/main/asciidoc/java/index.adoc#jmx vertxOptions.setMetricsOptions( new DropwizardMetricsOptions() .setEnabled(applicationConfiguration.isMetricsEnabled()) .setJmxEnabled(applicationConfiguration.isJmxEnabled()) .setJmxDomain(applicationConfiguration.getJmxDomainName())); return Vertx.vertx(vertxOptions); }
public Single<Void> start(JsonObject defaultConfig, Class<?>... resourceOrProviderClasses){ setupLogging(); VertxOptions options = new VertxOptions(); options.setWarningExceptionTime(Long.MAX_VALUE); vertx = Vertx.vertx(options); AppGlobals.init(); AppGlobals.get().setVertx(vertx); // Propagate the Resteasy context on RxJava RxJavaHooks.setOnSingleCreate(new ResteasyContextPropagatingOnSingleCreateAction()); return loadConfig(defaultConfig) .flatMap(config -> { return setupPlugins() .flatMap(v -> setupTemplateRenderers()) .flatMap(v -> setupResteasy(resourceOrProviderClasses)) .flatMap(deployment -> { setupSwagger(deployment); return setupVertx(config, deployment); }); }); }
@Override public ConcurrentMap<String, VertxOptions> visit(final String... keys) throws ZeroException { // 1. Must be the first line, fixed position. Ensurer.eqLength(getClass(), 0, (Object[]) keys); // 2. Visit the node for vertx final JsonObject data = this.NODE.read(); // 3. Vertx node validation. final JsonObject vertxData = data.getJsonObject(KEY); LOGGER.info(Info.INF_B_VERIFY, KEY, getClass().getSimpleName(), vertxData); Fn.shuntZero(() -> Ruler.verify(KEY, vertxData), vertxData); // 4. Set cluster options this.clusterOptions = this.clusterTransformer.transform(data.getJsonObject(YKEY_CLUSTERED)); // 5. Transfer Data return visit(vertxData.getJsonArray(YKEY_INSTANCE)); }
private ConcurrentMap<String, VertxOptions> visit( final JsonArray vertxData) throws ZeroException { final ConcurrentMap<String, VertxOptions> map = new ConcurrentHashMap<>(); final boolean clustered = this.clusterOptions.isEnabled(); Fn.etJArray(vertxData, JsonObject.class, (item, index) -> { // 1. Extract single final String name = item.getString(YKEY_NAME); // 2. Extract VertxOptions final VertxOptions options = this.transformer.transform(item); // 3. Check the configuration for cluster sync Fn.flingZero(clustered != options.isClustered(), LOGGER, ClusterConflictException.class, getClass(), name, options.toString()); // 4. Put the options into map map.put(name, options); }); return map; }
public void start() { sdk = null; config = null; if (server == null) { Vertx vertx = Vertx .vertx(new VertxOptions().setWorkerPoolSize(40).setBlockedThreadCheckInterval(1000L * 60L * 10L) .setMaxWorkerExecuteTime(1000L * 1000L * 1000L * 60L * 10L)); HttpServerOptions options = new HttpServerOptions(); options.setMaxInitialLineLength(HttpServerOptions.DEFAULT_MAX_INITIAL_LINE_LENGTH * 2); server = vertx.createHttpServer(options); router = Router.router(vertx); } retrieveConfig(); if (config == null || config.isApiKeyEmpty()) { logError("Unable to find " + String.valueOf(ENVVAR_MBED_CLOUD_API_KEY) + " environment variable"); System.exit(1); } defineInitialisationRoute(); defineModuleMethodTestRoute(); logInfo("Starting Java SDK test server on port " + String.valueOf(port) + "..."); server.requestHandler(router::accept).listen(port); }
static void main(String[] asdfasd) { JDBCClient jdbcClient = Test.jdbcClient("jpadb", Vertx.vertx(new VertxOptions() .setWorkerPoolSize(1) .setEventLoopPoolSize(1) )); BaseOrm baseOrm = Test.baseOrm(); final JsonObject employee = new JsonObject( "{\"eid\":1201,\"ename\":\"Gopal\",\"salary\":40000.0,\"deg\":\"Technical Manager\",\"department\":{\"id\":98798079087,\"name\":\"ICT\",\"department\":{\"id\":98457984,\"name\":\"RGV\",\"department\":{\"id\":94504975049,\"name\":\"MCE\",\"department\":null,\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"department2\":{\"id\":988286326887,\"name\":\"BGGV\",\"department\":{\"id\":8283175518,\"name\":\"MKLC\",\"department\":{\"id\":56165582,\"name\":\"VVKM\",\"department\":null,\"employee\":{\"eid\":2389,\"ename\":\"KOMOL\",\"salary\":8000.0,\"deg\":\"DOC\",\"department\":null,\"department2\":null,\"departments\":[]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"departments\":[{\"id\":98798079087,\"name\":\"ICT\",\"department\":{\"id\":98457984,\"name\":\"RGV\",\"department\":{\"id\":94504975049,\"name\":\"MCE\",\"department\":null,\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}}]}" ); merge(employee); System.out.println(employee.encodePrettily()); baseOrm.upsert( BaseOrm.UpsertParams.builder() .entity("employee") .jsonObject(employee) .build() ).mapP(Test.sqlDB()::update).then(jsonObject -> { System.out.println("ppp888888888888888888888888888888888888888888888888888888888888888888888"); }).err(Throwable::printStackTrace); }
@Test public void name() throws Exception { JsonObject config = new JsonObject() .put("gremlinServerConfigPath", "gremlin-server.yaml") // .put("gremlinServerConfigPath", "D:\\tg-metagraph-reposities\\vertx-gremlin\\vertx-gremlin-server\\src\\test\\resources\\gremlin-server.yaml") .put("eventBusAddress", "outMessage"); DeploymentOptions options = new DeploymentOptions().setConfig(config); VertxOptions vertxOptions = new VertxOptions().setClustered(true); Vertx.clusteredVertx(vertxOptions, event -> { if (event.succeeded()) { Vertx vertx = event.result(); vertx.deployVerticle(new VertxGremlinServer(), options); } }); Thread.sleep(Long.MAX_VALUE); }
@Override protected void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> ar) { CountDownLatch latch = new CountDownLatch(1); Future<Vertx> future = Future.future(); future.setHandler(ar); super.clusteredVertx(options, asyncResult -> { if (asyncResult.succeeded()) { future.complete(asyncResult.result()); } else { future.fail(asyncResult.cause()); } latch.countDown(); }); try { assertTrue(latch.await(2, TimeUnit.MINUTES)); } catch (InterruptedException e) { fail(e.getMessage()); } }
@Test(timeout = 15000L) public void shouldFireSessionExpiredEventForHazelcastSessionStore(TestContext context) { Async async = context.async(); Vertx.clusteredVertx(new VertxOptions().setClusterManager(new HazelcastClusterManager()), res -> { vertx = res.result(); SessionStore adapted = SessionStoreAdapter.adapt(vertx, ClusteredSessionStore.create(vertx)); Session session = adapted.createSession(2000); sessionExpiredConsumer = SessionStoreAdapter.sessionExpiredHandler(vertx, event -> { context.assertEquals(session.id(), event.body()); async.countDown(); }); adapted.put(session, Future.<Boolean>future().completer()); session.put("a", "b"); }); }
/** * not using @junit @Before since not all tests want to the same configuration for vertx metrics. * Don't forget to call this in your method */ public void setup(boolean isDryRun, Long flushInterval, Integer flushSize) { StatfulMetricsOptions options = new StatfulMetricsOptions() .setPort(PORT) .setHost(HOST) .setDryrun(isDryRun) .setEnablePoolMetrics(false) .setMaxBufferSize(5000) .setToken("a token") .setSecure(false); Optional.ofNullable(flushInterval).ifPresent(options::setFlushInterval); Optional.ofNullable(flushSize).ifPresent(options::setFlushSize); this.vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(options)); this.victim = new HttpSender(vertx, vertx.getOrCreateContext(), options); this.server = vertx.createHttpServer(); }
@Test public void testCreationFromFile(TestContext context) { Async async = context.async(); StatfulMetricsOptions options = new StatfulMetricsOptions(); options.setConfigPath("config/statful.json") // setting enabled to false, to check that the configuration available on file is used .setEnabled(false); VertxOptions vertxOptions = new VertxOptions().setMetricsOptions(options); Vertx vertx = Vertx.vertx(vertxOptions); StatfulMetricsFactoryImpl victim = new StatfulMetricsFactoryImpl(); assertTrue(victim.metrics(vertx, vertxOptions).isEnabled()); vertx.close(close -> async.complete()); }
@Test public void testCreationFromNonExistentFile(TestContext context) { Async async = context.async(); StatfulMetricsOptions options = new StatfulMetricsOptions(); options.setConfigPath("config/statful-not-existent.json") // setting enabled to false, to check that the configuration available on file is used .setEnabled(false); VertxOptions vertxOptions = new VertxOptions().setMetricsOptions(options); Vertx vertx = Vertx.vertx(vertxOptions); StatfulMetricsFactoryImpl victim = new StatfulMetricsFactoryImpl(); try { victim.metrics(vertx, vertxOptions); context.assertTrue(false, "should never run, an exception should've been thrown"); } catch (RuntimeException e) { vertx.close(close -> async.complete()); } }
@Before public void setUp(TestContext context) { Async async = context.async(); VertxOptions options = new VertxOptions(); options.setBlockedThreadCheckInterval(60000); // in ms options.setWarningExceptionTime(60000); // in ms vertx = Vertx.vertx(options); RestAssured.port = port; client = vertx.createHttpClient(); checkDocker(res2 -> { haveDocker = res2.succeeded(); logger.info("haveDocker = " + haveDocker); DeploymentOptions opt = new DeploymentOptions() .setConfig(new JsonObject().put("port", Integer.toString(port))); vertx.deployVerticle(MainVerticle.class.getName(), opt, res -> async.complete()); }); }
private void initVerticle(Handler<Object> handler){ //start vert.x ClusterManager mgr = new HazelcastClusterManager(); VertxOptions options = new VertxOptions().setClusterManager(mgr); options.setWorkerPoolSize(1000); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { vertx = res.result(); vertx.eventBus().registerDefaultCodec(MessageBody.class, new MessageBodyCodec()); AppConfig appConfig = context.getBean(AppConfig.class); appConfig.setVertx(vertx); appConfig.setAppClass(appClass); appConfig.setAppName(appName); handler.handle(1); } else { logger.error("fail clusteredVertx"); } }); }
public static void main(String[] args) { VertxOptions options = new VertxOptions(); options.setMaxEventLoopExecuteTime(Long.MAX_VALUE); final Vertx vertx = Vertx.factory.vertx(options); ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class); Verticle serverVerticle = (Verticle) context.getBean("serverVerticle"); Verticle userDatabaseVerticle = (Verticle) context.getBean("userDatabaseVerticle"); Verticle blogServiceVerticle = (Verticle) context.getBean("blogServiceVerticle"); vertx.deployVerticle(serverVerticle); vertx.deployVerticle(userDatabaseVerticle, new DeploymentOptions().setWorker(true)); vertx.deployVerticle(blogServiceVerticle, new DeploymentOptions().setWorker(true)); }
public static Vertx getOrCreateVertxByName(String name, VertxOptions vertxOptions) { Vertx vertx = getVertxByName(name); if (vertx == null) { synchronized (VertxUtils.class) { vertx = getVertxByName(name); if (vertx == null) { vertx = init(name, vertxOptions); vertxMap.put(name, vertx); } } } return vertx; }
@Test public void testVertxUtilsInitWithOptions() { VertxOptions oOptions = new VertxOptions(); oOptions.setClustered(false); Vertx vertx = VertxUtils.init(oOptions); Assert.assertNotEquals(null, vertx); vertx.close(); }
public SpringVertx(VertxFactory factory, VertxOptions options, Collection<VerticleRegistration> verticleRegistrations, List<VertxListener> listeners, String verticleFactoryPrefix, int startupPhase, boolean autoStartup) { this.factory = factory; this.options = new VertxOptions(options); this.verticleRegistrations = new ArrayList<>(verticleRegistrations); this.verticleFactoryPrefix = verticleFactoryPrefix; this.startupPhase = startupPhase; this.autoStartup = autoStartup; }
public Builder options(Consumer<VertxOptions> optionsSpec) { if (this.options == null) { this.options = new VertxOptions(); } optionsSpec.accept(options); return this; }
public VertxOptions toVertxOptions() { VertxOptions newOptions = new VertxOptions(this.vertxOptions); if (addressResolver != null) { newOptions.setAddressResolverOptions(addressResolver.toAddressResolverOptions()); } if (eventBus != null) { newOptions.setEventBusOptions(eventBus); } return newOptions; }
public VertxNetworkBackend () { this.options = new VertxOptions(); //create new vertx.io instance this.vertx = Vertx.vertx(this.options); //set connection timeout of 1 seconds this.netClientOptions.setConnectTimeout(5000); //if connection fails, try 1x /*this.netClientOptions.setReconnectAttempts(5) .setReconnectInterval(500);*/ }
@Bean public VertxOptions vertxOptions() { return new VertxOptions() .setWarningExceptionTime(vertxWarningExceptionTime) .setWorkerPoolSize(vertxWorkerPoolSize); }
public static void main(final String[] args) throws Exception { final VertxOptions vertOptions = new VertxOptions(); vertOptions.setWarningExceptionTime(1); vertOptions.setWorkerPoolSize(50); final Vertx vertx = Vertx.vertx(vertOptions); final DeploymentOptions options = new DeploymentOptions(); vertx.deployVerticle(new EngineSampleMain(), options); }
@Bean public VertxOptions vertxOptions(final AddressResolverOptions addressResolverOptions) { return new VertxOptions() .setAddressResolverOptions(addressResolverOptions) .setWarningExceptionTime(vertxWarningExceptionTime) .setWorkerPoolSize(vertxWorkerPoolSize); }