private void createKafkaAdaptorListener(
      InputEventAdapterListener inputEventAdapterListener,
      InputEventAdapterConfiguration inputEventAdapterConfiguration) {

    Map<String, String> brokerProperties = new HashMap<String, String>();
    brokerProperties.putAll(inputEventAdapterConfiguration.getProperties());
    String zkConnect =
        brokerProperties.get(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_ZOOKEEPER_CONNECT);
    String groupID = brokerProperties.get(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_GROUP_ID);
    String threadsStr = brokerProperties.get(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_THREADS);
    String optionalConfiguration =
        brokerProperties.get(KafkaEventAdapterConstants.ADAPTOR_OPTIONAL_CONFIGURATION_PROPERTIES);
    int threads = Integer.parseInt(threadsStr);

    String topic =
        inputEventAdapterConfiguration
            .getProperties()
            .get(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_TOPIC);

    consumerKafkaAdaptor =
        new ConsumerKafkaAdaptor(
            topic,
            tenantId,
            KafkaEventAdapter.createConsumerConfig(zkConnect, groupID, optionalConfiguration));
    consumerKafkaAdaptor.run(threads, inputEventAdapterListener);
  }
  private int[] computeClusterNumberRange(int min, int max, int hop, Optimizer optimizer)
      throws ExecutionException, InterruptedException {
    ExecutorService executor;
    if (parallelWorkers > 1) {
      executor = Executors.newFixedThreadPool(2);
    } else {
      executor = Executors.newFixedThreadPool(1);
    }
    ConcurrentMap<Integer, Double> sharedScores = new ConcurrentHashMap<>();
    SearchSpaceBoundaryFinder_old upperBoundFinder =
        new SearchSpaceUpperBoundaryFinder_old(min, max, hop, optimizer, sharedScores);
    Future<Integer> futureUpperBound = executor.submit(upperBoundFinder);
    SearchSpaceBoundaryFinder_old lowerBoundFinder =
        new SearchSpaceLowerBoundaryFinder_old(min, max, hop, optimizer, sharedScores);
    Future<Integer> futureLowerBound = executor.submit(lowerBoundFinder);
    executor.shutdown();
    int[] r = new int[2];
    Integer realMin = futureLowerBound.get();
    Integer realMax = futureUpperBound.get();
    r[0] = realMin == null ? -1 : realMin;
    r[1] = realMax == null ? -1 : realMax;

    scores.putAll(lowerBoundFinder.getSplitsAndScores());
    // scores.putAll(upperBoundFinder.getSplitsAndScores());
    return r;
  }
  @Override
  public Map<?, ?> selectMap(
      final String statementName,
      final Object parameterObject,
      final String mapKey,
      final RowBounds rowBounds) {
    if (isSqlAuditorBehaviorEnabled()) {
      getSqlAuditor()
          .audit(
              statementName,
              getSqlByStatementName(statementName, parameterObject),
              parameterObject);
    }
    if (isPartitioningBehaviorEnabled()) {
      SortedMap<String, DataSource> dsMap =
          lookupDataSourcesByRouter(statementName, parameterObject);
      if (dsMap != null && !dsMap.isEmpty()) {

        SqlSessionCallback action =
            new SqlSessionCallback<Map<?, ?>>() {
              @Override
              public Map<?, ?> doInSession(SqlSession sqlSession) {
                return sqlSession.selectMap(statementName, parameterObject, mapKey, rowBounds);
              }
            };

        if (dsMap.size() == 1) {
          return (Map<?, ?>) executeWith(dsMap.get(dsMap.firstKey()), action);
        } else {
          List<Object> results = executeInConcurrency(action, dsMap);
          Map<?, ?> retVal = Maps.newHashMap();
          if (results != null && !results.isEmpty()) {
            for (int i = 0; i < results.size(); i++) {
              retVal.putAll((Map) results.get(i));
            }
          }

          return retVal;
        }
      }
    }

    return super.selectMap(statementName, parameterObject, mapKey, rowBounds);
  }
 private Map<String, HeaderDefinition> buildHeaderDefinitions() throws MojoFailureException {
   // like mappings, first get default definitions
   final Map<String, HeaderDefinition> headers =
       new HashMap<String, HeaderDefinition>(HeaderType.defaultDefinitions());
   // and then override them with those provided in properties file
   for (String resource : headerDefinitions) {
     try {
       InputSource source = new InputSource(finder.findResource(resource).openStream());
       source.setEncoding(encoding);
       final AdditionalHeaderDefinition fileDefinitions =
           new AdditionalHeaderDefinition(XMLDoc.from(source, true));
       final Map<String, HeaderDefinition> map = fileDefinitions.getDefinitions();
       debug("%d header definitions loaded from '%s'", map.size(), resource);
       headers.putAll(map);
     } catch (IOException ex) {
       throw new MojoFailureException("Error reading header definition: " + resource, ex);
     }
   }
   // force inclusion of unknow item to manage unknown files
   headers.put(HeaderType.UNKNOWN.getDefinition().getType(), HeaderType.UNKNOWN.getDefinition());
   return headers;
 }
 private Map<String, String> mergeProperties(Document document) {
   // first put systen environment
   Map<String, String> props = new LinkedHashMap<String, String>(System.getenv());
   // then add ${project.XYZ} properties
   props.put("project.groupId", project.getGroupId());
   props.put("project.artifactId", project.getArtifactId());
   props.put("project.version", project.getVersion());
   props.put("project.name", project.getName());
   props.put("project.description", project.getDescription());
   props.put("project.inceptionYear", project.getInceptionYear());
   props.put("project.url", project.getUrl());
   // then add per document properties
   props.put("file.name", document.getFile().getName());
   // we override by properties in the POM
   if (this.properties != null) {
     props.putAll(this.properties);
   }
   // then we override by java system properties (command-line -D...)
   for (String key : System.getProperties().stringPropertyNames()) {
     props.put(key, System.getProperty(key));
   }
   return props;
 }