Java Code Examples for com.google.inject.Provider

The following examples show how to use com.google.inject.Provider. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: presto   Source File: HiveS3Module.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    S3FileSystemType type = buildConfigObject(HiveS3TypeConfig.class).getS3FileSystemType();
    if (type == S3FileSystemType.PRESTO) {
        bindSecurityMapping(binder);

        newSetBinder(binder, ConfigurationInitializer.class).addBinding().to(PrestoS3ConfigurationInitializer.class).in(Scopes.SINGLETON);
        configBinder(binder).bindConfig(HiveS3Config.class);

        binder.bind(PrestoS3FileSystemStats.class).toInstance(PrestoS3FileSystem.getFileSystemStats());
        Provider<CatalogName> catalogName = binder.getProvider(CatalogName.class);
        newExporter(binder).export(PrestoS3FileSystemStats.class)
                .as(generator -> generator.generatedNameOf(PrestoS3FileSystem.class, catalogName.get().toString()));
    }
    else if (type == S3FileSystemType.EMRFS) {
        validateEmrFsClass();
        newSetBinder(binder, ConfigurationInitializer.class).addBinding().to(EmrFsS3ConfigurationInitializer.class).in(Scopes.SINGLETON);
    }
    else if (type == S3FileSystemType.HADOOP_DEFAULT) {
        // configuration is done using Hadoop configuration files
    }
    else {
        throw new RuntimeException("Unknown file system type: " + type);
    }
}
 
Example 2
Source Project: openAGV   Source File: KeyValueSetPropertyEditorPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param editorProvider a guice injected provider of KeyValuePropertyEditorPanel Instances
 */
@Inject
public KeyValueSetPropertyEditorPanel(Provider<KeyValuePropertyEditorPanel> editorProvider) {
  this.editorProvider = requireNonNull(editorProvider, "editorProvider");

  initComponents();

  itemsTable.setModel(new ItemsTableModel());

  setPreferredSize(new Dimension(350, 200));

  itemsTable.getSelectionModel().addListSelectionListener((ListSelectionEvent evt) -> {
    if (evt.getValueIsAdjusting()) {
      return;
    }

    handleSelectionChanged();
  });
}
 
Example 3
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public Collection<ICoreQuickfixProvider> getCoreQuickfixProviders(final String language) {
  Collection<ICoreQuickfixProvider> providers = Lists.newArrayList();
  for (ICheckImplDescriptor v : Sets.newHashSet(getDescriptors(language))) {
    if (v instanceof Provider<?>) {
      final ICoreQuickfixProvider provider = ((Provider<ICoreQuickfixProvider>) v).get();
      if (provider == null) { // may be null if specified target class could not be found
        removeLanguageDescriptor(language, v);
      } else {
        providers.add(provider);
      }
    }
  }
  return providers;
}
 
Example 4
Source Project: jackson-modules-base   Source File: ObjectMapperModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ObjectMapper get()
{
    ObjectMapper mapper = objectMapper;
    if (mapper == null) {
        final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector();
        AnnotationIntrospector defaultAI = new JacksonAnnotationIntrospector();
        MapperBuilder<?,?> builder = JsonMapper.builder()
                .injectableValues(new GuiceInjectableValues(injector))
                .annotationIntrospector(new AnnotationIntrospectorPair(guiceIntrospector, defaultAI))
                .addModules(modulesToAdd);
        for (Provider<? extends Module> provider : providedModules) {
            builder = builder.addModule(provider.get());
        }
        mapper = builder.build();

      /*
  } else {
        // 05-Feb-2017, tatu: _Should_ be fine, considering instances are now (3.0) truly immutable.
      //    But if this turns out to be problematic, may need to consider addition of `copy()`
      //    back in databind
      mapper = mapper.copy();
      */
  }
  return mapper;
}
 
Example 5
Source Project: gef   Source File: HoverFeedbackPart.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the {@link Color} that is used to stroke hover feedback.
 *
 * @return The {@link Color} that is used to stroke hover feedback.
 */
@SuppressWarnings("serial")
protected Color getHoverStroke() {
	Provider<Color> hoverFeedbackColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultHoverFeedbackPartFactory.HOVER_FEEDBACK_COLOR_PROVIDER));
	return hoverFeedbackColorProvider == null
			? DefaultHoverFeedbackPartFactory.DEFAULT_HOVER_FEEDBACK_COLOR
			: hoverFeedbackColorProvider.get();
}
 
Example 6
Source Project: gef   Source File: SelectionFeedbackPart.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the primary selection {@link Color}.
 *
 * @return The primary selection {@link Color}.
 */
protected Color getPrimarySelectionColor() {
	@SuppressWarnings("serial")
	Provider<Color> connectedColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultSelectionFeedbackPartFactory.PRIMARY_SELECTION_FEEDBACK_COLOR_PROVIDER));
	return connectedColorProvider == null
			? DefaultSelectionFeedbackPartFactory.DEFAULT_PRIMARY_SELECTION_FEEDBACK_COLOR
			: connectedColorProvider.get();
}
 
