io.vertx.core.Context.config()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中io.vertx.core.Context.config()方法的一些代码示例,展示了Context.config()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.config()方法的具体详情如下:
包路径:io.vertx.core.Context
类名称:Context
方法名:config

Context.config介绍

[英]If the context is associated with a Verticle deployment, this returns the configuration that was specified when the verticle was deployed.
[中]如果上下文与垂直部署关联,则返回垂直部署时指定的配置。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Get the configuration of the verticle.
 * <p>
 * This can be specified when the verticle is deployed.
 * @return the configuration
 */
public JsonObject config() {
 return context.config();
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
public void start() throws Exception {
 JsonObject config = Vertx.currentContext().config();

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {
  // If a config file is set, read the host and port.
  String host = Vertx.currentContext().config().getString("host");
  if (host == null) {
   host = "127.0.0.1";
  }

  // Create the redis client
  final RedisClient client = RedisClient.create(vertx,
    new RedisOptions().setHost(host));

  client.set("key", "value", r -> {
   if (r.succeeded()) {
    System.out.println("key stored");
    client.get("key", s -> {
     System.out.println("Retrieved value: " + s.result());
    });
   } else {
    System.out.println("Connection or Operation Failed " + r.cause());
   }
  });
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Override
 public void start() throws Exception {
  processArgs = context.processArgs();
  conf = context.config();
//    if (Thread.currentThread().getContextClassLoader() != getClass().getClassLoader()) {
//      throw new IllegalStateException("Wrong tccl!");
//    }
  vertx.eventBus().send("testcounts",
   new JsonObject().put("deploymentID", context.deploymentID()).put("count", instanceCount.incrementAndGet()));
 }

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public void start() throws Exception {
 switch (startAction) {
  case THROW_EXCEPTION:
   throw new Exception("FooBar!");
  case THROW_ERROR:
   throw new Error("FooBar!");
  default:
   startCalled = true;
   startContext = Vertx.currentContext();
 }
 deploymentID = Vertx.currentContext().deploymentID();
 config = context.config();
}

代码示例来源:origin: io.vertx/vertx-core

/**
 * Get the configuration of the verticle.
 * <p>
 * This can be specified when the verticle is deployed.
 * @return the configuration
 */
public JsonObject config() {
 return context.config();
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void init(Vertx vertx, Context context) {
 super.init(vertx, context);
 this.endpoint = (Endpoint) context.config().getValue(AbstractTransport.ENDPOINT_KEY);
 this.endpointObject = (URIEndpointObject) this.endpoint.getAddress();
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void init(Vertx vertx, Context context) {
 super.init(vertx, context);
 this.endpoint = (Endpoint) context.config().getValue(AbstractTransport.ENDPOINT_KEY);
 this.endpointObject = (URIEndpointObject) endpoint.getAddress();
}

代码示例来源:origin: io.vertx/vertx-core

@Override
 public void start() throws Exception {
  processArgs = context.processArgs();
  conf = context.config();
//    if (Thread.currentThread().getContextClassLoader() != getClass().getClassLoader()) {
//      throw new IllegalStateException("Wrong tccl!");
//    }
  vertx.eventBus().send("testcounts",
   new JsonObject().put("deploymentID", context.deploymentID()).put("count", instanceCount.incrementAndGet()));
 }

代码示例来源:origin: io.vertx/vertx-core

@Override
public void start() throws Exception {
 switch (startAction) {
  case THROW_EXCEPTION:
   throw new Exception("FooBar!");
  case THROW_ERROR:
   throw new Error("FooBar!");
  default:
   startCalled = true;
   startContext = Vertx.currentContext();
 }
 deploymentID = Vertx.currentContext().deploymentID();
 config = context.config();
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * If the context is associated with a Verticle deployment, this returns the configuration that was specified when
 * the verticle was deployed.
 * @return the configuration of the deployment or null if not a Verticle deployment
 */
public JsonObject config() { 
 JsonObject ret = delegate.config();
 return ret;
}

代码示例来源:origin: ef-labs/vertx-jersey

@Inject
public JsonConfigObjectMapperConfigurator(Vertx vertx) {
  config = vertx.getOrCreateContext().config();
  config = config.getJsonObject("jersey", config).getJsonObject("jackson", config);
}

代码示例来源:origin: org.apache.servicecomb/transport-rest-vertx

@Override
public void init(Vertx vertx, Context context) {
 super.init(vertx, context);
 this.endpoint = (Endpoint) context.config().getValue(AbstractTransport.ENDPOINT_KEY);
 this.endpointObject = (URIEndpointObject) endpoint.getAddress();
}

代码示例来源:origin: georocket/georocket

private void configureVertx(Vertx vertx) {
 JsonObject config = vertx.getOrCreateContext().config();
 // prevent exception -> http://stackoverflow.com/questions/19840056/failed-to-detect-a-valid-hadoop-home-directory
 System.setProperty("hadoop.home.dir", "/");
 config.put(ConfigConstants.STORAGE_HDFS_PATH, hdfsLocalRoot);
 config.put(ConfigConstants.STORAGE_HDFS_DEFAULT_FS, hdfsAdress);
}

代码示例来源:origin: org.apache.servicecomb/transport-highway

@Override
public void init(Vertx vertx, Context context) {
 super.init(vertx, context);
 this.endpoint = (Endpoint) context.config().getValue(AbstractTransport.ENDPOINT_KEY);
 this.endpointObject = (URIEndpointObject) this.endpoint.getAddress();
}

代码示例来源:origin: ef-labs/vertx-cassandra

@Before
public void setUp() throws Exception {
  JsonObject baseConfig = new JsonObject().put("cassandra", config);
  when(context.config()).thenReturn(baseConfig);
  when(vertx.getOrCreateContext()).thenReturn(context);
}

代码示例来源:origin: io.vertx/vertx-service-factory

@Override
public void start() throws Exception {
 JsonObject conf = Vertx.currentContext().config();
 vertx.eventBus().publish("moduleStarted", conf.getString("foo").equals("wibble") &&
              conf.getString("quux").equals("blah") && conf.getString("socks").equals("eeek"));
}

代码示例来源:origin: io.vertx/vertx-shell

@Test
public void testDeployWithOptionsAsJsonConfig(TestContext context) {
 String cmd =
  "verticle-deploy io.vertx.ext.shell.command.base.DeployVerticleTest$SomeVerticle '{\"config\":{\"ok\":true}}'";
 String result = testDeployCmd(context, cmd);
 context.assertNotNull(ctx.get());
 context.assertEquals(result, "Deployed " + ctx.get().deploymentID());
 context.assertEquals(1, ctx.get().getInstanceCount());
 context.assertNotNull(ctx.get().config());
 context.assertTrue(ctx.get().config().containsKey("ok"));
 context.assertEquals(true, ctx.get().config().getBoolean("ok"));
}

代码示例来源:origin: amoAHCP/vxms

public static void init(final Future<Void> startFuture, AbstractVerticle registrationObject,
  VxmsRoutes... routes) {
 // TODO to be used for build in REST and others
 final Vertx vertx = registrationObject.getVertx();
 final JsonObject config = vertx.getOrCreateContext().config();
 vertx.eventBus()
   .consumer(ConfigurationUtil.getServiceName(config, registrationObject.getClass()) + "-info",
     VxmsEndpoint::info);
 initEndpoint(startFuture, registrationObject, new VxmsShared(vertx, new LocalData(vertx)),
   routes);
}

代码示例来源:origin: io.vertx/vertx-kafka-client

@Override
 public void start(Future<Void> startFuture) throws Exception {
  Properties config = new Properties();
  config.putAll(context.config().getMap());
  KafkaProducer<String, String> producer = KafkaProducer.createShared(vertx, "the-name", config);
  producer.write(KafkaProducerRecord.create("the_topic", "the_value"), ar -> startFuture.handle(ar.map((Void) null)));
 }
}

相关文章