KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > ldap > impl > LDAPServiceContainerImpl


1 /***************************************************************************
2  * Copyright 2001-2004 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 /**
6  * Created by The eXo Platform SARL .
7  * Author : Daniel Summer
8  * danny_xcz@users.sourceforge.net
9  * Date: 25/5/2004
10  *
11  */

12
13 package org.exoplatform.services.ldap.impl;
14
15 import java.util.Stack JavaDoc;
16 import org.exoplatform.services.exception.ExoServiceException;
17 import org.exoplatform.services.ldap.LDAPService;
18 import org.exoplatform.services.ldap.LDAPServiceContainer;
19 import org.exoplatform.services.log.LogService;
20
21 public class LDAPServiceContainerImpl implements LDAPServiceContainer {
22     private LDAPServiceConfig ldapServiceConfig_;
23     private LogService logService_;
24     private Stack JavaDoc pool = new Stack JavaDoc();
25     int min = 1;
26     int max = 10;
27
28     public LDAPServiceContainerImpl(LogService lservice) throws Exception JavaDoc {
29       logService_ = lservice;
30       ldapServiceConfig_ = new LDAPServiceConfig();
31       for (int i = 0; i < min; i++) {
32         LDAPService service = new LDAPServiceImpl(logService_);
33         service.connect(ldapServiceConfig_.SERVICES_LDAP_HOST,
34                         ldapServiceConfig_.SERVICES_LDAP_PORT);
35         service.authenticate(ldapServiceConfig_.SERVICES_LDAP_BASEDN,
36                              ldapServiceConfig_.SERVICES_LDAP_PASSWD);
37         pool.push(service);
38       }
39     }
40
41     public LDAPService createLDAPService() throws ExoServiceException {
42         LDAPService service = null;
43
44         if (pool.size() > 0) {
45             service = (LDAPService) pool.pop();
46         } else {
47             service = new LDAPServiceImpl(logService_);
48             service.connect(ldapServiceConfig_.SERVICES_LDAP_HOST,
49                               ldapServiceConfig_.SERVICES_LDAP_PORT);
50             service.authenticate(ldapServiceConfig_.SERVICES_LDAP_BASEDN,
51                                    ldapServiceConfig_.SERVICES_LDAP_PASSWD);
52
53         }
54         return service;
55     }
56
57     public void closeLDAPService(LDAPService ldapService)
58         throws ExoServiceException {
59         if ((pool.size() + 1) > max) {
60             ldapService.disconnect();
61         } else {
62             pool.push(ldapService);
63         }
64     }
65
66 }
67
Popular Tags