-
Notifications
You must be signed in to change notification settings - Fork 35
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 #530 from swisspost/feature/appender_repository
#529 EventBusAppender instance pollution in Java Heap Space
- Loading branch information
Showing
21 changed files
with
308 additions
and
67 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
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
45 changes: 45 additions & 0 deletions
45
...en-logging/src/main/java/org/swisspush/gateleen/logging/DefaultLogAppenderRepository.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,45 @@ | ||
package org.swisspush.gateleen.logging; | ||
|
||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.eventbus.Message; | ||
import org.apache.logging.log4j.core.Appender; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.swisspush.gateleen.logging.LoggingResourceManager.UPDATE_ADDRESS; | ||
|
||
/** | ||
* Default implementation of the {@link LogAppenderRepository} caching the {@link Appender} instances in a {@link Map} | ||
* | ||
* @author https://github.com/mcweba [Marc-Andre Weber] | ||
*/ | ||
public class DefaultLogAppenderRepository implements LogAppenderRepository { | ||
|
||
private Map<String, Appender> appenderMap = new HashMap<>(); | ||
|
||
public DefaultLogAppenderRepository(Vertx vertx) { | ||
vertx.eventBus().consumer(UPDATE_ADDRESS, (Handler<Message<Boolean>>) event -> clearRepository()); | ||
} | ||
|
||
@Override | ||
public boolean hasAppender(String name) { | ||
return appenderMap.containsKey(name); | ||
} | ||
|
||
@Override | ||
public void addAppender(String name, Appender appender) { | ||
appenderMap.put(name, appender); | ||
} | ||
|
||
@Override | ||
public Appender getAppender(String name) { | ||
return appenderMap.get(name); | ||
} | ||
|
||
@Override | ||
public void clearRepository() { | ||
appenderMap.clear(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LogAppenderRepository.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,20 @@ | ||
package org.swisspush.gateleen.logging; | ||
|
||
import org.apache.logging.log4j.core.Appender; | ||
|
||
/** | ||
* A repository holding {@link Appender} instances. The repository allows to reuse an appender | ||
* instead of creating a new one for every log statement | ||
* | ||
* @author https://github.com/mcweba [Marc-Andre Weber] | ||
*/ | ||
public interface LogAppenderRepository { | ||
|
||
boolean hasAppender(String name); | ||
|
||
void addAppender(String name, Appender appender); | ||
|
||
Appender getAppender(String name); | ||
|
||
void clearRepository(); | ||
} |
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
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
Oops, something went wrong.