<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * 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 org.apache.uima.internal.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.analysis_engine.ResultSpecification;
import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
import org.apache.uima.resource.Resource;
import org.apache.uima.resource.ResourceConfigurationException;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.util.Logger;

/**
 * A pool of Analysis Engines, which supports reconfiguration. This is not part of the stable UIMA
 * API and may change in future releases.
 * 
 * 
 */
public class AnalysisEnginePool {

  /**
   * Creates a new AnalysisEnginePool.
   * 
   * @param aName
   *          the pool name
   * @param aNumInstances
   *          the number of Resource instances in the pool
   * @param aResourceSpecifier
   *          specifier that describes how to create the Resource instances for the pool
   * 
   * @throws ResourceInitializationException
   *           if the Resource instances could not be created
   */
  public AnalysisEnginePool(String aName, int aNumInstances, ResourceSpecifier aResourceSpecifier)
          throws ResourceInitializationException {
    this(aName, aNumInstances, aResourceSpecifier, null);
  }

  /**
   * Creates a new AnalysisEnginePool.
   * 
   * @param aName
   *          the pool name
   * @param aNumInstances
   *          the number of Resource instances in the pool
   * @param aResourceSpecifier
   *          specifier that describes how to create the Resource instances for the pool
   * @param aResourceInitParams
   *          additional parameters to be passed to
   *          {@link Resource#initialize(ResourceSpecifier,Map)} methods. May be null if there are
   *          no parameters.
   * 
   * @throws ResourceInitializationException
   *           if the Resource instances could not be created
   */
  public AnalysisEnginePool(String aName, int aNumInstances, ResourceSpecifier aResourceSpecifier,
          Map aResourceInitParams) throws ResourceInitializationException {
    if (aResourceInitParams == null) {
      aResourceInitParams = new HashMap();
    } else {
      aResourceInitParams = new HashMap(aResourceInitParams);
    }

    // initialize ResourcePool
    mPool = new ResourcePool(aNumInstances, aResourceSpecifier, getResourceClass(),
            aResourceInitParams);
  }

  /**
   * Checks out an AnalysisEngine from the pool.<commit_msg>UIMA-1504 Generify the additionalParams Map through the uimaj-core codebase<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * 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 org.apache.uima.internal.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.analysis_engine.ResultSpecification;
import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
import org.apache.uima.resource.Resource;
import org.apache.uima.resource.ResourceConfigurationException;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.util.Logger;

/**
 * A pool of Analysis Engines, which supports reconfiguration. This is not part of the stable UIMA
 * API and may change in future releases.
 * 
 * 
 */
public class AnalysisEnginePool {

  /**
   * Creates a new AnalysisEnginePool.
   * 
   * @param aName
   *          the pool name
   * @param aNumInstances
   *          the number of Resource instances in the pool
   * @param aResourceSpecifier
   *          specifier that describes how to create the Resource instances for the pool
   * 
   * @throws ResourceInitializationException
   *           if the Resource instances could not be created
   */
  public AnalysisEnginePool(String aName, int aNumInstances, ResourceSpecifier aResourceSpecifier)
          throws ResourceInitializationException {
    this(aName, aNumInstances, aResourceSpecifier, null);
  }

  /**
   * Creates a new AnalysisEnginePool.
   * 
   * @param aName
   *          the pool name
   * @param aNumInstances
   *          the number of Resource instances in the pool
   * @param aResourceSpecifier
   *          specifier that describes how to create the Resource instances for the pool
   * @param aResourceInitParams
   *          additional parameters to be passed to
   *          {@link Resource#initialize(ResourceSpecifier,Map)} methods. May be null if there are
   *          no parameters.
   * 
   * @throws ResourceInitializationException
   *           if the Resource instances could not be created
   */
  public AnalysisEnginePool(String aName, int aNumInstances, ResourceSpecifier aResourceSpecifier,
          Map<String, Object> aResourceInitParams) throws ResourceInitializationException {
    if (aResourceInitParams == null) {
      aResourceInitParams = new HashMap<String, Object>();
    } else {
      aResourceInitParams = new HashMap<String, Object>(aResourceInitParams);
    }

    // initialize ResourcePool
    mPool = new ResourcePool(aNumInstances, aResourceSpecifier, getResourceClass(),
            aResourceInitParams);
  }

  /**
   * Checks out an AnalysisEngine from the pool.
{'fraction_non_alphanumeric': 0.06804323725055432, 'fraction_numerical': 0.0016629711751662971, 'mean_word_length': 3.516270337922403, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7663253', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1842, 'n_words': 660}