Пример #1
0
  public <T extends Aggregate, R extends SourcedEvent> Observable<T> load(
      final JsonObject query, final Class<T> aggregateClass, final R event) {
    final String id = query.encode();
    if (aggregateCache.containsKey(id)) {
      final Aggregate aggregate = aggregateCache.get(id);
      aggregate.apply(event);
      //noinspection unchecked
      return Observable.just((T) aggregate);
    }

    return loadFromMongo(aggregateClass, query);
  }
Пример #2
0
 // Add some information on a deployment in the cluster so other nodes know about it
 private void addToHA(
     String deploymentID, String verticleName, DeploymentOptions deploymentOptions) {
   String encoded;
   synchronized (haInfo) {
     JsonObject verticleConf = new JsonObject().put("dep_id", deploymentID);
     verticleConf.put("verticle_name", verticleName);
     verticleConf.put("options", deploymentOptions.toJson());
     JsonArray haMods = haInfo.getJsonArray("verticles");
     haMods.add(verticleConf);
     encoded = haInfo.encode();
     clusterMap.put(nodeID, encoded);
   }
 }
Пример #3
0
  @RouteMapping(value = "/:id", method = RouteMethod.GET)
  public Handler<RoutingContext> fetch() {
    return ctx -> {
      String id = ctx.request().getParam("id");
      if (StringUtils.isBlank(id)) {
        LOGGER.error("ID is blank");
        JsonObject error = new JsonObject();
        error.put("error", "ID should not be blank");
        ctx.response().setStatusCode(205).end(error.encode());
      }

      JDBCClient client = AppUtil.getJdbcClient(Vertx.vertx());
      client.getConnection(
          conn -> {
            if (conn.failed()) {
              LOGGER.error(conn.cause().getMessage(), conn.cause());
              ctx.fail(400);
            }

            SQLUtil.query(
                conn.result(),
                "select id, title, description from item where id = ?",
                new JsonArray().add(Integer.valueOf(id)),
                rs -> {
                  SQLUtil.close(conn.result());
                  if (rs.getRows().size() == 1) {
                    ctx.response().end(rs.getRows().get(0).encode());
                  } else {
                    JsonObject error = new JsonObject();
                    error.put("error", "Record not found");
                    ctx.response().setStatusCode(205).end(error.encode());
                  }
                });
          });
    };
  }
Пример #4
0
 // Remove the information on the deployment from the cluster - this is called when an HA module is
 // undeployed
 public void removeFromHA(String depID) {
   Deployment dep = deploymentManager.getDeployment(depID);
   if (dep == null || !dep.deploymentOptions().isHa()) {
     return;
   }
   synchronized (haInfo) {
     JsonArray haMods = haInfo.getJsonArray("verticles");
     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());
   }
 }
Пример #5
0
  public HAManager(
      VertxInternal vertx,
      DeploymentManager deploymentManager,
      ClusterManager clusterManager,
      int quorumSize,
      String group,
      boolean enabled) {
    this.vertx = vertx;
    this.deploymentManager = deploymentManager;
    this.clusterManager = clusterManager;
    this.quorumSize = enabled ? quorumSize : 0;
    this.group = enabled ? group : "__DISABLED__";
    this.enabled = enabled;
    this.haInfo = new JsonObject();
    haInfo.put("verticles", new JsonArray());
    haInfo.put("group", this.group);
    this.clusterMap = clusterManager.getSyncMap(CLUSTER_MAP_NAME);
    this.nodeID = clusterManager.getNodeID();
    clusterManager.nodeListener(
        new NodeListener() {
          @Override
          public void nodeAdded(String nodeID) {
            HAManager.this.nodeAdded(nodeID);
          }

          @Override
          public void nodeLeft(String leftNodeID) {
            HAManager.this.nodeLeft(leftNodeID);
          }
        });
    clusterMap.put(nodeID, haInfo.encode());
    quorumTimerID = vertx.setPeriodic(QUORUM_CHECK_PERIOD, tid -> checkHADeployments());
    // Call check quorum to compute whether we have an initial quorum
    synchronized (this) {
      checkQuorum();
    }
  }
Пример #6
0
 @CodeTranslate
 public void encode() throws Exception {
   JsonObject obj = new JsonObject().put("foo", "foo_value");
   JsonTest.o = obj.encode();
 }
Пример #7
0
 public void addDataToAHAInfo(String key, JsonObject value) {
   synchronized (haInfo) {
     haInfo.put(key, value);
     clusterMap.put(nodeID, haInfo.encode());
   }
 }