-
-
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 #95 from hkupty/improve-tests
Restructure penna-api
- Loading branch information
Showing
33 changed files
with
313 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=0.8.0-rc1 | ||
version=0.8.0-rc2 |
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
60 changes: 60 additions & 0 deletions
60
penna-api/src/main/java/penna/api/config/internal/ManagerImpl.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,60 @@ | ||
package penna.api.config.internal; | ||
|
||
import penna.api.config.ConfigToLogger; | ||
import penna.api.config.Manager; | ||
import penna.api.config.Provider; | ||
import penna.api.config.Storage; | ||
import penna.api.models.Config; | ||
|
||
import java.util.ServiceLoader; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* This is the central piece of the configuration management. | ||
* It should not be created manually, but instead through {@link Manager#create(Storage)}. | ||
*/ | ||
public final class ManagerImpl implements Manager { | ||
/** | ||
* The service loader for Providers | ||
*/ | ||
public static final ServiceLoader<Provider> loader = ServiceLoader.load(Provider.class); | ||
|
||
private final Storage storage; | ||
|
||
/** | ||
* Initializes the Manager with an instance of {@link Storage} | ||
* @param storage The component that stores loggers and the respective configuration | ||
*/ | ||
public ManagerImpl(Storage storage) { | ||
this.storage = storage; | ||
} | ||
|
||
@Override | ||
public void set(ConfigToLogger... configs) { | ||
storage.apply(configs); | ||
} | ||
|
||
@Override | ||
public void set(String logger, Supplier<Config> action) { | ||
Config config = action.get(); | ||
ConfigToLogger item = switch (logger) { | ||
case String path when path.isEmpty() -> new ConfigToLogger.RootLoggerConfigItem(config); | ||
case String path -> new ConfigToLogger.NamedLoggerConfigItem(path, config); | ||
}; | ||
|
||
storage.apply(item); | ||
} | ||
|
||
@Override | ||
public void update(String logger, Function<Config, Config> action) { | ||
var current = storage.get(logger); | ||
Config config = action.apply(current); | ||
ConfigToLogger item = switch (logger) { | ||
case String path when path.isEmpty() -> new ConfigToLogger.RootLoggerConfigItem(config); | ||
case String path -> new ConfigToLogger.NamedLoggerConfigItem(path, config); | ||
}; | ||
|
||
storage.apply(item); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
...rc/main/java/penna/api/config/Config.java → ...rc/main/java/penna/api/models/Config.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
2 changes: 1 addition & 1 deletion
2
...a/penna/api/config/ExceptionHandling.java → ...a/penna/api/models/ExceptionHandling.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
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
36 changes: 36 additions & 0 deletions
36
penna-core/src/main/java/penna/core/api/LoggerController.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,36 @@ | ||
package penna.core.api; | ||
|
||
import org.slf4j.event.Level; | ||
import penna.api.config.Manager; | ||
import penna.api.config.Provider; | ||
import penna.core.internals.ManagerHolder; | ||
|
||
/** | ||
* This is class provides the runtime with a façade for simple runtime control over the loggers. | ||
* For a finer level of control, resort to implementing a custom {@link Provider} instead. | ||
*/ | ||
public class LoggerController { | ||
|
||
private LoggerController() {} | ||
|
||
/** | ||
* Convenience runtime function for changing the logger level. | ||
* For a finer level of control, resort to implementing a custom {@link Provider} | ||
* @param loggerName Name of the logger (or prefix of the logger) for the level change | ||
* @param level The target level for supplied logger | ||
*/ | ||
public static void changeLoggerLevel(String loggerName, Level level) { | ||
Manager instance; | ||
if ((instance = ManagerHolder.getInstance()) != null) { | ||
instance.update(loggerName, config -> config.replaceLevel(level)); | ||
} | ||
} | ||
|
||
/** | ||
* Convenience runtime function for changing the logger level. | ||
* For a finer level of control, resort to implementing a custom {@link Provider} | ||
* @param klass The class whose name is assigned to the logger | ||
* @param level The target level for supplied logger | ||
*/ | ||
public static void changeLoggerLevel(Class<?> klass, Level level) { changeLoggerLevel(klass.getName(), level);} | ||
} |
26 changes: 26 additions & 0 deletions
26
penna-core/src/main/java/penna/core/internals/ManagerHolder.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,26 @@ | ||
package penna.core.internals; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import penna.api.config.Manager; | ||
|
||
/** | ||
* This class exists as a middle ground for both the concrete implementation and the {@link Manager} | ||
* so the creation of the Manager instance, which happens at the concrete implementation during runtime, can | ||
* still provide the Manager's interface with an instance for its static methods. | ||
*/ | ||
public class ManagerHolder { | ||
private ManagerHolder() {} | ||
private static Manager instance; | ||
|
||
/** | ||
* After creating an instance, this method should be called to store it for "global" availability; | ||
* @param manager The concrete {@link Manager} instance. | ||
*/ | ||
public static void setManager(Manager manager) { instance = manager; } | ||
|
||
/** | ||
* Returns the stored Manager. | ||
* @return the stored Manager. | ||
*/ | ||
public static @Nullable Manager getInstance() { return instance; } | ||
} |
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.