1
1
/*
2
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
37
37
* The {@code LdapDnsProviderService} is responsible for creating and providing
38
38
* access to the registered {@code LdapDnsProvider}s. The {@link ServiceLoader}
39
39
* is used to find and register any implementations of {@link LdapDnsProvider}.
40
+ *
41
+ * <p> Instances of this class are safe for use by multiple threads.
40
42
*/
41
43
final class LdapDnsProviderService {
42
44
@@ -68,19 +70,19 @@ private LdapDnsProviderService() {
68
70
}
69
71
70
72
/**
71
- * Retrieve the singleton static instance of LdapDnsProviderService.
73
+ * Retrieves the singleton instance of LdapDnsProviderService.
72
74
*/
73
75
static LdapDnsProviderService getInstance () {
74
76
if (service != null ) return service ;
75
- synchronized (LOCK ) {
77
+ synchronized (LOCK ) {
76
78
if (service != null ) return service ;
77
79
service = new LdapDnsProviderService ();
78
80
}
79
81
return service ;
80
82
}
81
83
82
84
/**
83
- * Retrieve result from the first provider that successfully resolves
85
+ * Retrieves result from the first provider that successfully resolves
84
86
* the endpoints. If no results are found when calling installed
85
87
* subclasses of {@code LdapDnsProvider} then this method will fall back
86
88
* to the {@code DefaultLdapDnsProvider}.
@@ -91,14 +93,15 @@ static LdapDnsProviderService getInstance() {
91
93
LdapDnsProviderResult lookupEndpoints (String url , Hashtable <?,?> env )
92
94
throws NamingException
93
95
{
94
- Iterator <LdapDnsProvider > iterator = providers .iterator ();
95
- Hashtable <?, ?> envCopy = new Hashtable <>(env );
96
96
LdapDnsProviderResult result = null ;
97
-
98
- while (result == null && iterator .hasNext ()) {
99
- result = iterator .next ().lookupEndpoints (url , envCopy )
100
- .filter (r -> r .getEndpoints ().size () > 0 )
101
- .orElse (null );
97
+ Hashtable <?, ?> envCopy = new Hashtable <>(env );
98
+ synchronized (LOCK ) {
99
+ Iterator <LdapDnsProvider > iterator = providers .iterator ();
100
+ while (result == null && iterator .hasNext ()) {
101
+ result = iterator .next ().lookupEndpoints (url , envCopy )
102
+ .filter (r -> !r .getEndpoints ().isEmpty ())
103
+ .orElse (null );
104
+ }
102
105
}
103
106
104
107
if (result == null ) {
0 commit comments