<commit_before>package org.onyxplatform.api.java;

import java.util.UUID;

import clojure.lang.IPersistentMap;
import clojure.lang.PersistentHashMap;
import clojure.lang.PersistentVector;

import org.onyxplatform.api.java.utils.AsyncCatalog;
import org.onyxplatform.api.java.utils.AsyncLifecycles;
import org.onyxplatform.api.java.utils.MapFns;
import org.onyxplatform.api.java.utils.Timbre;


/**
 * High level functionality and general utilities for environment control,
 * such as peer configuration and environment configuration management, as
 * well as job control (starting, stopping, waiting), and garbage collection.
 * OnyxEnv should be used as an API utility/convenience class, that holds
 * an OnyxEnv object for use in running jobs.
 *
 * **Note** OnyxEnvs contain both EnvConfiguration and PeerConfiguration
 * objects, an OnyxEnv should not be confused with an EnvConfiguration.
 */
public class OnyxEnv {

	protected IPersistentMap onyxEnvConfig;

	protected TaskScheduler taskScheduler;
	protected EnvConfiguration envConfig;
	protected PeerConfiguration peerConfig;

	protected Object tenancyId;

	protected int virtualPeerCount;
	protected Object onyxEnv;
	protected Object peerGroup;
	protected Object virtualPeers;


	/**
	 * Constructs a new OnyxEnv object based on a string representing a path
	 * to an EDN file (that contains a map specifying environment conditions
	 * with keyword value pairs).
	 * @param  onyxEnvConfig (string) path to the EDN file containing environment spec
	 */
	public OnyxEnv(String onyxEnvConfig) {
		OnyxMap config = MapFns.fromResources(onyxEnvConfig);
		applySetupMap(config.toMap());
	}

	/**
	 * Constructs a new OnyxEnv object based on a string representing a path
	 * to an EDN file (that contains a map specifying environment conditions
	 * with keyword value pairs), and a boolean for convenience in automatically
	 * starting the environment upon creation.
	 * @param  onyxEnvConfig (string) path to the EDN file containing environment spec
	 * @param  start         boolean specifies whether the environment should start
	 */
	public OnyxEnv(String onyxEnvConfig, boolean start) {
		this(onyxEnvConfig);
		if (start) {
			startEnv();
		}
	}

	/**
	 * Constructs a new OnyxEnv object directly from a setup map of type IPersistentMap.
	 * The setupMap should contain keyword value pairs directing how the environment
	 * should be constructed.
	 * @param  setupMap      a map containing keywords and values describing the environment
	 * @return                new OnyxEnv object
	 */
	public OnyxEnv applySetupMap(IPersistentMap setupMap){

		if( (boolean) MapFns.get(setupMap, "generateTenancyId") ) {
			generateTenancyId();
		}

		setTaskScheduler(new TaskScheduler((String) MapFns.get(setupMap, "taskScheduler")));
		setVirtualPeerCount(((Long) MapFns.get(setupMap, "virtualPeerCount")).intValue());
		loadEnvConfig((String) MapFns.get(setupMap, "envEdn"));
		loadPeerConfig((String) MapFns.get(setupMap, "peerEdn"));
		configureLog((String) MapFns.get(setupMap, "logEdn"));
		return this;
	}

