Java Code Examples for javax.inject.Provider#get()

The following examples show how to use javax.inject.Provider#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewModelFactory.java    From MVVMArms with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: ViewModelFactory.java    From Dagger2-Sample with MIT License 6 votes vote down vote up
@Override
public <T extends ViewModel> T create(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);
    }
}
 
Example 3
Source File: ViewModelFactory.java    From AndroidBlueprints with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(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);
    }
}
 
Example 4
Source File: ViewModelFactory.java    From firestore-android-arch-components with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: ObjectFactoryCreatingFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testProviderOperation() throws Exception {
	ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class);
	Provider<?> provider = testBean.getProvider();

	Date date1 = (Date) provider.get();
	Date date2 = (Date) provider.get();
	assertTrue(date1 != date2);
}
 
Example 6
Source File: MethodHandleInvoker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static MethodHandleInvoker caching(Provider<?> targeter) {
    return new MethodHandleInvoker() {
        private @Nullable Object cache;
        @Override protected Object targetFor(Method method) {
            if(cache == null) {
                cache = targeter.get();
            }
            return cache;
        }
    };
}
 
Example 7
Source File: MethodHandleInvoker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static MethodHandleInvoker dynamic(Provider<?> targeter) {
    return new MethodHandleInvoker() {
        @Override protected Object targetFor(Method method) {
            return targeter.get();
        }
    };
}
 
Example 8
Source File: InjectionStore.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public <T> T provide(Key<T> key, Provider<T> provider) {
    T t = (T) map.get(key);
    if(t != null) return t;

    t = provider.get();
    if(!Scopes.isCircularProxy(t)) {
        store(key, t);
    }

    return t;
}
 
Example 9
Source File: PrimitiveAdapter.java    From Graywater with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected ActionListener<? extends Primitive, PrimitiveViewHolder, ? extends PrimitiveViewHolder>
getActionListener(final Primitive model) {
	final Class<? extends Primitive> modelType = getModelType(model);
	final Provider<ActionListener<? extends Primitive, PrimitiveViewHolder, ? extends PrimitiveViewHolder>>
			provider = mActionListenerMap.get(modelType);

	return provider != null ? provider.get() : null;
}
 
Example 10
Source File: ProviderAloneTest.java    From smallrye-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testProvider() {
    Provider<Email> emailProvider = bean.emailProvider;
    assertNotNull(emailProvider);
    Email email = emailProvider.get();
    assertNotNull(email);
    assertEquals("example", email.getName());
    assertEquals("smallrye.io", email.getDomain());
}
 
Example 11
Source File: DefaultSingletonBeanRegistry.java    From festival with Apache License 2.0 5 votes vote down vote up
protected Object getSingleton(String beanName, boolean allowEarly) {
    synchronized (singletons) {
        Object singleton = singletons.get(beanName);
        if (singleton == null && allowEarly) {
            singleton = earlySingletons.get(beanName);
            if (singleton == null && underCreating(beanName)) {
                Provider<?> provider = singletonProviders.get(beanName);
                singleton = provider.get();
                earlySingletons.put(beanName, singleton);
            }
        }
        return singleton;
    }
}
 
Example 12
Source File: SabotNode.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
ExecutorSelectionService getExecutorSelectionService(
        Provider<ClusterCoordinator> clusterCoordinator,
        Provider<OptionManager> optionManagerProvider,
        Provider<ExecutorSelectorFactory> executorSelectorFactory,
        Provider<ExecutorSelectorProvider> executorSelectorProvider
) {
  return new ExecutorSelectionServiceImpl(
          clusterCoordinator,
          optionManagerProvider,
          executorSelectorFactory,
          executorSelectorProvider.get()
  );
}
 
Example 13
Source File: OpenTCSModelManager.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param crsObjFactory A course object factory to be used.
 * @param procAdapterUtil A utility class for process adapters.
 * @param systemModelProvider Provides instances of SystemModel.
 * @param statusPanel StatusPanel to log messages.
 * @param homeDir The application's home directory.
 * @param kernelPersistor Persists a model to a kernel.
 * @param modelReader The model reader.
 * @param modelPersistor The model persistor.
 * @param modelImportAdapter Converts model data on import.
 * @param modelExportAdapter Converts model data on export.
 */
@Inject
public OpenTCSModelManager(CourseObjectFactory crsObjFactory,
                           ProcessAdapterUtil procAdapterUtil,
                           Provider<SystemModel> systemModelProvider,
                           StatusPanel statusPanel,
                           @ApplicationHome File homeDir,
                           ModelKernelPersistor kernelPersistor,
                           ModelFileReader modelReader,
                           ModelFilePersistor modelPersistor,
                           ModelImportAdapter modelImportAdapter,
                           ModelExportAdapter modelExportAdapter) {
  this.crsObjFactory = requireNonNull(crsObjFactory, "crsObjFactory");
  this.procAdapterUtil = requireNonNull(procAdapterUtil, "procAdapterUtil");
  this.systemModelProvider = requireNonNull(systemModelProvider, "systemModelProvider");
  this.statusPanel = requireNonNull(statusPanel, "statusPanel");
  requireNonNull(homeDir, "homeDir");
  this.kernelPersistor = requireNonNull(kernelPersistor, "kernelPersistor");
  
  this.modelReader = requireNonNull(modelReader, "modelReader");
  this.modelReaderFileChooser = new SynchronizedFileChooser(new File(homeDir, "data"));
  this.modelReaderFileChooser.setAcceptAllFileFilterUsed(false);
  this.modelReaderFileChooser.setFileFilter(modelReader.getDialogFileFilter());

  this.modelPersistor = requireNonNull(modelPersistor, "modelPersistor");
  this.modelPersistorFileChooser = new SynchronizedFileChooser(new File(homeDir, "data"));
  this.modelPersistorFileChooser.setAcceptAllFileFilterUsed(false);
  this.modelPersistorFileChooser.setFileFilter(modelPersistor.getDialogFileFilter());

  this.modelImportAdapter = requireNonNull(modelImportAdapter, "modelImportAdapter");
  this.modelExportAdapter = requireNonNull(modelExportAdapter, "modelExportAdapter");

  this.systemModel = systemModelProvider.get();
  initializeSystemModel(systemModel);
}
 
Example 14
Source File: ObjectFactoryCreatingFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testProviderOperation() {
	ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class);
	Provider<?> provider = testBean.getProvider();

	Date date1 = (Date) provider.get();
	Date date2 = (Date) provider.get();
	assertTrue(date1 != date2);
}
 
Example 15
Source File: TestGuiceServiceModule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
D getD(Provider<B> bProvider, Provider<C> cProvider, Provider<A> aProvider) {
  bProvider.get();
  aProvider.get();
  cProvider.get();
  return new D();
}
 
Example 16
Source File: TestGuiceServiceModule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
B getB(Provider<A> aProvider, Provider<C> cProvider) {
  aProvider.get();
  cProvider.get();
  return new BImpl();
}
 
Example 17
Source File: AutowiredConfigurationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean @Scope("prototype")
public TestBean testBean2(@Value("#{systemProperties[myProp]}") Provider<String> name2) {
	return new TestBean(name2.get());
}
 
Example 18
Source File: AutowiredConfigurationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean @Scope("prototype")
public TestBean testBean(@Value("#{systemProperties[myProp]}") Provider<String> name) {
	return new TestBean(name.get());
}
 
