Java Code Examples for com.google.inject.Injector#getProvider()

The following examples show how to use com.google.inject.Injector#getProvider() . 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: TestPseudoDistributedFileSystemPluginE2E.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static final void setupDefaultTestCluster() throws Exception {
  BaseTestQuery.setupDefaultTestCluster();
  Map<String, FormatPluginConfig> formats = ImmutableMap.of("parquet", (FormatPluginConfig) new ParquetFormatConfig());
  WorkspaceConfig workspace = new WorkspaceConfig(TEMPORARY_FOLDER.newFolder().getAbsolutePath(), true, "parquet");
  String path = TEMPORARY_FOLDER.newFolder().getAbsolutePath();

  final Injector injector = getInjector();
  final Provider<SabotContext> sabotContext = injector.getProvider(SabotContext.class);

  service = new PDFSService(injector.getProvider(FabricService.class), () -> sabotContext.get().getEndpoint(), () -> sabotContext.get().getExecutors(),
    DremioTest.DEFAULT_SABOT_CONFIG, getSabotContext().getAllocator());
  service.start();

  SourceConfig c = new SourceConfig();
  PDFSConf conf = new PDFSConf() ;
  conf.path = path;
  c.setType(conf.getType());
  c.setName("pdfs");
  c.setMetadataPolicy(CatalogService.DEFAULT_METADATA_POLICY);
  c.setConfig(conf.toBytesString());
  ((CatalogServiceImpl) getSabotContext().getCatalogService()).getSystemUserCatalog().createSource(c);
}
 
Example 2
Source File: AbstractArchiveOptimalityTester.java    From opt4j with MIT License 5 votes vote down vote up
/**
 * Initializes the {@link Archive} with NUMBER_OF_INDIVIDUALS different
 * {@link Individual}s.
 * <p>
 * Therefore. three {@link Objective}s are added:
 * <ul>
 * <li>the first dimension is incremented</li>
 * <li>the second dimension is decremented</li>
 * <li>the third dimension is set randomly with a static seed.</li>
 * </ul>
 * 
 * @param injector
 *            the injector
 * @param archive
 *            the archive under test
 */
private void fillArchive(Injector injector, Archive archive) {
	Random r = new Random(100);
	Provider<Individual> individuals = injector.getProvider(Individual.class);

	first = null;
	last = null;
	randMin = null;
	int smallestRand = Integer.MAX_VALUE;
	for (int i = 0; i < NUMBER_OF_INDIVUDUALS; i++) {
		Individual individual = individuals.get();
		Objectives o = new Objectives();
		o.add(o1, i);
		o.add(o2, -i);
		int randomValue = r.nextInt(Integer.MAX_VALUE);
		o.add(o3, randomValue);
		individual.setObjectives(o);
		archive.update(individual);

		if (i == 0) {
			first = individual;
		}
		if (i == NUMBER_OF_INDIVUDUALS - 1) {
			last = individual;
		}
		if (randomValue < smallestRand) {
			randMin = individual;
			smallestRand = randomValue;
		}
	}
}
 
Example 3
Source File: RuleContextHelper.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieves the evaluation context (= set of variables) for a ruleModel. The context is shared with all rules in
 * the
 * same model (= rule file).
 *
 * @param ruleModel the ruleModel to get the context for
 * @return the evaluation context
 */
public static synchronized IEvaluationContext getContext(RuleModel ruleModel) {
    Logger logger = LoggerFactory.getLogger(RuleContextHelper.class);
    Injector injector = RulesStandaloneSetup.getInjector();

    // check if a context already exists on the resource
    for (Adapter adapter : ruleModel.eAdapters()) {
        if (adapter instanceof RuleContextAdapter) {
            return ((RuleContextAdapter) adapter).getContext();
        }
    }
    Provider<@NonNull IEvaluationContext> contextProvider = injector.getProvider(IEvaluationContext.class);
    // no evaluation context found, so create a new one
    ScriptEngine scriptEngine = injector.getInstance(ScriptEngine.class);
    IEvaluationContext evaluationContext = contextProvider.get();
    for (VariableDeclaration var : ruleModel.getVariables()) {
        try {
            Object initialValue = var.getRight() == null ? null
                    : scriptEngine.newScriptFromXExpression(var.getRight()).execute();
            evaluationContext.newValue(QualifiedName.create(var.getName()), initialValue);
        } catch (ScriptExecutionException e) {
            logger.warn("Variable '{}' on rule file '{}' cannot be initialized with value '{}': {}", var.getName(),
                    ruleModel.eResource().getURI().path(), var.getRight(), e.getMessage());
        }
    }
    ruleModel.eAdapters().add(new RuleContextAdapter(evaluationContext));
    return evaluationContext;
}
 
