All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nstream.adapter.mongodb.MongoDbIngressSettings Maven / Gradle / Ivy

// Copyright 2015-2024 Nstream, inc.
//
// Licensed under the Redis Source Available License 2.0 (RSALv2) Agreement;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://redis.com/legal/rsalv2-agreement/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nstream.adapter.mongodb;

import nstream.adapter.common.AdapterSettings;
import swim.codec.Format;
import swim.codec.Output;
import swim.structure.Form;
import swim.structure.Kind;
import swim.structure.Tag;
import swim.structure.Value;

/**
 * Provides a concrete class to parse and store agent configuration
 * used for MongoDB ingress by various ingesting agents and patches.
 *
 * @see MongoDbIngestingAgent
 * @see MongoDbIngestingPatch
 * @see MongoDbChangeStreamIngestingAgent
 * @see MongoDbChangeStreamIngestingPatch
 */
@Tag("mongoDbIngressSettings")
public class MongoDbIngressSettings implements AdapterSettings {

  private final long firstFetchDelayMillis;
  private final long fetchIntervalMillis;
  private final String clientProvisionName;
  private final String database;
  private final String collection;
  private final String query;
  private final String projection;
  private final Value relaySchema;

  public MongoDbIngressSettings(long firstFetchDelayMillis, long fetchIntervalMillis,
                                String clientProvisionName, String database,
                                String collection, String query,
                                String projection, Value relaySchema) {
    this.firstFetchDelayMillis = firstFetchDelayMillis;
    this.fetchIntervalMillis = fetchIntervalMillis;
    this.clientProvisionName = clientProvisionName;
    this.database = database;
    this.collection = collection;
    this.query = query;
    this.projection = projection;
    this.relaySchema = relaySchema;
  }

  public MongoDbIngressSettings() {
    this(2000L, 120000L, null, null, null, null, null, null);
  }

  /**
   * Initial delay on agent load before starting ingestion.
   *
   * @return the delay in ms
   */
  public long firstFetchDelayMillis() {
    return this.firstFetchDelayMillis;
  }

  /**
   * Interval between fetches/polls in milliseconds.
   *
   * @return the interval in ms
   */
  public long fetchIntervalMillis() {
    return this.fetchIntervalMillis;
  }

  /**
   * Name of MongoDB client provision to be used for ingestion.
   *
   * @return the client provision name
   */
  public String clientProvisionName() {
    return this.clientProvisionName;
  }

  /**
   * The MongoDB database name to be polled/streamed.
   *
   * @return the database name
   */
  public String database() {
    return this.database;
  }

  /**
   * The MongoDB collection name to be polled/streamed.
   *
   * @return the collection name
   */
  public String collection() {
    return this.collection;
  }

  /**
   * The query filter for the find operation on the collection.
   * In JSON string format.
   *
   * @return the query filter
   */
  public String query() {
    return this.query;
  }

  /**
   * The projection for the find operation on the collection.
   * In JSON string format.
   *
   * @return the projection
   */
  public String projection() {
    return this.projection;
  }

  /**
   * Relay schema definition.
   *
   * @return the relay schema
   */
  public Value relaySchema() {
    return this.relaySchema;
  }

  @Override
  public  Output debug(Output output) {
    output = output.write("MongoDbIngressSettings").write('.').write("of").write('(').write(')')
        .write('.').write("firstFetchDelay").write('(').debug(this.firstFetchDelayMillis).write(')')
        .write('.').write("fetchInterval").write('(').debug(this.fetchIntervalMillis).write(')')
        .write('.').write("clientProvisionName").write('(').debug(this.clientProvisionName).write(')')
        .write('.').write("database").write('(').debug(this.database).write(')')
        .write('.').write("collection").write('(').debug(this.collection).write(')')
        .write('.').write("query").write('(').debug(this.query).write(')')
        .write('.').write("projection").write('(').debug(this.projection).write(')')
        .write('.').write("relaySchema").write('(').debug(this.relaySchema).write(')');

    return output;
  }

  @Override
  public String toString() {
    return Format.debug(this);
  }

  @Kind
  private static Form form;

  private static final MongoDbIngressSettings DEFAULT = new MongoDbIngressSettings();

  public static Form form() {
    if (MongoDbIngressSettings.form == null) {
      MongoDbIngressSettings.form = Form.forClass(MongoDbIngressSettings.class);
    }
    return MongoDbIngressSettings.form;
  }

  public static MongoDbIngressSettings defaultSettings() {
    return MongoDbIngressSettings.DEFAULT;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy