Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RESTEASY-3247] Use a singleton ConfigurationFactory to avoid too man…
…y lookups of the factory. Signed-off-by: James R. Perkins <jperkins@redhat.com>
- Loading branch information
Showing
7 changed files
with
90 additions
and
103 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
67 changes: 67 additions & 0 deletions
67
...y-core-spi/src/main/java/org/jboss/resteasy/spi/config/SingletonConfigurationFactory.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,67 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2022 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jboss.resteasy.spi.config; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* Loads the {@link ConfigurationFactory} lazily during instantiation. | ||
* | ||
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> | ||
*/ | ||
class SingletonConfigurationFactory { | ||
|
||
/** | ||
* Returns the lazily created {@link ConfigurationFactory}. | ||
* | ||
* @return the configuration factory found | ||
*/ | ||
static ConfigurationFactory getInstance() { | ||
return Holder.INSTANCE; | ||
} | ||
|
||
private static class Holder { | ||
static final ConfigurationFactory INSTANCE; | ||
|
||
static { | ||
final PrivilegedAction<ConfigurationFactory> action = () -> { | ||
// We must use this class loader for environments where the TCCL might pick up an instance from a source | ||
// that is not meant to be shared. | ||
final ServiceLoader<ConfigurationFactory> loader = ServiceLoader.load(ConfigurationFactory.class, Holder.class.getClassLoader()); | ||
ConfigurationFactory current = null; | ||
for (ConfigurationFactory factory : loader) { | ||
if (current == null) { | ||
current = factory; | ||
} else if (factory.priority() < current.priority()) { | ||
current = factory; | ||
} | ||
} | ||
return current == null ? () -> Integer.MAX_VALUE : current; | ||
}; | ||
if (System.getSecurityManager() == null) { | ||
INSTANCE = action.run(); | ||
} else { | ||
INSTANCE = AccessController.doPrivileged(action); | ||
} | ||
} | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
resteasy-core/src/main/java/org/jboss/resteasy/core/config/DefaultConfigurationFactory.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
...e/src/main/resources/META-INF/services/org.jboss.resteasy.spi.config.ConfigurationFactory
This file was deleted.
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