Example 4
Source File: RuleContextHelper.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieves the evaluation context (= set of variables) for a rule. The context is shared with all rules in the
 * same model (= rule file).
 *
 * @param rule the rule to get the context for
 * @return the evaluation context
 */
public static synchronized IEvaluationContext getContext(Rule rule, Injector injector) {
    Logger logger = LoggerFactory.getLogger(RuleContextHelper.class);
    RuleModel ruleModel = (RuleModel) rule.eContainer();

    // check if a context already exists on the resource
    for (Adapter adapter : ruleModel.eAdapters()) {
        if (adapter instanceof RuleContextAdapter) {
            return ((RuleContextAdapter) adapter).getContext();
        }
    }
    Provider<IEvaluationContext> contextProvider = injector.getProvider(IEvaluationContext.class);
    // no evaluation context found, so create a new one
    ScriptEngine scriptEngine = injector.getInstance(ScriptEngine.class);
    if (scriptEngine != null) {
        IEvaluationContext evaluationContext = contextProvider.get();
        for (VariableDeclaration var : ruleModel.getVariables()) {
            try {
                Object initialValue = var.getRight() == null ? null
                        : scriptEngine.newScriptFromXExpression(var.getRight()).execute();
                evaluationContext.newValue(QualifiedName.create(var.getName()), initialValue);
            } catch (ScriptExecutionException e) {
                logger.warn("Variable '{}' on rule file '{}' cannot be initialized with value '{}': {}",
                        new Object[] { var.getName(), ruleModel.eResource().getURI().path(),
                                var.getRight().toString(), e.getMessage() });
            }
        }
        ruleModel.eAdapters().add(new RuleContextAdapter(evaluationContext));
        return evaluationContext;
    } else {
        logger.debug("Rule variables of rule {} cannot be evaluated as no scriptengine is available!",
                ruleModel.eResource().getURI().path());
        return contextProvider.get();
    }
}
 
Example 5
Source File: SingleCodetemplateUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<PreferenceStoreAccessor> providePreferenceStoreAccessor() {
	Injector injector = CodetemplatesActivator.getInstance().getInjector("org.eclipse.xtext.ui.codetemplates.Codetemplates");
	return injector.getProvider(PreferenceStoreAccessor.class);
}
 
Example 6
Source File: SingleCodetemplateUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<IPreferenceStoreAccess> provideIPreferenceStoreAccess() {
	Injector injector = CodetemplatesActivator.getInstance().getInjector("org.eclipse.xtext.ui.codetemplates.Codetemplates");
	return injector.getProvider(IPreferenceStoreAccess.class);
}
 
Example 7
Source File: SingleCodetemplateUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<LanguageRegistry> provideLanguageRegistry() {
	Injector injector = CodetemplatesActivator.getInstance().getInjector("org.eclipse.xtext.ui.codetemplates.Codetemplates");
	return injector.getProvider(LanguageRegistry.class);
}
 
Example 8
Source File: SarlScriptExecutor.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Change the injector.
 *
 * @param injector the new injector.
 */
@Inject
public void setInjector(Injector injector) {
	this.compilerProvider = injector.getProvider(SarlBatchCompiler.class);
	this.interpreterProvider = injector.getProvider(IExpressionInterpreter.class);
}
 
Example 9
Source File: SupplierProvider.java    From druid-api with Apache License 2.0 4 votes vote down vote up
@Inject
public void configure(Injector injector)
{
  this.supplierProvider = injector.getProvider(supplierKey);
}