	/**
	 * Convenience function for generating a unique UUID automatically. The
	 * id, called a tenancyId, is used to track Environment and Peer Configurations
	 * across job tasks. This method acts on an existing OnyxEnv object.
	 * @return the updated OnyxEnv object
	 */
	public OnyxEnv generateTenancyId(){
		tenancyId = UUID.randomUUID();
		System.out.println("Tenancy ID set to: " + tenancyId);
		return this;
	}
<commit_msg>Made use of timbre logging optional in OnyxEnv<commit_after>package org.onyxplatform.api.java;

import java.util.UUID;

import clojure.lang.IPersistentMap;
import clojure.lang.PersistentHashMap;
import clojure.lang.PersistentVector;

import org.onyxplatform.api.java.utils.AsyncCatalog;
import org.onyxplatform.api.java.utils.AsyncLifecycles;
import org.onyxplatform.api.java.utils.MapFns;
import org.onyxplatform.api.java.utils.Timbre;


/**
 * High level functionality and general utilities for environment control,
 * such as peer configuration and environment configuration management, as
 * well as job control (starting, stopping, waiting), and garbage collection.
 * OnyxEnv should be used as an API utility/convenience class, that holds
 * an OnyxEnv object for use in running jobs.
 *
 * **Note** OnyxEnvs contain both EnvConfiguration and PeerConfiguration
 * objects, an OnyxEnv should not be confused with an EnvConfiguration.
 */
public class OnyxEnv {

	protected IPersistentMap onyxEnvConfig;

	protected TaskScheduler taskScheduler;
	protected EnvConfiguration envConfig;
	protected PeerConfiguration peerConfig;

	protected Object tenancyId;

	protected int virtualPeerCount;
	protected Object onyxEnv;
	protected Object peerGroup;
	protected Object virtualPeers;


	/**
	 * Constructs a new OnyxEnv object based on a string representing a path
	 * to an EDN file (that contains a map specifying environment conditions
	 * with keyword value pairs).
	 * @param  onyxEnvConfig (string) path to the EDN file containing environment spec
	 */
	public OnyxEnv(String onyxEnvConfig) {
		OnyxMap config = MapFns.fromResources(onyxEnvConfig);
		applySetupMap(config.toMap());
	}

	/**
	 * Constructs a new OnyxEnv object based on a string representing a path
	 * to an EDN file (that contains a map specifying environment conditions
	 * with keyword value pairs), and a boolean for convenience in automatically
	 * starting the environment upon creation.
	 * @param  onyxEnvConfig (string) path to the EDN file containing environment spec
	 * @param  start         boolean specifies whether the environment should start
	 */
	public OnyxEnv(String onyxEnvConfig, boolean start) {
		this(onyxEnvConfig);
		if (start) {
			startEnv();
		}
	}

	/**
	 * Constructs a new OnyxEnv object directly from a setup map of type IPersistentMap.
	 * The setupMap should contain keyword value pairs directing how the environment
	 * should be constructed.
	 * @param  setupMap      a map containing keywords and values describing the environment
	 * @return                new OnyxEnv object
	 */
	public OnyxEnv applySetupMap(IPersistentMap setupMap){

		if( (boolean) MapFns.get(setupMap, "generateTenancyId") ) {
			generateTenancyId();
		}

		setTaskScheduler(new TaskScheduler((String) MapFns.get(setupMap, "taskScheduler")));
		setVirtualPeerCount(((Long) MapFns.get(setupMap, "virtualPeerCount")).intValue());
		loadEnvConfig((String) MapFns.get(setupMap, "envEdn"));
		loadPeerConfig((String) MapFns.get(setupMap, "peerEdn"));
		String logEdn = (String) MapFns.get(setupMap, "logEdn");

		// Don't force people to use logging
		if (null != logEdn) {
			configureLog(logEdn);
		}

		return this;
	}

	/**
	 * Convenience function for generating a unique UUID automatically. The
	 * id, called a tenancyId, is used to track Environment and Peer Configurations
	 * across job tasks. This method acts on an existing OnyxEnv object.
	 * @return the updated OnyxEnv object
	 */
	public OnyxEnv generateTenancyId(){
		tenancyId = UUID.randomUUID();
		System.out.println("Tenancy ID set to: " + tenancyId);
		return this;
	}

{'fraction_non_alphanumeric': 0.07947671965114643, 'fraction_numerical': 0.0, 'mean_word_length': 4.546021840873635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '246552', 'n_tokens_mistral': 2147, 'n_tokens_neox': 1972, 'n_words': 705}