001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019package org.nuxeo.ecm.platform.importer.mqueues.computation; 020 021import java.util.HashMap; 022import java.util.Map; 023 024/** 025 * Enable to configure the stream partitioning and computation concurrency. 026 * 027 * @since 9.2 028 */ 029public class Settings { 030 private final int defaultConcurrency; 031 private final int defaultPartitions; 032 private final Map<String, Integer> concurrences = new HashMap<>(); 033 private final Map<String, Integer> partitions = new HashMap<>(); 034 035 public Settings(int defaultConcurrency, int defaultPartitions) { 036 this.defaultConcurrency = defaultConcurrency; 037 this.defaultPartitions = defaultPartitions; 038 } 039 040 public Settings setConcurrency(String computationName, int concurrency) { 041 concurrences.put(computationName, concurrency); 042 return this; 043 } 044 045 public int getConcurrency(String computationName) { 046 return concurrences.getOrDefault(computationName, defaultConcurrency); 047 } 048 049 public Settings setPartitions(String streamName, int partitions) { 050 this.partitions.put(streamName, partitions); 051 return this; 052 } 053 054 public int getPartitions(String streamName) { 055 return partitions.getOrDefault(streamName, defaultPartitions); 056 } 057 058} 059