Example 19
Source File: DremioServer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public void startDremioServer(
  SingletonRegistry registry,
  DACConfig config,
  Provider<ServerHealthMonitor> serverHealthMonitor,
  Provider<NodeEndpoint> endpointProvider,
  Provider<SabotContext> contextProvider,
  Provider<RestServerV2> restServerProvider,
  Provider<APIServer> apiServerProvider,
  DremioBinder dremioBinder,
  Tracer tracer,
  String uiType,
  boolean isInternalUS
) throws Exception {
  try {
    if (!embeddedJetty.isRunning()) {
      createConnector(config);
      addHandlers();
    }

    // security header filters
    servletContextHandler.addFilter(SecurityHeadersFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST));

    // server tracing filter.
    servletContextHandler.addFilter(SpanFinishingFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST));

    // add the font mime type.
    final MimeTypes mimeTypes = servletContextHandler.getMimeTypes();
    mimeTypes.addMimeMapping("woff2", "application/font-woff2; charset=utf-8");
    servletContextHandler.setMimeTypes(mimeTypes);

    // WebSocket API
    final SocketServlet servlet = new SocketServlet(registry.lookup(JobsService.class), registry.lookup(TokenManager.class));
    final ServletHolder wsHolder = new ServletHolder(servlet);
    wsHolder.setInitOrder(3);
    servletContextHandler.addServlet(wsHolder, "/apiv2/socket");

    // Rest API
    ResourceConfig restServer = restServerProvider.get();

    restServer.property(RestServerV2.ERROR_STACKTRACE_ENABLE, config.sendStackTraceToClient);
    restServer.property(RestServerV2.TEST_API_ENABLE, config.allowTestApis);
    restServer.property(RestServerV2.FIRST_TIME_API_ENABLE, isInternalUS);

    restServer.register(dremioBinder);
    restServer.register(new ServerTracingDynamicFeature(tracer));

    final ServletHolder restHolder = new ServletHolder(new ServletContainer(restServer));
    restHolder.setInitOrder(2);
    servletContextHandler.addServlet(restHolder, "/apiv2/*");

    // Public API
    ResourceConfig apiServer = apiServerProvider.get();
    apiServer.register(dremioBinder);
    apiServer.register(new ServerTracingDynamicFeature(tracer));

    final ServletHolder apiHolder = new ServletHolder(new ServletContainer(apiServer));
    apiHolder.setInitOrder(3);
    servletContextHandler.addServlet(apiHolder, "/api/v3/*");

    if (config.verboseAccessLog) {
      accessLogFilter = new AccessLogFilter();
      servletContextHandler.addFilter(
        new FilterHolder(accessLogFilter),
        "/*",
        EnumSet.of(DispatcherType.REQUEST));
    }

    if (config.serveUI) {
      final String basePath = "rest/dremio_static/";
      final String markerPath = String.format("META-INF/%s.properties", uiType);

      final ServletHolder fallbackServletHolder = new ServletHolder("fallback-servlet", registry.lookup(DremioServlet.class));
      addStaticPath(fallbackServletHolder, basePath, markerPath);
      servletContextHandler.addServlet(fallbackServletHolder, "/*");

      // TODO DX-1556 - temporary static asset serving for showing Profiles
      final String baseStaticPath = "rest/static/";
      final String arrowDownResourceRelativePath = "rest/static/img/arrow-down-small.svg";
      ServletHolder restStaticHolder = new ServletHolder("static", DefaultServlet.class);
      // Get resource URL for legacy static assets, based on where some image is located
      addStaticPath(restStaticHolder, baseStaticPath, arrowDownResourceRelativePath);
      servletContextHandler.addServlet(restStaticHolder, "/static/*");
    }

    if (!embeddedJetty.isRunning()) {
      embeddedJetty.start();
    }

    setPortFromConnector();
    logger.info("Started on {}://localhost:" + port, config.webSSLEnabled() ? "https" : "http");

    serviceStarted = true;
  } catch (Exception ex) {
    throw new ServerErrorException(ex);
  }
}
 
Example 20
Source File: AuthValidator.java    From dremio-flight-connector with Apache License 2.0 4 votes vote down vote up
public AuthValidator(Provider<UserService> userService, Provider<SabotContext> context) {
  this.userService = userService.get();
  this.context = context.get();
}