Skip to content

Commit

Permalink
Merge common fields/methods in LdapConnFactory subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Sep 16, 2023
1 parent f86cc9d commit 6c01ba6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.mozilla.jss.ssl.SSLSocketListener;

import com.netscape.cmscore.apps.CMSEngine;
import com.netscape.cmscore.ldapconn.LdapConnInfo;
import com.netscape.cmscore.ldapconn.PKISocketConfig;
import com.netscape.cmscore.logging.Auditor;

import netscape.ldap.LDAPConnection;
Expand All @@ -32,11 +34,54 @@
*/
public abstract class LdapConnFactory {

public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LdapConnFactory.class);

public static final String PROP_MINCONNS = "minConns";
public static final String PROP_MAXCONNS = "maxConns";
public static final String PROP_MAXRESULTS = "maxResults";
public static final String PROP_ERROR_IF_DOWN = "errorIfDown";

protected String id;

protected PKISocketConfig config;
protected LdapConnInfo mConnInfo;

protected int mMinConns = 5;
protected int mMaxConns = 1000;
protected int mMaxResults = 0;

/**
* number of available conns in array
*/
protected int mNumConns = 0;

/**
* total num conns
*/
protected int mTotal = 0;

/**
* return error if server is down at creation time.
*/
protected boolean mErrorIfDown;

/**
* default value for the above at init time.
*/
protected boolean mDefErrorIfDown;

protected CMSEngine engine;
protected Auditor auditor;
protected SSLSocketListener socketListener;
protected SSLCertificateApprovalCallback approvalCallback;

/**
* returns connection info.
*/
public LdapConnInfo getConnInfo() {
return mConnInfo;
}

public CMSEngine getCMSEngine() {
return engine;
}
Expand Down Expand Up @@ -65,23 +110,28 @@ public void setCMSEngine(CMSEngine engine) {
*
* @return Integer number of free connections.
*/

public abstract int freeConn();
public synchronized int freeConn() {
return mNumConns;
}

/**
* Returns the number of total connections available from this pool.
* Includes sum of free and in use connections.
*
* @return Integer number of total connections.
*/
public abstract int totalConn();
public int totalConn() {
return mTotal;
}

/**
* Returns the maximum number of connections available from this pool.
*
* @return Integer maximum number of connections.
*/
public abstract int maxConn();
public int maxConn() {
return mMaxConns;
}

/**
* Request access to a Ldap connection from the pool.
Expand All @@ -99,4 +149,9 @@ public void setCMSEngine(CMSEngine engine) {
* @exception ELdapException On any failure to return the connection.
*/
public abstract void returnConn(LDAPConnection conn) throws ELdapException;

@Override
protected void finalize() throws Exception {
reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,8 @@
*/
public class LdapAnonConnFactory extends LdapConnFactory {

public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LdapAnonConnFactory.class);

protected String id;

PKISocketConfig config;

protected int mMinConns = 5;
protected int mMaxConns = 1000;
protected int mMaxResults = 0;
protected LdapConnInfo mConnInfo = null;

public static final String PROP_MINCONNS = "minConns";
public static final String PROP_MAXCONNS = "maxConns";
public static final String PROP_MAXRESULTS = "maxResults";

public static final String PROP_ERROR_IF_DOWN = "errorIfDown";

private int mNumConns = 0; // number of available conns in array
private int mTotal = 0; // total num conns
private AnonConnection mConns[] = null;

private boolean mInited = false;

private boolean mErrorIfDown;
private boolean mDefErrorIfDown = false;
AnonConnection[] mConns;
boolean mInited;

/**
* Constructor for initializing from the config store.
Expand Down Expand Up @@ -128,22 +105,6 @@ public LdapAnonConnFactory(
this.mConnInfo = connInfo;
}


@Override
public int totalConn() {
return mTotal;
}

@Override
public int freeConn() {
return mNumConns;
}

@Override
public int maxConn() {
return mMaxConns;
}

public void init(PKISocketConfig config) throws ELdapException {

logger.debug("LdapAnonConnFactory: initialization");
Expand Down Expand Up @@ -455,19 +416,6 @@ public synchronized void returnConn(LDAPConnection conn) {
logger.debug(method + " final values. Total: " + mTotal + ", pool: " + mNumConns);
}

@Override
protected void finalize()
throws Exception {
reset();
}

/**
* returns connection info.
*/
public LdapConnInfo getConnInfo() {
return mConnInfo;
}

/**
* resets this factory - if no connections outstanding,
* disconnections all connections and resets everything to 0 as if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,15 @@
*/
public class LdapBoundConnFactory extends LdapConnFactory {

public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LdapBoundConnFactory.class);

protected String id;

PKISocketConfig config;

protected int mMinConns = 5;
protected int mMaxConns = 1000;
protected int mMaxResults = 0;

protected LdapConnInfo mConnInfo = null;
protected LdapAuthInfo mAuthInfo = null;
PasswordStore passwordStore;

public static final String PROP_MINCONNS = "minConns";
public static final String PROP_MAXCONNS = "maxConns";
public static final String PROP_MAXRESULTS = "maxResults";
public static final String PROP_LDAPCONNINFO = "ldapconn";
public static final String PROP_LDAPAUTHINFO = "ldapauth";

public static final String PROP_ERROR_IF_DOWN = "errorIfDown";

private int mNumConns = 0; // number of available conns in array
private int mTotal = 0; // total num conns

private boolean doCloning = true;
private LdapBoundConnection mMasterConn = null; // master connection object.
private LdapBoundConnection[] mConns;
LdapAuthInfo mAuthInfo;
PasswordStore passwordStore;

/**
* return error if server is down at creation time.
*/
private boolean mErrorIfDown;

/**
* default value for the above at init time.
*/
private boolean mDefErrorIfDown = false;
boolean doCloning = true;
LdapBoundConnection mMasterConn; // master connection object.
LdapBoundConnection[] mConns;

/**
* Constructor for initializing from the config store.
Expand Down Expand Up @@ -154,21 +125,6 @@ public LdapBoundConnFactory(
this.mAuthInfo = authInfo;
}

@Override
public int totalConn() {
return mTotal;
}

@Override
public synchronized int freeConn() {
return mNumConns;
}

@Override
public int maxConn() {
return mMaxConns;
}

public void init(
PKISocketConfig config,
PasswordStore passwordStore
Expand Down Expand Up @@ -562,12 +518,6 @@ public synchronized void returnConn(LDAPConnection conn) {

}

@Override
protected void finalize()
throws Exception {
reset();
}

/**
* used for disconnecting all connections and reset everything to 0
* as if connections were never made. used just before a subsystem
Expand Down Expand Up @@ -636,13 +586,6 @@ public synchronized void shutdown() throws ELdapException {
}
}

/**
* return ldap connection info
*/
public LdapConnInfo getConnInfo() {
return mConnInfo;
}

/**
* return ldap authentication info
*/
Expand Down

0 comments on commit 6c01ba6

Please sign in to comment.