1 5 12 13 package org.exoplatform.services.ldap.impl; 14 15 import java.util.Stack ; 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 pool = new Stack (); 25 int min = 1; 26 int max = 10; 27 28 public LDAPServiceContainerImpl(LogService lservice) throws Exception { 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 |