001/* 002 * (C) Copyright 2006-2012 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 * Florent Guillaume 018 * Julien Carsique 019 */ 020package org.nuxeo.ecm.core.api.repository; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XObject; 024 025/** 026 * Descriptor of the pool of low-level Nuxeo Sessions. 027 * 028 * @since 5.6 029 */ 030@XObject("pool") 031public class PoolConfiguration { 032 033 public static final int DEFAULT_MAX_POOL_SIZE = 20; 034 035 public static final int DEFAULT_MIN_POOL_SIZE = 0; 036 037 public static final int DEFAULT_BLOCKING_TIMEOUT_MILLIS = 100; 038 039 @XNode("@maxPoolSize") 040 private Integer maxPoolSize; 041 042 @XNode("@minPoolSize") 043 private Integer minPoolSize; 044 045 @XNode("@blockingTimeoutMillis") 046 private Integer blockingTimeoutMillis; 047 048 public PoolConfiguration() { 049 } 050 051 /** Copy constructor. */ 052 public PoolConfiguration(PoolConfiguration other) { 053 maxPoolSize = other.maxPoolSize; 054 minPoolSize = other.minPoolSize; 055 blockingTimeoutMillis = other.blockingTimeoutMillis; 056 } 057 058 public void merge(PoolConfiguration other) { 059 if (other.maxPoolSize != null) { 060 maxPoolSize = other.maxPoolSize; 061 } 062 if (other.minPoolSize != null) { 063 minPoolSize = other.minPoolSize; 064 } 065 if (other.blockingTimeoutMillis != null) { 066 blockingTimeoutMillis = other.blockingTimeoutMillis; 067 } 068 } 069 070 private static int defaultInt(Integer value, int def) { 071 return value == null ? def : value.intValue(); 072 } 073 074 public int getMaxPoolSize() { 075 return defaultInt(maxPoolSize, DEFAULT_MAX_POOL_SIZE); 076 } 077 078 public int getMinPoolSize() { 079 return defaultInt(minPoolSize, DEFAULT_MIN_POOL_SIZE); 080 } 081 082 public int getBlockingTimeoutMillis() { 083 return defaultInt(blockingTimeoutMillis, DEFAULT_BLOCKING_TIMEOUT_MILLIS); 084 } 085 086 public void setMaxPoolSize(int maxPoolSize) { 087 this.maxPoolSize = Integer.valueOf(maxPoolSize); 088 } 089 090 public void setMinPoolSize(int minPoolSize) { 091 this.minPoolSize = Integer.valueOf(minPoolSize); 092 } 093 094 public void setBlockingTimeoutMillis(int blockingTimeoutMillis) { 095 this.blockingTimeoutMillis = Integer.valueOf(blockingTimeoutMillis); 096 } 097 098 @XNode("@maxActive") 099 public void setMaxActive(int num) { 100 maxPoolSize = num; 101 } 102 103 @XNode("@maxIdle") 104 public void setMaxIdle(int num) { 105 minPoolSize = num; 106 } 107 108 @XNode("@maxWait") 109 public void setMaxWait(int num) { 110 blockingTimeoutMillis = num; 111 } 112 113}