Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package ca.nrc.cadc.ac.server.ldap;
import ca.nrc.cadc.profiler.Profiler;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPInterface;
class LdapConnections
{
Profiler profiler = new Profiler(LdapPersistence.class);
private LdapPersistence persistence;
private LDAPConnection readOnlyConn;
private LDAPConnection readWriteConn;
private LdapConfig config;
private LDAPConnection nonPooledConn;
LdapConnections(LdapPersistence persistence)
{
this.persistence = persistence;
}
LdapConnections(LdapConfig config)
{
this.config = config;
}
LDAPConnection getReadOnlyConnection() throws LDAPException
{
if (persistence != null)
{
if (readOnlyConn == null)
{
readOnlyConn = persistence.getReadOnlyConnection();
profiler.checkpoint("Get read only connection");
}
return readOnlyConn;
}
else
{
if (nonPooledConn == null)
{
nonPooledConn = getConnection(config);
}
return nonPooledConn;
}
}
LDAPConnection getReadWriteConnection() throws LDAPException
{
if (persistence != null)
{
if (readWriteConn == null)
{
readWriteConn = persistence.getReadWriteConnection();
profiler.checkpoint("Get read write connection");
}
return readWriteConn;
}
else
{
if (nonPooledConn == null)
{
nonPooledConn = getConnection(config);
}
return nonPooledConn;
}
}
void releaseConnections()
{
if (persistence != null)
{
if (readOnlyConn != null)
{
persistence.releaseReadOnlyConnection(readOnlyConn);
profiler.checkpoint("Release read only connection");
}
if (readWriteConn != null)
{
persistence.releaseReadWriteConnection(readWriteConn);
profiler.checkpoint("Release read write connection");
}
}
if (nonPooledConn != null)
{
nonPooledConn.close();
profiler.checkpoint("Close non-pooled connection");
}
}
LdapConfig getCurrentConfig()
{
if (persistence != null)
return persistence.getCurrentConfig();
else
return config;
}
private static LDAPConnection getConnection(LdapConfig config) throws LDAPException
{
LDAPConnection conn = new LDAPConnection(
LdapDAO.getSocketFactory(config),
config.getReadWritePool().getServers().get(0),
config.getPort());
conn.bind(config.getAdminUserDN(), config.getAdminPasswd());
return conn;
}
}