001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.connector.outbound.connectionmanagerconfig;
019    
020    import org.apache.geronimo.connector.outbound.ConnectionInterceptor;
021    import org.apache.geronimo.connector.outbound.PoolingAttributes;
022    import org.apache.geronimo.connector.outbound.SinglePoolConnectionInterceptor;
023    import org.apache.geronimo.connector.outbound.SinglePoolMatchAllConnectionInterceptor;
024    
025    /**
026     * @version $Rev: 550546 $ $Date: 2007-06-25 18:52:11 +0200 (Mon, 25 Jun 2007) $
027     */
028    public class SinglePool implements PoolingSupport {
029        private int maxSize;
030        private int minSize;
031        private int blockingTimeoutMilliseconds;
032        private int idleTimeoutMinutes;
033        private boolean matchOne;
034        private boolean matchAll;
035        private boolean selectOneAssumeMatch;
036    
037        private transient PoolingAttributes pool;
038    
039        public SinglePool(int maxSize, int minSize, int blockingTimeoutMilliseconds, int idleTimeoutMinutes, boolean matchOne, boolean matchAll, boolean selectOneAssumeMatch) {
040            this.maxSize = maxSize;
041            this.minSize = minSize;
042            this.blockingTimeoutMilliseconds = blockingTimeoutMilliseconds;
043            this.idleTimeoutMinutes = idleTimeoutMinutes;
044            this.matchOne = matchOne;
045            this.matchAll = matchAll;
046            this.selectOneAssumeMatch = selectOneAssumeMatch;
047        }
048    
049        public int getMaxSize() {
050            return maxSize;
051        }
052    
053        public void setMaxSize(int maxSize) {
054            this.maxSize = maxSize;
055        }
056    
057        public int getMinSize() {
058            return minSize;
059        }
060    
061        public void setMinSize(int minSize) {
062            this.minSize = minSize;
063        }
064    
065        public int getBlockingTimeoutMilliseconds() {
066            return blockingTimeoutMilliseconds;
067        }
068    
069        public void setBlockingTimeoutMilliseconds(int blockingTimeoutMilliseconds) {
070            this.blockingTimeoutMilliseconds = blockingTimeoutMilliseconds;
071            if (pool != null) {
072                pool.setBlockingTimeoutMilliseconds(blockingTimeoutMilliseconds);
073            }
074        }
075    
076        public int getIdleTimeoutMinutes() {
077            return idleTimeoutMinutes;
078        }
079    
080        public void setIdleTimeoutMinutes(int idleTimeoutMinutes) {
081            this.idleTimeoutMinutes = idleTimeoutMinutes;
082            if (pool != null) {
083                pool.setIdleTimeoutMinutes(idleTimeoutMinutes);
084            }
085        }
086    
087        public boolean isMatchOne() {
088            return matchOne;
089        }
090    
091        public void setMatchOne(boolean matchOne) {
092            this.matchOne = matchOne;
093        }
094    
095        public boolean isMatchAll() {
096            return matchAll;
097        }
098    
099        public void setMatchAll(boolean matchAll) {
100            this.matchAll = matchAll;
101        }
102    
103        public boolean isSelectOneAssumeMatch() {
104            return selectOneAssumeMatch;
105        }
106    
107        public void setSelectOneAssumeMatch(boolean selectOneAssumeMatch) {
108            this.selectOneAssumeMatch = selectOneAssumeMatch;
109        }
110    
111        public ConnectionInterceptor addPoolingInterceptors(ConnectionInterceptor tail) {
112            if (isMatchAll()) {
113                SinglePoolMatchAllConnectionInterceptor pool = new SinglePoolMatchAllConnectionInterceptor(tail,
114                        getMaxSize(),
115                        getMinSize(),
116                        getBlockingTimeoutMilliseconds(),
117                        getIdleTimeoutMinutes());
118                this.pool = pool;
119                return pool;
120    
121            } else {
122                SinglePoolConnectionInterceptor pool = new SinglePoolConnectionInterceptor(tail,
123                        getMaxSize(),
124                        getMinSize(),
125                        getBlockingTimeoutMilliseconds(),
126                        getIdleTimeoutMinutes(),
127                        isSelectOneAssumeMatch());
128                this.pool = pool;
129                return pool;
130            }
131        }
132    
133        public int getPartitionCount() {
134            return 1;
135        }
136    
137        public int getPartitionMaxSize() {
138            return maxSize;
139        }
140    
141        public void setPartitionMaxSize(int maxSize) throws InterruptedException {
142            if (pool != null) {
143                pool.setPartitionMaxSize(maxSize);
144            }
145            this.maxSize = maxSize;
146        }
147    
148        public int getPartitionMinSize() {
149            return minSize;
150        }
151    
152        public void setPartitionMinSize(int minSize) {
153            if (pool != null) {
154                pool.setPartitionMinSize(minSize);
155            }
156            this.minSize = minSize;
157        }
158    
159        public int getIdleConnectionCount() {
160            return pool == null ? 0 : pool.getIdleConnectionCount();
161        }
162    
163        public int getConnectionCount() {
164            return pool == null ? 0 : pool.getConnectionCount();
165        }
166    }