Example #1
0
    /**
     * Gets the.
     *
     * @param params the params
     * @return the mongo state
     */
    public MongoState get(final ObjectNode params) {

      final MongoStateConfig config = MongoStateConfig.decorate(params);
      final String id = config.getId();

      MongoState result = null;
      try {
        synchronized (this) {
          result = getCollection().findOne("{_id: #}", id).as(MongoState.class);
          if (result == null) {
            result = new MongoState(id, this, params);
            getCollection().insert(result);
          } else {
            result.setService(this);
          }
        }
        result.setCollection(getCollection());
      } catch (final Exception e) {
        LOG.log(Level.WARNING, "get error", e);
      }
      return result;
    }
Example #2
0
  /**
   * Gets the instance by params.
   *
   * @param params the params
   * @return the instance by params
   */
  public MongoStateProvider getInstanceByParams(final ObjectNode params) {
    final MongoStateConfig config = MongoStateConfig.decorate(params);
    final String key = config.getKey();

    if (instances.containsKey(key)) {
      return instances.get(key);
    } else {
      synchronized (instances) {
        if (!instances.containsKey(key)) {
          try {

            final MongoStateProvider result = new MongoStateProvider(params);
            if (result != null) {
              instances.put(key, result);
            }
          } catch (final UnknownHostException e) {
            LOG.log(Level.WARNING, "Couldn't init MongoStateService", e);
          }
        }
        return instances.get(key);
      }
    }
  }
Example #3
0
    /**
     * Instantiates a new mongo state service.
     *
     * @param params the params
     * @throws UnknownHostException the unknown host exception
     */
    public MongoStateProvider(final ObjectNode params) throws UnknownHostException {

      final MongoStateConfig config = MongoStateConfig.decorate(params);

      // initialization of client & jongo
      final MongoClient client = createClient(config.getHost(), config.getPort());
      jongo = new Jongo(client.getDB(config.getDatabase()));
      collectionName = config.getCollection();

      jongo.runCommand("{collMod: '" + collectionName + "', usePowerOf2Sizes : true }");
    }