當前位置: 首頁>>代碼示例>>Java>>正文


Java Vertx類代碼示例

本文整理匯總了Java中io.vertx.core.Vertx的典型用法代碼示例。如果您正苦於以下問題:Java Vertx類的具體用法?Java Vertx怎麽用?Java Vertx使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Vertx類屬於io.vertx.core包,在下文中一共展示了Vertx類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hello3

import io.vertx.core.Vertx; //導入依賴的package包/類
@Path("3")
@GET
public void hello3(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	System.err.println("Creating client");
	HttpClientOptions options = new HttpClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	HttpClient client = vertx.createHttpClient(options);
	client.getNow(443,
			"www.google.com", 
			"/robots.txt", 
			resp -> {
				System.err.println("Got response");
				resp.bodyHandler(body -> {
					System.err.println("Got body");
					asyncResponse.resume(Response.ok(body.toString()).build());
				});
			});
	System.err.println("Created client");
}
 
開發者ID:FroMage,項目名稱:redpipe,代碼行數:24,代碼來源:MyResource.java

示例2: initInternal

import io.vertx.core.Vertx; //導入依賴的package包/類
private static void initInternal(final Vertx vertx,
                                 final String name) {
    vertxRef = vertx;
    Fn.pool(CONFIGS, name,
            () -> Infix.init(Plugins.Infix.JOOQ,
                    (config) -> {
                        // Initialized client
                        final Configuration configuration = new DefaultConfiguration();
                        configuration.set(SQLDialect.MYSQL_8_0);
                        final ConnectionProvider provider =
                                new DefaultConnectionProvider(HikariCpPool.getConnection(
                                        config.getJsonObject("provider")
                                ));
                        // Initialized default configuration
                        configuration.set(provider);
                        return configuration;
                    }, JooqInfix.class));
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:19,代碼來源:JooqInfix.java

示例3: findByContext

import io.vertx.core.Vertx; //導入依賴的package包/類
protected CLIENT_POOL findByContext() {
  Context currentContext = Vertx.currentContext();
  if (currentContext != null
      && currentContext.owner() == vertx
      && currentContext.isEventLoopContext()) {
    // standard reactive mode
    CLIENT_POOL clientPool = currentContext.get(id);
    if (clientPool != null) {
      return clientPool;
    }

    // this will make "client.thread-count" bigger than which in microservice.yaml
    // maybe it's better to remove "client.thread-count", just use "rest/highway.thread-count"
    return createClientPool();
  }

  // not in correct context:
  // 1.normal thread
  // 2.vertx worker thread
  // 3.other vertx thread
  // select a existing context
  return nextPool();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:ClientPoolManager.java

示例4: VertxAsyncSecurityHandler

import io.vertx.core.Vertx; //導入依賴的package包/類
public VertxAsyncSecurityHandler(final Vertx vertx,
                                 final Context context,
                                 final AsyncConfig config, final Pac4jAuthProvider authProvider,
                                 final SecurityHandlerOptions options) {
    super(authProvider);
    CommonHelper.assertNotNull("vertx", vertx);
    CommonHelper.assertNotNull("context", context);
    CommonHelper.assertNotNull("config", config);
    CommonHelper.assertNotNull("config.getClients()", config.getClients());
    CommonHelper.assertNotNull("authProvider", authProvider);
    CommonHelper.assertNotNull("options", options);

    clientNames = options.getClients();
    authorizerName = options.getAuthorizers();
    matcherName = options.getMatchers();
    multiProfile = options.isMultiProfile();
    this.vertx = vertx;
    this.asynchronousComputationAdapter = new VertxAsynchronousComputationAdapter(vertx, context);
    this.context = context;
    this.config = config;

    final DefaultAsyncSecurityLogic<Void, U , VertxAsyncWebContext> securityLogic = new DefaultAsyncSecurityLogic<Void, U, VertxAsyncWebContext>(options.isSaveProfileInSession(),
            options.isMultiProfile(), config, httpActionAdapter);
    securityLogic.setProfileManagerFactory(c -> new VertxAsyncProfileManager(c));
    this.securityLogic = securityLogic;
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:27,代碼來源:VertxAsyncSecurityHandler.java

示例5: testCreationWithVertx

import io.vertx.core.Vertx; //導入依賴的package包/類
@Test
public void testCreationWithVertx() {
  Vertx vertx = Vertx.vertx();
  Fluid fluid = new Fluid(vertx);

  List<String> list = new ArrayList<>();
  FluidRegistry.register("input", Source.from("a", "b", "c"));
  FluidRegistry.register("output", Sink.<String>forEachPayload(list::add));

  fluid.deploy(f -> {
    Sink<String> output = f.sink("output");
    f.<String>from("input")
      .transformPayload(String::toUpperCase)
      .to(output);
  });

  await().until(() -> list.size() == 3);
  assertThat(list).containsExactly("A", "B", "C");
}
 
開發者ID:cescoffier,項目名稱:fluid,代碼行數:20,代碼來源:FluidTest.java

示例6: deploy

import io.vertx.core.Vertx; //導入依賴的package包/類
static void deploy(final Vertx vertx,
                   final Class<?> clazz,
                   final DeploymentOptions option,
                   final Annal logger) {
    // Verticle deployment
    final String name = clazz.getName();
    final String flag = option.isWorker() ? "Worker" : "Agent";
    vertx.deployVerticle(name, option, (result) -> {
        // Success or Failed.
        if (result.succeeded()) {
            logger.info(Info.VTC_END,
                    name, option.getInstances(), result.result(),
                    flag);
            INSTANCES.put(clazz, result.result());
        } else {
            logger.warn(Info.VTC_FAIL,
                    name, option.getInstances(), result.result(),
                    null == result.cause() ? null : result.cause().getMessage(), flag);
        }
    });
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:22,代碼來源:Verticles.java

示例7: setUp

import io.vertx.core.Vertx; //導入依賴的package包/類
@Before
public void setUp(TestContext context) throws IOException {
    vertx = Vertx.vertx();

    // Pick an available and random
    ServerSocket socket = new ServerSocket(0);
    port = socket.getLocalPort();
    socket.close();

    DeploymentOptions options = new DeploymentOptions()
        .setConfig(new JsonObject()
            .put("HTTP_PORT", port)
            .put("url", "jdbc:hsqldb:mem:test?shutdown=true")
            .put("driver_class", "org.hsqldb.jdbcDriver")
        );
    vertx.deployVerticle(MyFirstVerticle.class.getName(), options, context.asyncAssertSuccess());
}
 
開發者ID:cescoffier,項目名稱:introduction-to-vert.x,代碼行數:18,代碼來源:MyFirstVerticleTest.java

示例8: hello8

import io.vertx.core.Vertx; //導入依賴的package包/類
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.rxjava.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		return body.body().toString();
	});
}
 
開發者ID:FroMage,項目名稱:redpipe,代碼行數:20,代碼來源:MyResource.java

示例9: main

import io.vertx.core.Vertx; //導入依賴的package包/類
public static void main(String [] args) throws IOException {
    Properties properties = loadProperties("config.properties");
    String messagingHost = properties.getProperty("service.hostname", "messaging.enmasse.svc");
    int messagingPort = Integer.parseInt(properties.getProperty("service.port", "5672"));
    String username = properties.getProperty("service.username", "test");
    String password = properties.getProperty("service.password", "test");

    String maxAddress = properties.getProperty("address.max", "max");
    String controlPrefix = properties.getProperty("address.control.prefix", "control");

    int minTemp = Integer.parseInt(properties.getProperty("control.temperature.min", "15"));
    int maxTemp = Integer.parseInt(properties.getProperty("control.temperature.max", "25"));

    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(new Thermostat(messagingHost, messagingPort, username, password, maxAddress, controlPrefix, minTemp, maxTemp));
}
 
開發者ID:EnMasseProject,項目名稱:enmasse-workshop,代碼行數:17,代碼來源:Thermostat.java

示例10: main

import io.vertx.core.Vertx; //導入依賴的package包/類
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());
            }
        });
    }
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:21,代碼來源:BitcoinAdjustedData.java

