Here are the examples of the java api @org.springframework.lang.UsesJava7 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
12 Examples
19
Source : OverridingClassLoader.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* {@code ClreplacedLoader} that does <i>not</i> always delegate to the
* parent loader, as normal clreplaced loaders do. This enables, for example,
* instrumentation to be forced in the overriding ClreplacedLoader, or a
* "throwaway" clreplaced loading behavior, where selected clreplacedes are
* temporarily loaded in the overriding ClreplacedLoader, in order to load
* an instrumented version of the clreplaced in the parent ClreplacedLoader later on.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 2.0.1
*/
@UsesJava7
public clreplaced OverridingClreplacedLoader extends DecoratingClreplacedLoader {
/**
* Packages that are excluded by default
*/
public static final String[] DEFAULT_EXCLUDED_PACKAGES = new String[] { "java.", "javax.", "sun.", "oracle." };
private static final String CLreplaced_FILE_SUFFIX = ".clreplaced";
static {
if (parallelCapableClreplacedLoaderAvailable) {
ClreplacedLoader.registerAsParallelCapable();
}
}
/**
* Create a new OverridingClreplacedLoader for the given ClreplacedLoader.
* @param parent the ClreplacedLoader to build an overriding ClreplacedLoader for
*/
public OverridingClreplacedLoader(ClreplacedLoader parent) {
super(parent);
for (String packageName : DEFAULT_EXCLUDED_PACKAGES) {
excludePackage(packageName);
}
}
@Override
protected Clreplaced<?> loadClreplaced(String name, boolean resolve) throws ClreplacedNotFoundException {
Clreplaced<?> result = null;
if (isEligibleForOverriding(name)) {
result = loadClreplacedForOverriding(name);
}
if (result != null) {
if (resolve) {
resolveClreplaced(result);
}
return result;
} else {
return super.loadClreplaced(name, resolve);
}
}
/**
* Determine whether the specified clreplaced is eligible for overriding
* by this clreplaced loader.
* @param clreplacedName the clreplaced name to check
* @return whether the specified clreplaced is eligible
* @see #isExcluded
*/
protected boolean isEligibleForOverriding(String clreplacedName) {
return !isExcluded(clreplacedName);
}
/**
* Load the specified clreplaced for overriding purposes in this ClreplacedLoader.
* <p>The default implementation delegates to {@link #findLoadedClreplaced},
* {@link #loadBytesForClreplaced} and {@link #defineClreplaced}.
* @param name the name of the clreplaced
* @return the Clreplaced object, or {@code null} if no clreplaced defined for that name
* @throws ClreplacedNotFoundException if the clreplaced for the given name couldn't be loaded
*/
protected Clreplaced<?> loadClreplacedForOverriding(String name) throws ClreplacedNotFoundException {
Clreplaced<?> result = findLoadedClreplaced(name);
if (result == null) {
byte[] bytes = loadBytesForClreplaced(name);
if (bytes != null) {
result = defineClreplaced(name, bytes, 0, bytes.length);
}
}
return result;
}
/**
* Load the defining bytes for the given clreplaced,
* to be turned into a Clreplaced object through a {@link #defineClreplaced} call.
* <p>The default implementation delegates to {@link #openStreamForClreplaced}
* and {@link #transformIfNecessary}.
* @param name the name of the clreplaced
* @return the byte content (with transformers already applied),
* or {@code null} if no clreplaced defined for that name
* @throws ClreplacedNotFoundException if the clreplaced for the given name couldn't be loaded
*/
protected byte[] loadBytesForClreplaced(String name) throws ClreplacedNotFoundException {
InputStream is = openStreamForClreplaced(name);
if (is == null) {
return null;
}
try {
// Load the raw bytes.
byte[] bytes = FileCopyUtils.copyToByteArray(is);
// Transform if necessary and use the potentially transformed bytes.
return transformIfNecessary(name, bytes);
} catch (IOException ex) {
throw new ClreplacedNotFoundException("Cannot load resource for clreplaced [" + name + "]", ex);
}
}
/**
* Open an InputStream for the specified clreplaced.
* <p>The default implementation loads a standard clreplaced file through
* the parent ClreplacedLoader's {@code getResourcereplacedtream} method.
* @param name the name of the clreplaced
* @return the InputStream containing the byte code for the specified clreplaced
*/
protected InputStream openStreamForClreplaced(String name) {
String internalName = name.replace('.', '/') + CLreplaced_FILE_SUFFIX;
return getParent().getResourcereplacedtream(internalName);
}
/**
* Transformation hook to be implemented by subclreplacedes.
* <p>The default implementation simply returns the given bytes as-is.
* @param name the fully-qualified name of the clreplaced being transformed
* @param bytes the raw bytes of the clreplaced
* @return the transformed bytes (never {@code null};
* same as the input bytes if the transformation produced no changes)
*/
protected byte[] transformIfNecessary(String name, byte[] bytes) {
return bytes;
}
}
19
Source : PathResource.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* {@link Resource} implementation for {@code java.nio.file.Path} handles.
* Supports resolution as File, and also as URL.
* Implements the extended {@link WritableResource} interface.
*
* @author Philippe Marschall
* @author Juergen Hoeller
* @since 4.0
* @see java.nio.file.Path
*/
@UsesJava7
public clreplaced PathResource extends AbstractResource implements WritableResource {
private final Path path;
/**
* Create a new PathResource from a Path handle.
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root:
* e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
* @param path a Path handle
*/
public PathResource(Path path) {
replacedert.notNull(path, "Path must not be null");
this.path = path.normalize();
}
/**
* Create a new PathResource from a Path handle.
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root:
* e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
* @param path a path
* @see java.nio.file.Paths#get(String, String...)
*/
public PathResource(String path) {
replacedert.notNull(path, "Path must not be null");
this.path = Paths.get(path).normalize();
}
/**
* Create a new PathResource from a Path handle.
* <p>Note: Unlike {@link FileSystemResource}, when building relative resources
* via {@link #createRelative}, the relative path will be built <i>underneath</i>
* the given root:
* e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
* @see java.nio.file.Paths#get(URI)
* @param uri a path URI
*/
public PathResource(URI uri) {
replacedert.notNull(uri, "URI must not be null");
this.path = Paths.get(uri).normalize();
}
/**
* Return the file path for this resource.
*/
public final String getPath() {
return this.path.toString();
}
/**
* This implementation returns whether the underlying file exists.
* @see org.springframework.core.io.PathResource#exists()
*/
@Override
public boolean exists() {
return Files.exists(this.path);
}
/**
* This implementation checks whether the underlying file is marked as readable
* (and corresponds to an actual file with content, not to a directory).
* @see java.nio.file.Files#isReadable(Path)
* @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
*/
@Override
public boolean isReadable() {
return (Files.isReadable(this.path) && !Files.isDirectory(this.path));
}
/**
* This implementation opens a InputStream for the underlying file.
* @see java.nio.file.spi.FileSystemProvider#newInputStream(Path, OpenOption...)
*/
@Override
public InputStream getInputStream() throws IOException {
if (!exists()) {
throw new FileNotFoundException(getPath() + " (no such file or directory)");
}
if (Files.isDirectory(this.path)) {
throw new FileNotFoundException(getPath() + " (is a directory)");
}
return Files.newInputStream(this.path);
}
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.nio.file.Files#isWritable(Path)
* @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
*/
@Override
public boolean isWritable() {
return (Files.isWritable(this.path) && !Files.isDirectory(this.path));
}
/**
* This implementation opens a OutputStream for the underlying file.
* @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...)
*/
@Override
public OutputStream getOutputStream() throws IOException {
if (Files.isDirectory(this.path)) {
throw new FileNotFoundException(getPath() + " (is a directory)");
}
return Files.newOutputStream(this.path);
}
/**
* This implementation returns a URL for the underlying file.
* @see java.nio.file.Path#toUri()
* @see java.net.URI#toURL()
*/
@Override
public URL getURL() throws IOException {
return this.path.toUri().toURL();
}
/**
* This implementation returns a URI for the underlying file.
* @see java.nio.file.Path#toUri()
*/
@Override
public URI getURI() throws IOException {
return this.path.toUri();
}
/**
* This implementation returns the underlying File reference.
*/
@Override
public File getFile() throws IOException {
try {
return this.path.toFile();
} catch (UnsupportedOperationException ex) {
// only Paths on the default file system can be converted to a File
// do exception translation for cases where conversion is not possible
throw new FileNotFoundException(this.path + " cannot be resolved to " + "absolute file path");
}
}
/**
* This implementation returns the underlying File's length.
*/
@Override
public long contentLength() throws IOException {
return Files.size(this.path);
}
/**
* This implementation returns the underlying File's timestamp.
* @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...)
*/
@Override
public long lastModified() throws IOException {
// We can not use the superclreplaced method since it uses conversion to a File and
// only a Path on the default file system can be converted to a File...
return Files.getLastModifiedTime(path).toMillis();
}
/**
* This implementation creates a FileResource, applying the given path
* relative to the path of the underlying file of this resource descriptor.
* @see java.nio.file.Path#resolve(String)
*/
@Override
public Resource createRelative(String relativePath) throws IOException {
return new PathResource(this.path.resolve(relativePath));
}
/**
* This implementation returns the name of the file.
* @see java.nio.file.Path#getFileName()
*/
@Override
public String getFilename() {
return this.path.getFileName().toString();
}
@Override
public String getDescription() {
return "path [" + this.path.toAbsolutePath() + "]";
}
/**
* This implementation compares the underlying Path references.
*/
@Override
public boolean equals(Object obj) {
return (this == obj || (obj instanceof PathResource && this.path.equals(((PathResource) obj).path)));
}
/**
* This implementation returns the hash code of the underlying Path reference.
*/
@Override
public int hashCode() {
return this.path.hashCode();
}
}
19
Source : ThreadPoolTaskScheduler.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Return the current setting for the remove-on-cancel mode.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
*/
@UsesJava7
public boolean isRemoveOnCancelPolicy() {
if (!setRemoveOnCancelPolicyAvailable) {
return false;
}
if (this.scheduledExecutor == null) {
// Not initialized yet: return our setting for the time being.
return this.removeOnCancelPolicy;
}
return getScheduledThreadPoolExecutor().getRemoveOnCancelPolicy();
}
19
Source : ThreadPoolTaskScheduler.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Set the remove-on-cancel mode on {@link ScheduledThreadPoolExecutor} (JDK 7+).
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
* switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
*/
@UsesJava7
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
this.removeOnCancelPolicy = removeOnCancelPolicy;
if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
} else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
}
}
19
Source : SimpleThrowawayClassLoader.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* ClreplacedLoader that can be used to load clreplacedes without bringing them
* into the parent loader. Intended to support JPA "temp clreplaced loader"
* requirement, but not JPA-specific.
*
* @author Rod Johnson
* @since 2.0
*/
@UsesJava7
public clreplaced SimpleThrowawayClreplacedLoader extends OverridingClreplacedLoader {
static {
if (parallelCapableClreplacedLoaderAvailable) {
ClreplacedLoader.registerAsParallelCapable();
}
}
/**
* Create a new SimpleThrowawayClreplacedLoader for the given ClreplacedLoader.
* @param parent the ClreplacedLoader to build a throwaway ClreplacedLoader for
*/
public SimpleThrowawayClreplacedLoader(ClreplacedLoader parent) {
super(parent);
}
}
19
Source : SimpleInstrumentableClassLoader.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Simplistic implementation of an instrumentable {@code ClreplacedLoader}.
*
* <p>Usable in tests and standalone environments.
*
* @author Rod Johnson
* @author Costin Leau
* @since 2.0
*/
@UsesJava7
public clreplaced SimpleInstrumentableClreplacedLoader extends OverridingClreplacedLoader {
static {
if (parallelCapableClreplacedLoaderAvailable) {
ClreplacedLoader.registerAsParallelCapable();
}
}
private final WeavingTransformer weavingTransformer;
/**
* Create a new SimpleInstrumentableClreplacedLoader for the given ClreplacedLoader.
* @param parent the ClreplacedLoader to build an instrumentable ClreplacedLoader for
*/
public SimpleInstrumentableClreplacedLoader(ClreplacedLoader parent) {
super(parent);
this.weavingTransformer = new WeavingTransformer(parent);
}
/**
* Add a {@link ClreplacedFileTransformer} to be applied by this ClreplacedLoader.
* @param transformer the {@link ClreplacedFileTransformer} to register
*/
public void addTransformer(ClreplacedFileTransformer transformer) {
this.weavingTransformer.addTransformer(transformer);
}
@Override
protected byte[] transformIfNecessary(String name, byte[] bytes) {
return this.weavingTransformer.transformIfNecessary(name, bytes);
}
}
18
Source : ResultSetWrappingSqlRowSet.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* @see java.sql.ResultSet#getObject(int, Clreplaced)
*/
@UsesJava7
@Override
public <T> T getObject(int columnIndex, Clreplaced<T> type) throws InvalidResultSetAccessException {
try {
return this.resultSet.getObject(columnIndex, type);
} catch (SQLException se) {
throw new InvalidResultSetAccessException(se);
}
}
18
Source : DecoratingClassLoader.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Base clreplaced for decorating ClreplacedLoaders such as {@link OverridingClreplacedLoader}
* and {@link org.springframework.instrument.clreplacedloading.ShadowingClreplacedLoader},
* providing common handling of excluded packages and clreplacedes.
*
* @author Juergen Hoeller
* @author Rod Johnson
* @since 2.5.2
*/
@UsesJava7
public abstract clreplaced DecoratingClreplacedLoader extends ClreplacedLoader {
/**
* Java 7+ {@code ClreplacedLoader.registerAsParallelCapable()} available?
* @since 4.1.2
*/
protected static final boolean parallelCapableClreplacedLoaderAvailable = ClreplacedUtils.hasMethod(ClreplacedLoader.clreplaced, "registerAsParallelCapable");
static {
if (parallelCapableClreplacedLoaderAvailable) {
ClreplacedLoader.registerAsParallelCapable();
}
}
private final Set<String> excludedPackages = new HashSet<String>();
private final Set<String> excludedClreplacedes = new HashSet<String>();
private final Object exclusionMonitor = new Object();
/**
* Create a new DecoratingClreplacedLoader with no parent ClreplacedLoader.
*/
public DecoratingClreplacedLoader() {
}
/**
* Create a new DecoratingClreplacedLoader using the given parent ClreplacedLoader
* for delegation.
*/
public DecoratingClreplacedLoader(ClreplacedLoader parent) {
super(parent);
}
/**
* Add a package name to exclude from decoration (e.g. overriding).
* <p>Any clreplaced whose fully-qualified name starts with the name registered
* here will be handled by the parent ClreplacedLoader in the usual fashion.
* @param packageName the package name to exclude
*/
public void excludePackage(String packageName) {
replacedert.notNull(packageName, "Package name must not be null");
synchronized (this.exclusionMonitor) {
this.excludedPackages.add(packageName);
}
}
/**
* Add a clreplaced name to exclude from decoration (e.g. overriding).
* <p>Any clreplaced name registered here will be handled by the parent
* ClreplacedLoader in the usual fashion.
* @param clreplacedName the clreplaced name to exclude
*/
public void excludeClreplaced(String clreplacedName) {
replacedert.notNull(clreplacedName, "Clreplaced name must not be null");
synchronized (this.exclusionMonitor) {
this.excludedClreplacedes.add(clreplacedName);
}
}
/**
* Determine whether the specified clreplaced is excluded from decoration
* by this clreplaced loader.
* <p>The default implementation checks against excluded packages and clreplacedes.
* @param clreplacedName the clreplaced name to check
* @return whether the specified clreplaced is eligible
* @see #excludePackage
* @see #excludeClreplaced
*/
protected boolean isExcluded(String clreplacedName) {
synchronized (this.exclusionMonitor) {
if (this.excludedClreplacedes.contains(clreplacedName)) {
return true;
}
for (String packageName : this.excludedPackages) {
if (clreplacedName.startsWith(packageName)) {
return true;
}
}
}
return false;
}
}
18
Source : ForkJoinPoolFactoryBean.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* A Spring {@link FactoryBean} that builds and exposes a preconfigured {@link ForkJoinPool}.
* May be used on Java 7 and 8 as well as on Java 6 with {@code jsr166.jar} on the clreplacedpath
* (ideally on the VM bootstrap clreplacedpath).
*
* <p>For details on the ForkJoinPool API and its use with RecursiveActions, see the
* <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html">JDK 7 javadoc</a>.
*
* <p>{@code jsr166.jar}, containing {@code java.util.concurrent} updates for Java 6, can be obtained
* from the <a href="http://gee.cs.oswego.edu/dl/concurrency-interest/">concurrency interest website</a>.
*
* @author Juergen Hoeller
* @since 3.1
*/
@UsesJava7
public clreplaced ForkJoinPoolFactoryBean implements FactoryBean<ForkJoinPool>, InitializingBean, DisposableBean {
private boolean commonPool = false;
private int parallelism = Runtime.getRuntime().availableProcessors();
private ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = ForkJoinPool.defaultForkJoinWorkerThreadFactory;
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
private boolean asyncMode = false;
private int awaitTerminationSeconds = 0;
private ForkJoinPool forkJoinPool;
/**
* Set whether to expose JDK 8's 'common' {@link ForkJoinPool}.
* <p>Default is "false", creating a local {@link ForkJoinPool} instance based on the
* {@link #setParallelism "parallelism"}, {@link #setThreadFactory "threadFactory"},
* {@link #setUncaughtExceptionHandler "uncaughtExceptionHandler"} and
* {@link #setAsyncMode "asyncMode"} properties on this FactoryBean.
* <p><b>NOTE:</b> Setting this flag to "true" effectively ignores all other
* properties on this FactoryBean, reusing the shared common JDK {@link ForkJoinPool}
* instead. This is a fine choice on JDK 8 but does remove the application's ability
* to customize ForkJoinPool behavior, in particular the use of custom threads.
* @since 3.2
* @see java.util.concurrent.ForkJoinPool#commonPool()
*/
public void setCommonPool(boolean commonPool) {
this.commonPool = commonPool;
}
/**
* Specify the parallelism level. Default is {@link Runtime#availableProcessors()}.
*/
public void setParallelism(int parallelism) {
this.parallelism = parallelism;
}
/**
* Set the factory for creating new ForkJoinWorkerThreads.
* Default is {@link ForkJoinPool#defaultForkJoinWorkerThreadFactory}.
*/
public void setThreadFactory(ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory) {
this.threadFactory = threadFactory;
}
/**
* Set the handler for internal worker threads that terminate due to unrecoverable errors
* encountered while executing tasks. Default is none.
*/
public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
this.uncaughtExceptionHandler = uncaughtExceptionHandler;
}
/**
* Specify whether to establish a local first-in-first-out scheduling mode for forked tasks
* that are never joined. This mode (asyncMode = {@code true}) may be more appropriate
* than the default locally stack-based mode in applications in which worker threads only
* process event-style asynchronous tasks. Default is {@code false}.
*/
public void setAsyncMode(boolean asyncMode) {
this.asyncMode = asyncMode;
}
/**
* Set the maximum number of seconds that this ForkJoinPool is supposed to block
* on shutdown in order to wait for remaining tasks to complete their execution
* before the rest of the container continues to shut down. This is particularly
* useful if your remaining tasks are likely to need access to other resources
* that are also managed by the container.
* <p>By default, this ForkJoinPool won't wait for the termination of tasks at all.
* It will continue to fully execute all ongoing tasks as well as all remaining
* tasks in the queue, in parallel to the rest of the container shutting down.
* In contrast, if you specify an await-termination period using this property,
* this executor will wait for the given time (max) for the termination of tasks.
* <p>Note that this feature works for the {@link #setCommonPool "commonPool"}
* mode as well. The underlying ForkJoinPool won't actually terminate in that
* case but will wait for all tasks to terminate.
* @see java.util.concurrent.ForkJoinPool#shutdown()
* @see java.util.concurrent.ForkJoinPool#awaitTermination
*/
public void setAwaitTerminationSeconds(int awaitTerminationSeconds) {
this.awaitTerminationSeconds = awaitTerminationSeconds;
}
@Override
public void afterPropertiesSet() {
this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() : new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode));
}
@Override
public ForkJoinPool getObject() {
return this.forkJoinPool;
}
@Override
public Clreplaced<?> getObjectType() {
return ForkJoinPool.clreplaced;
}
@Override
public boolean isSingleton() {
return true;
}
@Override
public void destroy() {
// Ignored for the common pool.
this.forkJoinPool.shutdown();
// Wait for all tasks to terminate - works for the common pool as well.
if (this.awaitTerminationSeconds > 0) {
try {
this.forkJoinPool.awaitTermination(this.awaitTerminationSeconds, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
18
Source : ContextTypeMatchClassLoader.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Special variant of an overriding ClreplacedLoader, used for temporary type
* matching in {@link AbstractApplicationContext}. Redefines clreplacedes from
* a cached byte array for every {@code loadClreplaced} call in order to
* pick up recently loaded types in the parent ClreplacedLoader.
*
* @author Juergen Hoeller
* @since 2.5
* @see AbstractApplicationContext
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#setTempClreplacedLoader
*/
@UsesJava7
clreplaced ContextTypeMatchClreplacedLoader extends DecoratingClreplacedLoader implements SmartClreplacedLoader {
static {
if (parallelCapableClreplacedLoaderAvailable) {
ClreplacedLoader.registerAsParallelCapable();
}
}
private static Method findLoadedClreplacedMethod;
static {
try {
findLoadedClreplacedMethod = ClreplacedLoader.clreplaced.getDeclaredMethod("findLoadedClreplaced", String.clreplaced);
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("Invalid [java.lang.ClreplacedLoader] clreplaced: no 'findLoadedClreplaced' method defined!");
}
}
/**
* Cache for byte array per clreplaced name
*/
private final Map<String, byte[]> bytesCache = new ConcurrentHashMap<String, byte[]>(256);
public ContextTypeMatchClreplacedLoader(ClreplacedLoader parent) {
super(parent);
}
@Override
public Clreplaced<?> loadClreplaced(String name) throws ClreplacedNotFoundException {
return new ContextOverridingClreplacedLoader(getParent()).loadClreplaced(name);
}
@Override
public boolean isClreplacedReloadable(Clreplaced<?> clazz) {
return (clazz.getClreplacedLoader() instanceof ContextOverridingClreplacedLoader);
}
/**
* ClreplacedLoader to be created for each loaded clreplaced.
* Caches clreplaced file content but redefines clreplaced for each call.
*/
private clreplaced ContextOverridingClreplacedLoader extends OverridingClreplacedLoader {
public ContextOverridingClreplacedLoader(ClreplacedLoader parent) {
super(parent);
}
@Override
protected boolean isEligibleForOverriding(String clreplacedName) {
if (isExcluded(clreplacedName) || ContextTypeMatchClreplacedLoader.this.isExcluded(clreplacedName)) {
return false;
}
ReflectionUtils.makeAccessible(findLoadedClreplacedMethod);
ClreplacedLoader parent = getParent();
while (parent != null) {
if (ReflectionUtils.invokeMethod(findLoadedClreplacedMethod, parent, clreplacedName) != null) {
return false;
}
parent = parent.getParent();
}
return true;
}
@Override
protected Clreplaced<?> loadClreplacedForOverriding(String name) throws ClreplacedNotFoundException {
byte[] bytes = bytesCache.get(name);
if (bytes == null) {
bytes = loadBytesForClreplaced(name);
if (bytes != null) {
bytesCache.put(name, bytes);
} else {
return null;
}
}
return defineClreplaced(name, bytes, 0, bytes.length);
}
}
}
16
Source : ThreadPoolTaskScheduler.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@UsesJava7
@Override
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
if (this.removeOnCancelPolicy) {
if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true);
} else {
logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
}
}
return this.scheduledExecutor;
}
15
Source : ScheduledExecutorFactoryBean.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Override
@UsesJava7
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
ScheduledExecutorService executor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
if (this.removeOnCancelPolicy) {
if (setRemoveOnCancelPolicyAvailable && executor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true);
} else {
logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
}
}
// Register specified ScheduledExecutorTasks, if necessary.
if (!ObjectUtils.isEmpty(this.scheduledExecutorTasks)) {
registerTasks(this.scheduledExecutorTasks, executor);
}
// Wrap executor with an unconfigurable decorator.
this.exposedExecutor = (this.exposeUnconfigurableExecutor ? Executors.unconfigurableScheduledExecutorService(executor) : executor);
return executor;
}