-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from hkupty/mdc-write-safety
MDC: Replace internal implementation
- Loading branch information
Showing
12 changed files
with
470 additions
and
369 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
31 changes: 0 additions & 31 deletions
31
penna-core/src/main/java/penna/core/internals/MapWrapperRingBuffer.java
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
penna-core/src/main/java/penna/core/internals/MapWrapperTicket.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
penna-core/src/main/java/penna/core/internals/store/StringMap.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,11 @@ | ||
package penna.core.internals.store; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* The internal MDC implementation assumes a {@link Map} of Strings to String, so this interface | ||
* exists to ensure we can experiment and replace implementations without breaking SLF4J's binding implementation | ||
*/ | ||
public sealed interface StringMap extends Map<String, String> permits StringTreeMap { | ||
StringMap copy(); | ||
} |
29 changes: 29 additions & 0 deletions
29
penna-core/src/main/java/penna/core/internals/store/StringTreeMap.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,29 @@ | ||
package penna.core.internals.store; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* Simple wrapper over {@link TreeMap} just to provide two basic guarantees: | ||
* - We control the copying of the map; | ||
* - We control the initialization; | ||
* <br /> | ||
* This is not strictly necessary, but it is a very performant implementation of {@link StringMap}, | ||
* which is our goal. | ||
*/ | ||
public final class StringTreeMap extends TreeMap<String, String> implements StringMap { | ||
|
||
public StringTreeMap() { | ||
super(); | ||
} | ||
|
||
public StringTreeMap(Map<? extends String, ? extends String> m) { | ||
super(); | ||
super.putAll(m); | ||
} | ||
|
||
@Override | ||
public StringMap copy() { | ||
return new StringTreeMap(this); | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
penna-core/src/main/java/penna/core/slf4j/mdc/EmptyMdc.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,93 @@ | ||
package penna.core.slf4j.mdc; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import penna.core.internals.store.StringTreeMap; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
|
||
public final class EmptyMdc implements Mdc { | ||
@Override | ||
public String put(String key, String val) { | ||
var inner = new StringTreeMap(); | ||
inner.put(key, val); | ||
Control.mdcStorage.set(new MdcStorage(inner)); | ||
return key; | ||
} | ||
|
||
@Override | ||
public String remove(Object key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void putAll(@NotNull Map<? extends String, ? extends String> m) { | ||
Control.mdcStorage.set(new MdcStorage(new StringTreeMap(m))); | ||
} | ||
|
||
@Override | ||
public void clear() {} | ||
|
||
@NotNull | ||
@Override | ||
public Set<String> keySet() { | ||
return Set.of(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<String> values() { | ||
return List.of(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Set<Entry<String, String>> entrySet() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public boolean isNotEmpty() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void remove(String key) {} | ||
|
||
@Override | ||
public boolean isEmpty() {return true;} | ||
|
||
@Override | ||
public boolean containsKey(Object key) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean containsValue(Object value) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String get(Object key) {return null;} | ||
|
||
@Override | ||
public void forEach(BiConsumer<? super String, ? super String> action) {} | ||
|
||
@Override | ||
public String get(String key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getCopyOfContextMap() { | ||
return this; | ||
} | ||
} |
Oops, something went wrong.