org.vertx.java.core.json.JsonArray类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(124)

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

JsonArray介绍

[英]Represents a JSON array
[中]表示JSON数组

代码示例

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

@SuppressWarnings("unchecked")
public JsonArray getArray(String fieldName) {
 List<Object> l = (List<Object>) map.get(fieldName);
 return l == null ? null : new JsonArray(l);
}

代码示例来源:origin: com.englishtown/vertx-mod-cassandra

protected void initSeeds(JsonArray seeds) {
  // Get array of IPs, default to localhost
  if (seeds == null || seeds.size() == 0) {
    this.seeds = DEFAULT_SEEDS;
    return;
  }
  this.seeds = new ArrayList<>();
  for (int i = 0; i < seeds.size(); i++) {
    this.seeds.add(seeds.<String>get(i));
  }
}

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

public JsonArray addElement(JsonElement value) {
 if (value.isArray()) {
  return addArray(value.asArray());
 }
 return addObject(value.asObject());
}

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

public JsonArray copy() {
 return new JsonArray(encode());
}

代码示例来源:origin: vert-x/mod-lang-php

JsonArray json = new JsonArray();
Iterator<Value> iter = array.getValueIterator(env);
while (iter.hasNext()) {
 if (value.isArray()) {
  if (PhpTypes.arrayIsAssoc(env, value)) {
   json.addObject(PhpTypes.arrayToJsonObject(env, value));
   json.addArray(PhpTypes.arrayToJsonArray(env, value));
  json.addBoolean(value.toBoolean());
  json.addNumber(value.toJavaDouble());
  json.addNumber(value.toInt());
  json.addString(value.toString());
  json.add(value.toJavaObject());

代码示例来源:origin: com.englishtown/vertx-mod-hk2

bootstrapNames = (JsonArray) field;
} else {
  bootstrapNames = new JsonArray().add((field == null ? BOOTSTRAP_BINDER_NAME : field));
for (int i = 0; i < bootstrapNames.size(); i++) {
  String bootstrapName = bootstrapNames.get(i);
  try {
    Class bootstrapClass = cl.loadClass(bootstrapName);

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

public void handle(HttpServerRequest req) {
  if (log.isTraceEnabled()) log.trace("In Info handler");
  req.response.headers().put("Content-Type", "application/json; charset=UTF-8");
  req.response.headers().put("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
  JsonObject json = new JsonObject();
  json.putBoolean("websocket", websocket);
  json.putBoolean("cookie_needed", config.getBoolean("insert_JSESSIONID"));
  json.putArray("origins", new JsonArray().add("*:*"));
  // Java ints are signed, so we need to use a long and add the offset so
  // the result is not negative
  json.putNumber("entropy", RAND_OFFSET + new Random().nextInt());
  setCORS(req);
  req.response.end(json.encode());
 }
};

代码示例来源:origin: com.englishtown/vertx-mod-cassandra

JsonArray arr = new JsonArray();
json.putArray("seeds", arr);
if (seeds != null) {
  for (String seed : seeds) {
    arr.addString(seed);

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

private void checkFailover(String failedNodeID, JsonObject theHAInfo) {
 try {
  JsonArray deployments = theHAInfo.getArray("mods");
  String group = theHAInfo.getString("group");
  String chosen = chooseHashedNode(group, failedNodeID.hashCode());
  if (chosen != null && chosen.equals(this.nodeID)) {
   if (deployments != null && deployments.size() > 0) {
    log.info("Node " + failedNodeID + " has failed. This node will deploy " + deployments.size() + " deployments from that node.");
    for (Object obj: deployments) {
     JsonObject app = (JsonObject)obj;
     processFailover(app);
    }
   }
   // Failover is complete! We can now remove the failed node from the cluster map
   clusterMap.remove(failedNodeID);
   callFailoverCompleteHandler(failedNodeID, theHAInfo, true);
  }
 } catch (Throwable t) {
  log.error("Failed to handle failover", t);
  callFailoverCompleteHandler(failedNodeID, theHAInfo, false);
 }
}

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

private void addToHA(String deploymentID, String moduleName, JsonObject conf, int instances) {
 JsonObject moduleConf = new JsonObject().putString("dep_id", deploymentID);
 moduleConf.putString("module_name", moduleName);
 if (conf != null) {
  moduleConf.putObject("conf", conf);
 }
 moduleConf.putNumber("instances", instances);
 synchronized (haMods) {
  haMods.addObject(moduleConf);
 }
 clusterMap.put(nodeID, haInfo.encode());
}

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

protected int getBodyLength() {
 if (body == null) {
  return 1;
 } else {
  String strJson = body.encode();
  encoded = strJson.getBytes(CharsetUtil.UTF_8);
  return 1 + 4 + encoded.length;
 }
}

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

public void removeFromHA(String depID) {
 synchronized (haMods) {
  Iterator<Object> iter = haMods.iterator();
  while (iter.hasNext()) {
   Object obj = iter.next();
   JsonObject mod = (JsonObject)obj;
   if (mod.getString("dep_id").equals(depID)) {
    iter.remove();
   }
  }
 }
 clusterMap.put(nodeID, haInfo.encode());
}

代码示例来源:origin: OlivierCroisier/LP4J

/**
 * Constructor.
 *
 * @param httpPort The HTTP port on which the emulator should run.
 */
public EmulatorLaunchpad(int httpPort) {
  vertx = VertxFactory.newVertx();
  // Static files
  HttpServer httpServer = vertx.createHttpServer();
  httpServer.requestHandler(new WebResourceHandler());
  // Eventbus bridge
  JsonObject bridgeConfig = new JsonObject().putString("prefix", EVENTBUS_ADDRESS);
  JsonArray credentialsPermitAll = new JsonArray().add(new JsonObject());
  vertx.createSockJSServer(httpServer).bridge(bridgeConfig, credentialsPermitAll, credentialsPermitAll);
  vertx.eventBus().registerLocalHandler(EVENTBUS_SERVER_HANDLER_ID, eventBusHandler);
  System.out.println("Launchpad emulator is ready on http://localhost:" + httpPort + "/");
  httpServer.listen(httpPort);
}

代码示例来源:origin: net.kuujo/xync

private void checkFailover(String failedNodeID, JsonObject theHAInfo) {
 try {
  JsonArray deployments = theHAInfo.getArray("deployments");
  String group = theHAInfo.getString("group");
  String chosen = chooseHashedNode(group, failedNodeID.hashCode());
  if (chosen != null && chosen.equals(this.node)) {
   log.info("Node " + failedNodeID + " has failed. This node will deploy " + deployments.size() + " deployments from that node.");
   if (deployments != null) {
    for (Object obj: deployments) {
     JsonObject deployment = (JsonObject)obj;
     if (deployment.getBoolean("ha", false)) {
      processFailover(deployment);
     }
    }
   }
   // Failover is complete! We can now remove the failed node from the cluster map
   clusterMap.remove(failedNodeID);
  }
 } catch (Throwable t) {
  log.error("Failed to handle failover", t);
 }
}

代码示例来源:origin: net.kuujo/xync

private void addVerticleToHA(String deploymentID, String internalID, String main, JsonObject conf, int instances, boolean ha) {
 JsonObject info = new JsonObject()
   .putString("id", deploymentID)
   .putString("type", "verticle")
   .putString("group", group)
   .putString("main", main)
   .putObject("config", conf)
   .putNumber("instances", instances)
   .putBoolean("ha", ha);
 synchronized (haInfo) {
  deployments.addObject(info);
  deploymentIDs.putString(internalID, deploymentID);
  internalIDs.putString(deploymentID, internalID);
 }
 clusterMap.put(node, haInfo.encode());
}

代码示例来源:origin: net.kuujo/vertigo-utils

@Override
public <T> T deserializeObject(JsonArray json, TypeReference<T> type) {
 try {
  return mapper.readValue(json.encode(), type);
 } catch (Exception e) {
  throw new DeserializationException(e.getMessage());
 }
}

代码示例来源:origin: vert-x/mod-lang-php

/**
 * Converts a JSON array to a PHP array.
 *
 * @param env The Quercus environment.
 * @param json A Vert.x json array.
 * @return A populated PHP array.
 */
public static ArrayValue arrayFromJson(Env env, JsonArray json) {
 ArrayValue result = new ArrayValueImpl();
 Iterator<Object> iter = json.iterator();
 while (iter.hasNext()) {
  Object value = iter.next();
  if (value instanceof JsonObject) {
   result.put(PhpTypes.arrayFromJson(env, (JsonObject) value));
  }
  else if (value instanceof JsonArray) {
   result.put(PhpTypes.arrayFromJson(env, (JsonArray) value));
  }
  else {
   result.put(env.wrapJava(iter.next()));
  }
 }
 return result;
}

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

@SuppressWarnings("unchecked")
public Object getField(String fieldName) {
 Object obj = map.get(fieldName);
 if (obj instanceof Map) {
  return new JsonObject((Map<String, Object>) obj);
 } else if (obj instanceof List) {
  return new JsonArray((List<Object>) obj);
 } else {
  return obj;
 }
}

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

JsonArray disabled = new JsonArray();
disabled.add(Transport.WEBSOCKET.toString());
installApp(new JsonObject().putString("prefix", "/disabled_websocket_echo")
              .putNumber("max_bytes_streaming", 4096)

代码示例来源:origin: com.englishtown/vertx-mod-jersey

JsonArray resources = config.getArray(CONFIG_RESOURCES, null);
if (resources == null || resources.size() == 0) {
  throw new RuntimeException("At least one resource package name must be specified in the config " +
      CONFIG_RESOURCES);
String[] resourceArr = new String[resources.size()];
for (int i = 0; i < resources.size(); i++) {
  resourceArr[i] = resources.get(i);
if (features != null && features.size() > 0) {
  for (int i = 0; i < features.size(); i++) {
    try {
      Class<?> clazz = cl.loadClass(features.get(i));
      rc.register(clazz);
    } catch (ClassNotFoundException e) {
if (binders != null && binders.size() > 0) {
  for (int i = 0; i < binders.size(); i++) {
    try {
      Class<?> clazz = cl.loadClass(binders.get(i));
      rc.register(clazz.newInstance());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {

相关文章