Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-217] Restructure part 2: Remove configuration APIs #214

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions core/src/main/java/org/jboss/logmanager/Configurator.java

This file was deleted.

102 changes: 9 additions & 93 deletions core/src/main/java/org/jboss/logmanager/LogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.logging.Filter;
Expand Down Expand Up @@ -84,99 +81,20 @@ public LogManager() {

// Configuration

private final AtomicBoolean configured = new AtomicBoolean();

private static String tryGetProperty(String name, String defaultVal) {
try {
return System.getProperty(name, defaultVal);
} catch (Throwable t) {
return defaultVal;
}
}

/**
* Configure the log manager one time. An implementation of {@link ConfigurationLocator} is created by constructing an
* instance of the class name specified in the {@code org.jboss.logmanager.configurationLocator} system property.
* Do nothing. Log contexts are configured on construction.
*/
public void readConfiguration() throws IOException, SecurityException {
checkAccess();
if (configured.getAndSet(true)) {
return;
}
final String confLocClassName = tryGetProperty("org.jboss.logmanager.configurationLocator", null);
ConfigurationLocator locator = null;
if (confLocClassName != null) {
locator = construct(ConfigurationLocator.class, confLocClassName);
} else {
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
if (tccl != null) {
final ServiceLoader<ConfigurationLocator> loader = ServiceLoader.load(ConfigurationLocator.class, tccl);
final Iterator<ConfigurationLocator> iterator = loader.iterator();
if (iterator.hasNext()) {
locator = iterator.next();
}
}
if (locator == null) {
final ServiceLoader<ConfigurationLocator> loader = ServiceLoader.load(ConfigurationLocator.class, tccl != null ? tccl : LogManager.class.getClassLoader());
final Iterator<ConfigurationLocator> iterator = loader.iterator();
if (iterator.hasNext()) {
locator = iterator.next();
} else {
locator = new DefaultConfigurationLocator();
}
}
}
if (locator != null) {
final InputStream configuration = locator.findConfiguration();
if (configuration != null) {
readConfiguration(configuration);
}
}
public void readConfiguration() {
// on operation
}

/**
* Configure the log manager.
* Do nothing. Log contexts are configured on construction.
*
* @param inputStream the input stream from which the logmanager should be configured
* @param inputStream ignored
*/
public void readConfiguration(InputStream inputStream) throws IOException, SecurityException {
try {
checkAccess();
configured.set(true);
final String confClassName = tryGetProperty("org.jboss.logmanager.configurator", null);
Configurator configurator = null;
if (confClassName != null) {
configurator = construct(Configurator.class, confClassName);
} else {
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
if (tccl != null) {
final ServiceLoader<Configurator> loader = ServiceLoader.load(Configurator.class, tccl);
final Iterator<Configurator> iterator = loader.iterator();
if (iterator.hasNext()) {
configurator = iterator.next();
}
}
if (configurator == null) {
final ServiceLoader<Configurator> loader = ServiceLoader.load(Configurator.class, LogManager.class.getClassLoader());
final Iterator<Configurator> iterator = loader.iterator();
if (iterator.hasNext()) {
configurator = iterator.next();
} else {
configurator = new PropertyConfigurator();
}
}
}
if (configurator != null) try {
configurator.configure(inputStream);
LogContext.getSystemLogContext().getLogger("").attach(Configurator.ATTACHMENT_KEY, configurator);
} catch (Throwable t) {
StandardOutputStreams.printError(t, "Failed to read or configure the org.jboss.logmanager.LogManager");
}
} finally {
try {
inputStream.close();
} catch (Throwable ignored) {}
}
public void readConfiguration(InputStream inputStream) {
// on operation
}

static <T> T construct(Class<? extends T> type, String className) throws IOException {
Expand Down Expand Up @@ -217,8 +135,7 @@ public void removePropertyChangeListener(PropertyChangeListener l) {
}

/**
* Does nothing. The {@linkplain org.jboss.logmanager.config.LogContextConfiguration configuration API} should be
* used.
* Does nothing.
*
* @param mapper not used
*/
Expand All @@ -227,8 +144,7 @@ public void updateConfiguration(final Function<String, BiFunction<String, String
}

/**
* Does nothing. The {@linkplain org.jboss.logmanager.config.LogContextConfiguration configuration API} should be
* used.
* Does nothing.
*
* @param ins not used
* @param mapper not used
Expand Down
Loading