Example 7
Source Project: yql-plus   Source File: MultibinderPlannerNamespace.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SourceType findSource(Location location, ContextPlanner planner, List<String> sourcePath) {
    Provider<Source> sourceProvider = sourceBindings.get(keyFor(sourcePath));
    if (sourceProvider == null) {
        return null;
    }
    SourceUnitGenerator adapter = new SourceUnitGenerator(planner.getGambitScope());
    return adapter.apply(sourcePath, sourceProvider);
}
 
Example 8
protected XtextDocument createXtextDocument(String modelAsText) throws Exception {
	final XtextResource resource = getResource(modelAsText, "test.outlinetestlanguage");
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	XtextDocument xtextDocument = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	xtextDocument.setInput(resource);
	xtextDocument.set(modelAsText);
	return xtextDocument;	
}
 
Example 9
Source Project: xtext-eclipse   Source File: DefaultMergeViewer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected DefaultMergeEditor createMergeEditor() {
	@SuppressWarnings("unchecked")
	Provider<DefaultMergeEditor> mergeEditorProvider = (Provider<DefaultMergeEditor>) getCompareConfiguration()
			.getProperty(DefaultMergeEditor.PROVIDER);
	DefaultMergeEditor mergeEditor = mergeEditorProvider.get();
	return mergeEditor;
}
 
Example 10
Source Project: emodb   Source File: DataStoreModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
DataStore provideDataStore(@LocalDataStore Provider<DataStore> localDataStoreProvider,
                           @SystemDataStore Provider<DataStore> systemDataStoreProvider,
                           DataCenterConfiguration dataCenterConfiguration) {
    // Provides the unannotated version of the DataStore
    // If this is the system data center, return the local DataStore implementation
    // Otherwise return a proxy that delegates to local or remote system DataStores
    if (dataCenterConfiguration.isSystemDataCenter()) {
        return localDataStoreProvider.get();
    } else {
        return new DataStoreProviderProxy(localDataStoreProvider, systemDataStoreProvider);
    }
}
 
Example 11
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example 12
Source Project: bromium   Source File: DefaultModule.java    License: MIT License 5 votes vote down vote up
@CheckedProvides(IOProvider.class)
public RequestFilter getRequestFilter(@Named(COMMAND) String command,
                                      IOProvider<List<EventDetector>> eventDetectorListProvider,
                                      Provider<RecordingState> recordingStateProvider,
                                      Provider<ReplayingState> replayingStateProvider,
                                      Provider<List<ConditionsUpdater>> conditionsUpdaters) throws IOException {
    switch (command) {
        case RECORD:
            return new RecordRequestFilter(recordingStateProvider.get(), eventDetectorListProvider.get());
        case REPLAY:
            return new ReplayRequestFilter(replayingStateProvider.get(), conditionsUpdaters.get());
        default:
            throw new NoSuchCommandException();
    }
}
 
Example 13
Source Project: phoenix-tephra   Source File: InMemoryTransactionService.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public InMemoryTransactionService(Configuration conf, DiscoveryService discoveryService,
                                  Provider<TransactionManager> txManagerProvider) {

  this.discoveryService = discoveryService;
  this.txManagerProvider = txManagerProvider;
  this.serviceName = conf.get(TxConstants.Service.CFG_DATA_TX_DISCOVERY_SERVICE_NAME,
                              TxConstants.Service.DEFAULT_DATA_TX_DISCOVERY_SERVICE_NAME);

  address = conf.get(TxConstants.Service.CFG_DATA_TX_BIND_ADDRESS, TxConstants.Service.DEFAULT_DATA_TX_BIND_ADDRESS);
  port = conf.getInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, TxConstants.Service.DEFAULT_DATA_TX_BIND_PORT);

  // Retrieve the number of threads for the service
  threads = conf.getInt(TxConstants.Service.CFG_DATA_TX_SERVER_THREADS,
                        TxConstants.Service.DEFAULT_DATA_TX_SERVER_THREADS);
  ioThreads = conf.getInt(TxConstants.Service.CFG_DATA_TX_SERVER_IO_THREADS,
                          TxConstants.Service.DEFAULT_DATA_TX_SERVER_IO_THREADS);

  maxReadBufferBytes = conf.getInt(TxConstants.Service.CFG_DATA_TX_THRIFT_MAX_READ_BUFFER,
                                   TxConstants.Service.DEFAULT_DATA_TX_THRIFT_MAX_READ_BUFFER);

  LOG.info("Configuring TransactionService" +
             ", address: " + address +
             ", port: " + port +
             ", threads: " + threads +
             ", io threads: " + ioThreads +
             ", max read buffer (bytes): " + maxReadBufferBytes);
}
 
Example 14
@Override
public Provider<? extends StatefulFactory> getStatefulFactoryProvider() {
	final Provider<? extends StatefulFactory> delegate = super.getStatefulFactoryProvider();
	return new Provider<StatefulFactory>() {
		@Override
		public StatefulFactory get() {
			StatefulFactory result = delegate.get();
			result.getDelegate().setParser(partialContentAssistParser);
			if (rule != null) {
				partialContentAssistParser.initializeFor(rule);
			}
			return result;
		}
	};
}
 
