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

org.smallmind.claxon.registry.ClaxonConfiguration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2007 through 2024 David Berkman
 *
 * This file is part of the SmallMind Code Project.
 *
 * The SmallMind Code Project is free software, you can redistribute
 * it and/or modify it under either, at your discretion...
 *
 * 1) The terms of GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * ...or...
 *
 * 2) The terms of the Apache License, Version 2.0.
 *
 * The SmallMind Code Project is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License or Apache License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * and the Apache License along with the SmallMind Code Project. If not, see
 *  or .
 *
 * Additional permission under the GNU Affero GPL version 3 section 7
 * ------------------------------------------------------------------
 * If you modify this Program, or any covered work, by linking or
 * combining it with other code, such other code is not for that reason
 * alone subject to any of the requirements of the GNU Affero GPL
 * version 3.
 */
package org.smallmind.claxon.registry;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.smallmind.nutsnbolts.time.Stint;

public class ClaxonConfiguration {

  private Clock clock = SystemClock.instance();
  private Stint collectionStint = new Stint(2, TimeUnit.SECONDS);
  private Tag[] registryTags = new Tag[0];
  private HashMap meterTags;
  private NamingStrategy namingStrategy = new ImpliedNamingStrategy();

  public ClaxonConfiguration () {

  }

  public ClaxonConfiguration (Clock clock, Stint collectionStint, Tag[] registryTags, NamingStrategy namingStrategy) {

    if (clock != null) {
      this.clock = clock;
    }
    if (collectionStint != null) {
      this.collectionStint = collectionStint;
    }
    if (registryTags != null) {
      this.registryTags = registryTags;
    }
    if (namingStrategy != null) {
      this.namingStrategy = namingStrategy;
    }
  }

  public Clock getClock () {

    return clock;
  }

  public void setClock (Clock clock) {

    this.clock = clock;
  }

  public Stint getCollectionStint () {

    return collectionStint;
  }

  public void setCollectionStint (Stint collectionStint) {

    this.collectionStint = collectionStint;
  }

  public Tag[] getRegistryTags () {

    return registryTags;
  }

  public void setRegistryTags (Tag[] registryTags) {

    this.registryTags = registryTags;
  }

  public NamingStrategy getNamingStrategy () {

    return namingStrategy;
  }

  public void setNamingStrategy (NamingStrategy namingStrategy) {

    this.namingStrategy = namingStrategy;
  }

  public void setMeterTags (HashMap meterTags) {

    this.meterTags = meterTags;
  }

  public Tag[] forMeter (String name) {

    return (meterTags == null) ? null : meterTags.get(name);
  }

  public Tag[] calculateTags (String name, Tag... instanceTags) {

    Tag[] meterTags = forMeter(name);
    int tagCount = ((registryTags == null) ? 0 : registryTags.length) + ((meterTags == null) ? 0 : meterTags.length) + ((instanceTags == null) ? 0 : instanceTags.length);

    if (tagCount == 0) {

      return null;
    } else {

      Tag[] mergedTags = new Tag[tagCount];
      int index = 0;

      if ((registryTags != null) && (registryTags.length > 0)) {
        System.arraycopy(registryTags, 0, mergedTags, 0, registryTags.length);
        index += registryTags.length;
      }
      if ((meterTags != null) && (meterTags.length > 0)) {
        System.arraycopy(meterTags, 0, mergedTags, index, meterTags.length);
        index += meterTags.length;
      }
      if ((instanceTags != null) && (instanceTags.length > 0)) {
        System.arraycopy(instanceTags, 0, mergedTags, index, instanceTags.length);
      }

      return mergedTags;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy