![JAR search and dependency download from the Maven repository](/logo.png)
com.oracle.coherence.inject.InjectorProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coherence Show documentation
Show all versions of coherence Show documentation
Oracle Coherence Community Edition
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.oracle.coherence.inject;
import javax.annotation.Priority;
import java.util.ServiceLoader;
/**
* A {@link Injector} provider used by {@link Injectable}.
*
* @author Jonathan Knight 2020.11.19
* @since 20.12
*/
class InjectorProvider
{
// ----- constructors ---------------------------------------------------
/**
* Private constructor for utility class.
*/
private InjectorProvider()
{
}
// ----- InjectorProvider methods ---------------------------------------
/**
* Obtain the {@link Injector} to use.
*
* @return the {@link Injector} to use
*/
public static Injector getInstance()
{
return LazyHolder.SINGLETON;
}
// ----- helper methods -------------------------------------------------
static Injector getInjector()
{
Injector injector = INSTANCE;
int nPriority = Integer.MIN_VALUE;
for (Injector instance : ServiceLoader.load(Injector.class))
{
Priority priority = instance.getClass().getAnnotation(Priority.class);
if (priority != null && priority.value() > nPriority)
{
injector = instance;
nPriority = priority.value();
}
else if (nPriority == Integer.MIN_VALUE)
{
injector = instance;
}
}
return injector;
}
// ----- inner class: LazyHolder ----------------------------------------
/**
* A holder for the singleton {@link Injector} instance.
*/
private static class LazyHolder
{
static final Injector SINGLETON = InjectorProvider.getInjector();
}
// ----- constants ------------------------------------------------------
/**
* A no-op {@link Injector}.
*/
private static final Injector INSTANCE = (target) -> {};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy