Guest User

Untitled

a guest
Jul 13th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. public class MongoDaoVerticle extends AbstractVerticle {
  2.  
  3.     private static final Logger logger = LoggerFactory.getLogger(MongoDaoVerticle.class);
  4.  
  5.     MongoClient platformMongoClient;
  6.  
  7.     private static final String LAST_SUCCESSFULL_EXECUTION_REQUEST = "{\"$and\": [ {\"executionId\" : \"%s\"}  ," +
  8.             " { \"$where\" : \"function() { " +
  9.             "                   return this.executions.every( function(operation) {" +
  10.             "                           return (operation.read.executionStatus === 'SUCCESS' " +
  11.             "                                   && operation.process.executionStatus === 'SUCCESS' " +
  12.             "                                   && operation.write.executionStatus === 'SUCCESS') " +
  13.             "                           }) " +
  14.             "               }\"" +
  15.             " } " +
  16.             "] " +
  17.             "}";
  18.  
  19.     @Override
  20.     public void start() throws Exception {
  21.         JsonObject rootConfig = config();
  22.         JsonObject platformConfig = rootConfig.getJsonObject("mongo-platform");
  23.  
  24.         platformMongoClient = MongoClient.createShared(vertx, platformConfig, platformConfig.getString("pool_name"));
  25.  
  26.         vertx.eventBus().<JsonObject>consumer(EXECUTION_DAO_FIND_LAST_SUCCESSFUL, message -> {
  27.             String executionId = message.body().getString("executionId");
  28.  
  29.             FindOptions options = new FindOptions() {{
  30.                 setLimit(1);
  31.                 setSort(new JsonObject().put("creationDate", -1));
  32.             }};
  33.  
  34.             platformMongoClient.findWithOptions("executions", new JsonObject(String.format(LAST_SUCCESSFULL_EXECUTION_REQUEST, executionId)), options, event -> {
  35.                 if (event.failed()) {
  36.                     String errorMessage = "Find Error";
  37.                     logger.error(errorMessage, event.cause());
  38.                     message.fail(FIND_FAILURE, errorMessage);
  39.                 } else {
  40.                     message.reply(event.result().get(0));
  41.                 }
  42.             });
  43.         });
  44.  
  45.  
  46.     }
  47.  
  48.     @Override
  49.     public void stop() throws Exception {
  50.         platformMongoClient.close();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment