本文整理匯總了Java中javax.inject.Provider類的典型用法代碼示例。如果您正苦於以下問題:Java Provider類的具體用法?Java Provider怎麽用?Java Provider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Provider類屬於javax.inject包,在下文中一共展示了Provider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: renderedTags
import javax.inject.Provider; //導入依賴的package包/類
String[] renderedTags() {
final StringBuilder sb = new StringBuilder();
boolean some = false;
for(Provider<Tagger> provider : taggers.get()) {
final Tagger tagger;
try {
tagger = Injection.unwrappingExceptions(OutOfScopeException.class, provider);
} catch(OutOfScopeException e) {
// If the tagger is out of scope, just omit its tags,
// but log a warning in case this hides an unexpected exception.
logger.warning("Ignoring out-of-scope tagger (" + e.toString() + ")");
continue;
}
final ImmutableSet<Tag> tags = tagger.tags();
if(!tags.isEmpty()) {
if(some) sb.append(',');
some = true;
sb.append(tagSetCache.getUnchecked(tags));
}
}
return some ? new String[] {sb.toString()} : EMPTY;
}
示例2: testSingleton
import javax.inject.Provider; //導入依賴的package包/類
@Test
public void testSingleton() {
final Provider<MySingleton> provider = injector.getProvider(MySingleton.class);
assertNotNull(provider);
final MySingleton instance = provider.get();
assertNotNull(instance);
final Provider<MySingleton> provider2 = injector.getProvider(MySingleton.class);
assertNotNull(provider2);
assertEquals(provider, provider2);
final MySingleton instance2 = provider2.get();
assertNotNull(instance2);
assertEquals(instance, instance2);
assertTrue(instance == instance2);
}
示例3: create
import javax.inject.Provider; //導入依賴的package包/類
@NonNull
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
Provider<? extends ViewModel> creator = creators.get(modelClass);
if (creator == null) {
for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
if (modelClass.isAssignableFrom(entry.getKey())) {
creator = entry.getValue();
break;
}
}
}
if (creator == null) {
throw new IllegalArgumentException("unknown model class " + modelClass);
}
try {
return (T) creator.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: TArchiveDetector
import javax.inject.Provider; //導入依賴的package包/類
/**
* Constructs a new {@code TArchiveDetector} by filtering the given driver
* provider for all canonicalized extensions in the {@code extensions} list.
*
* @param provider the file system driver provider to filter.
* @param extensions A list of file name extensions which shall identify
* prospective archive files.
* If this is {@code null}, no filtering is applied and all drivers
* known by the given provider are available for use with this
* archive detector.
* @throws IllegalArgumentException If any of the extensions in the list
* names a extension for which no file system driver is known by the
* provider.
* @see ExtensionSet Syntax constraints for extension lists.
*/
public TArchiveDetector(final Provider<Map<FsScheme, FsDriver>> provider,
final @CheckForNull String extensions) {
final ExtensionSet available = extensions(provider);
ExtensionSet accepted;
if (null == extensions) {
accepted = available;
} else {
accepted = new ExtensionSet(extensions);
if (accepted.retainAll(available)) {
accepted = new ExtensionSet(extensions);
accepted.removeAll(available);
assert !accepted.isEmpty();
throw new IllegalArgumentException(
"\"" + accepted + "\" (no archive driver installed for these extensions)");
}
}
this.extensions = accepted;
this.drivers = provider.get();
}
示例5: Commander
import javax.inject.Provider; //導入依賴的package包/類
@Inject
public Commander(
Ignite ignite,
RPCManager manager,
@Named(DataCapturerBusConfiguration.CLUSTER_ID) UUID clusterId,
@Named(DataCapturerBusConfiguration.RPC_ADDRESS) String address,
@Named(DataCapturerBusConfiguration.SUPER_CLUSTER_ADDRESS) String superClusterAddress,
DataRecoveryConfig dataRecoveryConfig,
Provider<ActiveCacheStoreService> mainInterfaceProvider,
PublisherReplicaService replicaService
) {
this.ignite = ignite;
this.manager = manager;
this.clusterId = clusterId;
this.address = address;
this.superClusterAddress = superClusterAddress;
this.dataRecoveryConfig = dataRecoveryConfig;
this.mainInterfaceProvider = mainInterfaceProvider;
this.replicaService = replicaService;
}
示例6: startServices
import javax.inject.Provider; //導入依賴的package包/類
@BeforeClass
public static void startServices() throws Exception {
provider = new LocalKVStoreProvider(DremioTest.CLASSPATH_SCAN_RESULT, null, true, false);
provider.start();
manager = new TokenManagerImpl(
new Provider<KVStoreProvider>() {
@Override
public KVStoreProvider get() {
return provider;
}
},
new Provider<SchedulerService>() {
@Override
public SchedulerService get() {
return mock(SchedulerService.class);
}
},
false, 10, 10);
manager.start();
}
示例7: create
import javax.inject.Provider; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
Provider<? extends ViewModel> creator = mCreators.get(modelClass);
if (creator == null) {
for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : mCreators
.entrySet()) {
if (modelClass.isAssignableFrom(entry.getKey())) {
creator = entry.getValue();
break;
}
}
}
if (creator == null) {
throw new IllegalArgumentException("unknown model class " + modelClass);
}
try {
return (T) creator.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: testProviderFieldInjection
import javax.inject.Provider; //導入依賴的package包/類
@Test
public void testProviderFieldInjection() {
final Provider<ProviderFieldInjection> providerInjectionProvider = injector.getProvider(ProviderFieldInjection.class);
assertNotNull(providerInjectionProvider);
final ProviderFieldInjection providerInjection = providerInjectionProvider.get();
assertNotNull(providerInjection);
assertNotNull(providerInjection.provider);
final C instance1 = providerInjection.provider.get();
assertNotNull(instance1);
final C instance2 = providerInjection.provider.get();
assertNotNull(instance2);
assertNotEquals(instance1, instance2);
}
示例9: testSimple
import javax.inject.Provider; //導入依賴的package包/類
@Test
public void testSimple() {
final Provider<C> provider = injector.getProvider(C.class);
assertNotNull(provider);
final C instance = provider.get();
assertNotNull(instance);
final Provider<C> provider2 = injector.getProvider(C.class);
assertNotNull(provider2);
assertEquals(provider, provider2);
final C instance2 = provider2.get();
assertNotNull(instance2);
assertNotEquals(instance, instance2);
}
示例10: ModuleHolder
import javax.inject.Provider; //導入依賴的package包/類
public ModuleHolder(
String name,
boolean canOverrideExistingModule,
boolean supportsWebWorkers,
boolean needsEagerInit,
boolean hasConstants,
Provider<? extends NativeModule> provider) {
mName = name;
mCanOverrideExistingModule = canOverrideExistingModule;
mSupportsWebWorkers = supportsWebWorkers;
mHasConstants = hasConstants;
mProvider = provider;
if (needsEagerInit) {
mModule = create();
}
}
示例11: PDFSService
import javax.inject.Provider; //導入依賴的package包/類
public PDFSService(
final Provider<SabotContext> contextProvider,
Provider<FabricService> fabricService,
SabotConfig config,
BufferAllocator allocator,
PDFSMode mode) {
final Provider<Iterable<NodeEndpoint>> nodeProvider = new Provider<Iterable<NodeEndpoint>>(){
@Override
public Iterable<NodeEndpoint> get() {
return contextProvider.get().getExecutors();
}};
Provider<NodeEndpoint> identityProvider = new Provider<NodeEndpoint>(){
@Override
public NodeEndpoint get() {
return contextProvider.get().getEndpoint();
}};
this.fabricService = fabricService;
this.identityProvider = identityProvider;
this.nodeProvider = nodeProvider;
this.config = config;
this.allocator = allocator.newChildAllocator("pdfs-allocator", 0, Long.MAX_VALUE);
this.allowLocalAccess = mode == PDFSMode.DATA;
}
示例12: upgrade
import javax.inject.Provider; //導入依賴的package包/類
public static UpgradeStats upgrade(final SabotConfig sabotConfig, final ScanResult classpathScan,
final KVStoreProvider storeProvider) throws Exception {
final KVStore<String, ClusterIdentity> supportStore = storeProvider.getStore(SupportStoreCreator.class);
final ClusterIdentity identity = Preconditions.checkNotNull(supportStore.get(SupportService.CLUSTER_ID), "No Cluster Identity found");
final Version kvStoreVersion = retrieveStoreVersion(identity);
System.out.println("KVStore version is " + kvStoreVersion.getVersion());
ensureUpgradeSupported(kvStoreVersion);
final LogicalPlanPersistence lpPersistence = new LogicalPlanPersistence(sabotConfig, classpathScan);
final UpgradeContext context = new UpgradeContext(new Provider<KVStoreProvider>() {
@Override
public KVStoreProvider get() {
return storeProvider;
}
}, lpPersistence);
for (UpgradeTask task : TASKS) {
if (kvStoreVersion.compareTo(task.getMaxVersion()) < 0) {
System.out.println(task);
task.upgrade(context);
} else {
System.out.println("Skipping " + task);
}
// let exceptions propagate to main()
}
updateStoreVersion(supportStore, identity);
return context.getUpgradeStats();
}
示例13: SingletonHolder
import javax.inject.Provider; //導入依賴的package包/類
public SingletonHolder(
final Class<T> beanClass,
final Provider<Pair<T, Collection<ResourceReference<?>>>> factory,
final InterceptorChain chain
) {
this.beanClass = beanClass;
this.factory = factory;
proxyInstance = createProxy(beanClass, chain);
}
示例14: Car
import javax.inject.Provider; //導入依賴的package包/類
@Inject
public Car(Provider<Seat> seatProvider) {
Seat driver = seatProvider.get();
logger.info(driver + "");
Seat passenger = seatProvider.get();
logger.info(passenger + "");
}
示例15: prepareMapperClass
import javax.inject.Provider; //導入依賴的package包/類
public void prepareMapperClass(Class<? extends BaseMapper> mapperClass, Class<?> modelClass) {
Object o = Proxy.newProxyInstance(mapperClass.getClassLoader(),
new Class<?>[]{mapperClass},
new MapperJavaProxy(new DefaultMapperBuilder(beetlSql), beetlSql, mapperClass));
final BaseMapper mapper = $.cast(o);
mapperMap.put(mapperClass, mapper);
mapperMap.put(modelClass, mapper);
Genie genie = Act.getInstance(Genie.class);
genie.registerProvider(mapperClass, new Provider() {
@Override
public Object get() {
return mapper;
}
});
}