-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9b2516
commit 700491b
Showing
9 changed files
with
269 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 127 additions & 52 deletions
179
dotCMS/src/main/java/com/dotcms/cache/lettuce/MasterReplicaLettuceClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
dotCMS/src/main/java/com/dotcms/system/CompositeAppContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.dotcms.system; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* This class is a composite of one or more {@link AppContext} objects. When a specific attribute is requested, it will | ||
* try to get it from the first context that has it. | ||
* | ||
* @author jsanca | ||
* @since Jun 7th, 2023 | ||
*/ | ||
public class CompositeAppContext implements AppContext { | ||
|
||
private final AppContext writeContext; | ||
private final AppContext[] readContexts; | ||
|
||
public CompositeAppContext(final AppContext writeContext, final AppContext... readContexts) { | ||
this.writeContext = writeContext; | ||
this.readContexts = null == readContexts? new AppContext[0] : readContexts; | ||
} | ||
|
||
@Override | ||
public <T> T getAttribute(final String attributeName) { | ||
return (T)Stream.of(this.readContexts).filter(context -> context.getAttribute(attributeName) != null) | ||
.map(c -> c.getAttribute(attributeName)).findFirst().orElse(null); | ||
} | ||
|
||
@Override | ||
public <T> void setAttribute(String attributeName, T attributeValue) { | ||
if (null != this.writeContext) { | ||
this.writeContext.setAttribute(attributeName, attributeValue); | ||
} | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return AppContext.super.getId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
dotCMS/src/main/java/com/dotmarketing/util/EnvironmentVariablesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.dotmarketing.util; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* This services encapsulates the environment variables and allows | ||
* for a better testing to override, add environment variables. | ||
* @author jsanca | ||
*/ | ||
public class EnvironmentVariablesService { | ||
|
||
private static class SingletonHolder { | ||
private static final EnvironmentVariablesService INSTANCE = new EnvironmentVariablesService(); | ||
} | ||
/** | ||
* Get the instance. | ||
* @return EnvironmentVariablesService | ||
*/ | ||
public static EnvironmentVariablesService getInstance() { | ||
|
||
return EnvironmentVariablesService.SingletonHolder.INSTANCE; | ||
} // getInstance. | ||
|
||
private final Map<String, String> envMap = new ConcurrentHashMap<>(); | ||
private EnvironmentVariablesService() { | ||
|
||
System.getenv().entrySet().stream() | ||
.forEach(e -> envMap.put(e.getKey(), e.getValue())); | ||
} | ||
|
||
@VisibleForTesting | ||
public EnvironmentVariablesService put (final String envKey, final String envValue) { | ||
|
||
// todo: add condition if profile is test, allows | ||
Optional.ofNullable(envValue).ifPresent(v -> this.envMap.put(envKey, envValue)); | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns the environment map | ||
* @return Map | ||
*/ | ||
public Map<String, String> getenv() { | ||
|
||
return this.envMap; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters