Skip to content

Commit 2667cc2

Browse files
committed
Fix bad integ
[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 108276]
1 parent 5f2da81 commit 2667cc2

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

prj/coherence-core/src/main/java/com/tangosol/net/CoherenceConfiguration.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -36,7 +36,7 @@ public interface CoherenceConfiguration
3636
*/
3737
static Builder builder()
3838
{
39-
return new Builder();
39+
return new Builder().discoverSessions();
4040
}
4141

4242
/**
@@ -115,6 +115,14 @@ default String getDefaultSessionName()
115115
*/
116116
class Builder
117117
{
118+
/**
119+
* Create a {@link Builder}.
120+
*/
121+
public Builder()
122+
{
123+
m_fDiscoverSessions = true;
124+
}
125+
118126
/**
119127
* Set the name of the {@link Coherence} instance.
120128
* <p>
@@ -166,7 +174,18 @@ public Builder withDefaultSession(String sName)
166174
*/
167175
public Builder discoverSessions()
168176
{
169-
withSessions(ServiceLoader.load(SessionConfiguration.class));
177+
return discoverSessions(true);
178+
}
179+
180+
/**
181+
* Add all of the {@link SessionConfiguration} instances discovered
182+
* using the {@link ServiceLoader}.
183+
*
184+
* @return this {@link Builder}
185+
*/
186+
public Builder discoverSessions(boolean f)
187+
{
188+
m_fDiscoverSessions = f;
170189
return this;
171190
}
172191

@@ -188,6 +207,12 @@ public Builder discoverSessions()
188207
* @return this {@link Builder}
189208
*/
190209
public Builder withSession(SessionConfiguration config)
210+
{
211+
withSession(config, f_mapConfig);
212+
return this;
213+
}
214+
215+
private void withSession(SessionConfiguration config, Map<String, SessionConfiguration> map)
191216
{
192217
if (config != null && config.isEnabled())
193218
{
@@ -196,9 +221,8 @@ public Builder withSession(SessionConfiguration config)
196221
{
197222
throw new IllegalArgumentException("A session configuration must provide a non-null name");
198223
}
199-
f_mapConfig.put(sName, config);
224+
map.put(sName, config);
200225
}
201-
return this;
202226
}
203227

204228
/**
@@ -320,12 +344,15 @@ public Builder withApplicationContext(Context context)
320344
*/
321345
public CoherenceConfiguration build()
322346
{
323-
if (Coherence.getInstance(m_sName) != null)
347+
Map<String, SessionConfiguration> mapConfig = new HashMap<>();
348+
if (m_fDiscoverSessions)
324349
{
325-
throw new IllegalStateException("A Coherence instance already exists with the name " + m_sName);
350+
for (SessionConfiguration configuration : ServiceLoader.load(SessionConfiguration.class))
351+
{
352+
withSession(configuration, mapConfig);
353+
}
326354
}
327-
328-
Map<String, SessionConfiguration> mapConfig = new HashMap<>(f_mapConfig);
355+
mapConfig.putAll(f_mapConfig);
329356

330357
if (mapConfig.isEmpty())
331358
{
@@ -349,6 +376,11 @@ public CoherenceConfiguration build()
349376
*/
350377
private String m_sDefaultSession = Coherence.DEFAULT_NAME;
351378

379+
/**
380+
* A flag to determine whether to automatically discover session configurations.
381+
*/
382+
private boolean m_fDiscoverSessions;
383+
352384
/**
353385
* A map of named {@link SessionConfiguration} instances.
354386
*/

0 commit comments

Comments
 (0)