View Javadoc

1   /*
2    * Copyright 2010 University Corporation for Advanced Internet Development, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector;
18  
19  import edu.vt.middleware.ldap.Ldap;
20  import edu.vt.middleware.ldap.pool.BlockingLdapPool;
21  import edu.vt.middleware.ldap.pool.LdapFactory;
22  import edu.vt.middleware.ldap.pool.LdapPool;
23  import edu.vt.middleware.ldap.pool.LdapPoolConfig;
24  import edu.vt.middleware.ldap.pool.SoftLimitLdapPool;
25  
26  /**
27   * Ldap pool strategy backed by the vt-ldap library. 
28   */
29  public class LdapPoolVTStrategy implements LdapPoolStrategy {
30  
31      /** Underlying pool. */
32      private LdapPool<Ldap> ldapPool;
33  
34      /** Ldap pool configuration. */
35      private LdapPoolConfig ldapPoolConfig;
36  
37      /** Factory for making ldap objects. */
38      private LdapFactory<Ldap> ldapFactory;
39  
40      /** Whether to block when empty. */
41      private boolean blockWhenEmpty;
42  
43      /**
44       * Default constructor.
45       */
46      public LdapPoolVTStrategy() {}
47  
48      /** {@inheritDoc} */
49      public void setLdapPoolConfig(LdapPoolConfig config) {
50          ldapPoolConfig = config;
51      }
52  
53      /** {@inheritDoc} */
54      public void setLdapFactory(LdapFactory<Ldap> factory) {
55          ldapFactory = factory;
56      }
57  
58      /** {@inheritDoc} */
59      public void setBlockWhenEmpty(boolean block) {
60          blockWhenEmpty = block;
61      }
62  
63      /** {@inheritDoc} */
64      public void initialize() {
65          ldapPoolConfig.setPruneTimerPeriod(ldapPoolConfig.getValidateTimerPeriod());
66          if (blockWhenEmpty) {
67              ldapPool = new BlockingLdapPool(ldapPoolConfig, ldapFactory);
68          } else {
69              ldapPool = new SoftLimitLdapPool(ldapPoolConfig, ldapFactory);
70          }
71          ldapPool.initialize();
72      }
73  
74      /** {@inheritDoc} */
75      public Ldap checkOut() throws Exception {
76          return ldapPool.checkOut();
77      }
78  
79      /** {@inheritDoc} */
80      public void checkIn(Ldap l) throws Exception {
81          ldapPool.checkIn(l);
82      }
83  }