Example 15
Source Project: phoenix-omid   Source File: TSOMockModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example 16
Source Project: xtext-eclipse   Source File: RenameLinkedMode.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public boolean start(IRenameElementContext renameElementContext, Provider<LinkedPositionGroup> provider, IProgressMonitor monitor) {
	if (renameElementContext == null)
		throw new IllegalArgumentException("RenameElementContext is null");
	this.linkedPositionGroup = provider.get();
	if (linkedPositionGroup == null || linkedPositionGroup.isEmpty())
		return false;
	this.editor = (XtextEditor) renameElementContext.getTriggeringEditor();
	this.focusEditingSupport = new FocusEditingSupport();
	ISourceViewer viewer = editor.getInternalSourceViewer();
	IDocument document = viewer.getDocument();
	originalSelection = viewer.getSelectedRange();
	currentPosition = linkedPositionGroup.getPositions()[0];
	originalName = getCurrentName();
	try {
		linkedModeModel = new LinkedModeModel();
		linkedModeModel.addGroup(linkedPositionGroup);
		linkedModeModel.forceInstall();
		linkedModeModel.addLinkingListener(new EditorSynchronizer());
		LinkedModeUI ui = new EditorLinkedModeUI(linkedModeModel, viewer);
		ui.setExitPolicy(new ExitPolicy(document));
		if (currentPosition.includes(originalSelection.x))
			ui.setExitPosition(viewer, originalSelection.x, 0, Integer.MAX_VALUE);
		ui.enter();
		if (currentPosition.includes(originalSelection.x)
				&& currentPosition.includes(originalSelection.x + originalSelection.y))
			viewer.setSelectedRange(originalSelection.x, originalSelection.y);
		if (viewer instanceof IEditingSupportRegistry) {
			IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer;
			registry.register(focusEditingSupport);
		}
		openPopup();
		return true;
	} catch (BadLocationException e) {
		throw new WrappedException(e);
	}
}
 
Example 17
Source Project: opt4j   Source File: AbstractArchiveOptimalityTester.java    License: 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 18
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
	return cache.get(REFERENCE_DESCRIPTIONS_CACHE_KEY, getResource(), new Provider<List<IReferenceDescription>>(){
		@Override
		public List<IReferenceDescription> get() {
			return computeReferenceDescriptions();
		}});
}
 
Example 19
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example 20
public Provider<? extends InternalInheritanceTestLanguageLexer> provideInternalInheritanceTestLanguageLexer() {
	return LexerProvider.create(InternalInheritanceTestLanguageLexer.class);
}
 
Example 21
Source Project: hadoop-ozone   Source File: TestReconWithDifferentSqlDBs.java    License: Apache License 2.0 4 votes vote down vote up
public TestReconWithDifferentSqlDBs(
    Provider<DataSourceConfiguration> provider) {
  super(provider);
}
 
Example 22
Source Project: yql-plus   Source File: CompilingTestBase.java    License: Apache License 2.0 4 votes vote down vote up
protected void defineSource(String name, Class<? extends Source> sourceClazz) {
    sources.put(name, (Provider<? extends Source>)injector.getProvider(sourceClazz));
}
 
Example 23
Source Project: xtext-eclipse   Source File: Access.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public static Provider<IAllContainersState> getJavaProjectsState() {
	return Access.<IAllContainersState>contributedProvider(JavaProjectsState.class);
}
 
Example 24
public Provider<? extends InternalBug360834TestLanguageLexer> provideInternalBug360834TestLanguageLexer() {
	return LexerProvider.create(InternalBug360834TestLanguageLexer.class);
}
 
Example 25
public Class<? extends IRenameStrategy.Provider> bindIRenameStrategy$Provider() {
	return JvmMemberRenameStrategy.Provider.class;
}
 
Example 26
Source Project: M2Doc   Source File: AbstractMyDslRuntimeModule.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IAllContainersState.Provider> bindIAllContainersState$Provider() {
	return ResourceSetBasedAllContainersStateProvider.class;
}
 
Example 27
public Provider<? extends InternalUnassignedTextTestLanguageLexer> provideInternalUnassignedTextTestLanguageLexer() {
	return LexerProvider.create(InternalUnassignedTextTestLanguageLexer.class);
}
 
Example 28
Source Project: xtext-eclipse   Source File: Access.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.5
 */
public static Provider<ISharedStateContributionRegistry> getSharedStateContributionRegistry() {
	return Access.<ISharedStateContributionRegistry>provider(ISharedStateContributionRegistry.class);
}
 
Example 29
@Inject
public VoiceContextExecutorResolver(Provider<VoiceContextExecutorRegistry> registry) {
   this.registry = registry;
}
 
Example 30
public Provider<? extends InternalPureXbaseLexer> provideInternalPureXbaseLexer() {
	return LexerProvider.create(InternalPureXbaseLexer.class);
}