001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
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 */
016package core.tut.pori.properties;
017
018import java.util.Properties;
019
020import org.apache.log4j.Logger;
021
022/**
023 * Settings for the system executor and quartz scheduler.
024 */
025public class ExecutorProperties extends SystemProperty {
026  /* properties */
027  private static final String PROPERTY_CORE_PORI_EXECUTOR_CORE_COUNT = PROPERTY_CORE_PORI_EXECUTOR+".core_count";
028  private static final String PROPERTY_CORE_PORI_EXECUTOR_KEEP_ALIVE = PROPERTY_CORE_PORI_EXECUTOR+".thread_keep_alive";
029  private static final String PROPERTY_CORE_PORI_EXECUTOR_QUEUE_SIZE = PROPERTY_CORE_PORI_EXECUTOR+".queue_size";
030  private static final String PROPERTY_CORE_PORI_EXECUTOR_POOL_SIZE = PROPERTY_CORE_PORI_EXECUTOR+".thread_count";
031  private int _coreCount = 1;
032  private long _keepAlive = 60;
033  private int _queueSize = 10;
034  private int _poolSize = 10;
035  
036  @Override
037  public void initialize(Properties properties) throws IllegalArgumentException {
038    try{
039      _coreCount = Integer.parseInt(properties.getProperty(PROPERTY_CORE_PORI_EXECUTOR_CORE_COUNT));
040      _keepAlive = Long.parseLong(properties.getProperty(PROPERTY_CORE_PORI_EXECUTOR_KEEP_ALIVE));
041      _queueSize = Integer.parseInt(properties.getProperty(PROPERTY_CORE_PORI_EXECUTOR_QUEUE_SIZE));
042      _poolSize = Integer.parseInt(properties.getProperty(PROPERTY_CORE_PORI_EXECUTOR_POOL_SIZE));
043    }catch (NumberFormatException ex){
044      Logger.getLogger(getClass()).error(ex, ex);
045      throw new IllegalArgumentException("Bad "+PROPERTY_CORE_PORI_EXECUTOR_POOL_SIZE+", "+PROPERTY_CORE_PORI_EXECUTOR_QUEUE_SIZE+", "+PROPERTY_CORE_PORI_EXECUTOR_CORE_COUNT+" OR "+PROPERTY_CORE_PORI_EXECUTOR_KEEP_ALIVE);
046    }
047  }
048
049  /**
050   * @return the coreCount
051   */
052  public int getCoreCount() {
053    return _coreCount;
054  }
055
056  /**
057   * @return the keepAlive, in seconds
058   */
059  public long getKeepAlive() {
060    return _keepAlive;
061  }
062
063  /**
064   * @return the queueSize
065   */
066  public int getQueueSize() {
067    return _queueSize;
068  }
069
070  /**
071   * @return the poolSize
072   */
073  public int getPoolSize() {
074    return _poolSize;
075  }
076}