示例11: main

import io.vertx.core.Vertx; //導入依賴的package包/類
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());
            }
        });
    }
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:25,代碼來源:JSPercentilesDatasource.java

示例12: start

import io.vertx.core.Vertx; //導入依賴的package包/類
@Override
public void start() throws Exception {

    JsonObject config = Vertx.currentContext().config();
    DeploymentOptions opts = new DeploymentOptions().setConfig(config);
    DeploymentOptions chunkOpts = new DeploymentOptions().setConfig(config.copy().put(ADDRESS, "/queryChunk"))
            //.setInstances(config.getInteger(PARALLELISM))
            //.setWorker(true)
            ;

    vertx.deployVerticle("js:io/devcon5/metrics/demo6/AggregatePercentilesVerticle.js",chunkOpts, result -> {
        if (result.succeeded()) {
            LOG.info("JS Verticle successfully deployed {}", result.result());
        } else {
            LOG.error("Failed to deploy JS Verticle", result.cause());
        }
    });
    vertx.deployVerticle(SplitMergeTimeSeriesVerticle.class.getName(), opts);
    vertx.deployVerticle(AnnotationVerticle.class.getName(), opts);
    vertx.deployVerticle(LabelVerticle.class.getName(), opts);
    vertx.deployVerticle(HttpServerVerticle.class.getName(), opts);
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:23,代碼來源:JSPercentilesDatasource.java

示例13: VertxAsyncLogoutHandler

import io.vertx.core.Vertx; //導入依賴的package包/類
public VertxAsyncLogoutHandler(final Vertx vertx,
                               final Context context,
                               final AsyncConfig<Void, CommonProfile, VertxAsyncWebContext> config,
                               final LogoutHandlerOptions options) {
    DefaultAsyncLogoutLogic<Void, CommonProfile, VertxAsyncWebContext> defaultApplicationLogoutLogic = new DefaultAsyncLogoutLogic<>(config,
            httpActionAdapter,
            options.getDefaultUrl(),
            options.getLogoutUrlPattern(),
            options.isLocalLogout(),
            options.isDestroySession(),
            options.isCentralLogout());
    defaultApplicationLogoutLogic.setProfileManagerFactory(c -> new VertxAsyncProfileManager(c));
    this.logoutLogic = defaultApplicationLogoutLogic;
    this.config = config;
    this.asynchronousComputationAdapter = new VertxAsynchronousComputationAdapter(vertx, context);
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:17,代碼來源:VertxAsyncLogoutHandler.java

示例14: testRoundStrategy

import io.vertx.core.Vertx; //導入依賴的package包/類
@Test
public void testRoundStrategy() {
	Vertx vertx = Vertx.vertx();
	WebClient http = WebClient.create(vertx);
	App a = new App(vertx,http,"test");
	RoundNodeStrategy w = new RoundNodeStrategy();
	Node n1 = a.createDevNode("10.10.10.1",80,1);
	Node n2 = a.createDevNode("10.10.10.1",80,1);
	Node n3 = a.createDevNode("10.10.10.1",80,1);
	Node n4 = a.createDevNode("10.10.10.1",80,1);
	Node n5 = a.createDevNode("10.10.10.1",80,1);
	w.addNode(n1);
	w.addNode(n2);
	w.addNode(n3);
	w.addNode(n4);
	w.addNode(n5);
	
	
	for(int i=0; i<100 ;i++){
		System.out.println(w.getNode(null).toString());
	}
	
	
}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:25,代碼來源:TestNodeSelectStrategy.java

示例15: getChannel

import io.vertx.core.Vertx; //導入依賴的package包/類
/**
 * @param vertx  Vert.x instance
 * @param config configuration
 * @return ManagedChannel
 */
public static ManagedChannel getChannel(final Vertx vertx,
                                        final JsonObject config) {
    final String rpcHost = config.getString(Key.HOST);
    final Integer rpcPort = config.getInteger(Key.PORT);
    LOGGER.info(Info.CLIENT_RPC, rpcHost, String.valueOf(rpcPort));
    final VertxChannelBuilder builder =
            VertxChannelBuilder
                    .forAddress(vertx, rpcHost, rpcPort);
    Fn.safeSemi(null != config.getValue(Key.SSL), LOGGER,
            () -> {
                final JsonObject sslConfig = config.getJsonObject(Key.SSL);
                if (null != sslConfig && !sslConfig.isEmpty()) {
                    final Object type = sslConfig.getValue("type");
                    final CertType certType = null == type ?
                            CertType.PEM : Types.fromStr(CertType.class, type.toString());
                    final TrustPipe<JsonObject> pipe = TrustPipe.get(certType);
                    // Enable SSL
                    builder.useSsl(pipe.parse(sslConfig));
                } else {
                    builder.usePlaintext(true);
                }
            });
    return builder.build();
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:30,代碼來源:RpcSslTool.java


注:本文中的io.vertx.core.Vertx類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。