Java Code Examples for com.google.inject.Scopes

The following are top voted examples for showing how to use com.google.inject.Scopes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: drift   File: DriftClientBinder.java   Source Code and License 6 votes vote down vote up
private <T> DriftClientBindingBuilder bindDriftClient(Class<T> clientInterface, String configPrefix, Class<? extends Annotation> annotation)
{
    Annotation clientAnnotation = getDriftClientAnnotation(clientInterface, annotation);

    configBinder(binder).bindConfig(DriftClientConfig.class, clientAnnotation, configPrefix);

    TypeLiteral<DriftClient<T>> typeLiteral = driftClientTypeLiteral(clientInterface);

    Provider<T> instanceProvider = new DriftClientInstanceProvider<>(clientAnnotation, Key.get(typeLiteral, annotation));
    Provider<DriftClient<T>> factoryProvider = new DriftClientProvider<>(clientInterface, clientAnnotation);

    binder.bind(Key.get(clientInterface, annotation)).toProvider(instanceProvider).in(Scopes.SINGLETON);
    binder.bind(Key.get(typeLiteral, annotation)).toProvider(factoryProvider).in(Scopes.SINGLETON);

    if (annotation == DefaultClient.class) {
        binder.bind(Key.get(clientInterface)).toProvider(instanceProvider).in(Scopes.SINGLETON);
        binder.bind(Key.get(typeLiteral)).toProvider(factoryProvider).in(Scopes.SINGLETON);
    }

    return new DriftClientBindingBuilder(binder, clientAnnotation, configPrefix);
}
 
Example 2
Project: paraflow   File: HDFSModule.java   Source Code and License 6 votes vote down vote up
/**
 * Contributes bindings and other configurations for this module to {@code binder}.
 *
 * @param binder binder
 */
@Override
public void configure(Binder binder)
{
    binder.bind(HDFSConnectorId.class).toInstance(new HDFSConnectorId(connectorId));
    binder.bind(TypeManager.class).toInstance(typeManager);

    configBinder(binder).bindConfig(MetaConfig.class);

    binder.bind(HDFSMetadataFactory.class).in(Scopes.SINGLETON);
    binder.bind(HDFSMetadata.class).in(Scopes.SINGLETON);
    binder.bind(FSFactory.class).in(Scopes.SINGLETON);
    binder.bind(HDFSConnector.class).in(Scopes.SINGLETON);
    binder.bind(HDFSSplitManager.class).in(Scopes.SINGLETON);
    binder.bind(HDFSPageSourceProvider.class).in(Scopes.SINGLETON);
    binder.bind(ClassLoader.class).toInstance(HDFSPlugin.getClassLoader());
}
 
Example 3
Project: OSWf-OSWorkflow-fork   File: ServiceModule.java   Source Code and License 6 votes vote down vote up
protected void configure() {

        bindConstant().annotatedWith(Names.named("executable.graphviz"))
                      .to(locality.getValue("executable.graphviz", "dot"));

        bind(OSWfConfiguration.class).toInstance(oswfConfiguration);
        
        // Service implementations are singletons
        bind(OSWfServiceImpl.class).in(Scopes.SINGLETON);
        bind(GraphvizServiceImpl.class).in(Scopes.SINGLETON);
        bind(WfDefinitionServiceImpl.class).in(Scopes.SINGLETON);

        // Bind interfaces to implementation classes
        bind(OSWfService.class).to(OSWfServiceImpl.class);
        bind(WfDefinitionService.class).to(WfDefinitionServiceImpl.class);
        bind(GraphvizService.class).to(GraphvizServiceImpl.class);
    }
 
Example 4
Project: monarch   File: AmpoolModule.java   Source Code and License 6 votes vote down vote up
@Override
public void configure(Binder binder)
{
    log.info("INFORMATION: AmpoolMetadata configure() called.");

    binder.bind(TypeManager.class).toInstance(typeManager);
    binder.bind(AmpoolConnectorID.class).toInstance(new AmpoolConnectorID(connectorId));
    binder.bind(AmpoolConnector.class).in(Scopes.SINGLETON);
    binder.bind(AmpoolMetadata.class).in(Scopes.SINGLETON);
    binder.bind(AmpoolClient.class).in(Scopes.SINGLETON);
    binder.bind(AmpoolSplitManager.class).in(Scopes.SINGLETON);
    binder.bind(AmpoolRecordSetProvider.class).in(Scopes.SINGLETON);
    //configBinder(binder).bindConfig(AmpoolConfig.class);

    /*
    jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
    jsonCodecBinder(binder).bindMapJsonCodec(String.class, listJsonCodec(AmpoolTable.class));
    */
}
 
Example 5
Project: guacamole-auth-callback   File: CallbackAuthenticationProviderModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {

    // Bind core implementations of guacamole-ext classes
    bind(AuthenticationProvider.class).toInstance(authProvider);
    bind(Environment.class).toInstance(environment);

    // Bind services
    bind(ConfigurationService.class);
    bind(UserDataService.class);

    // Bind singleton ObjectMapper for JSON serialization/deserialization
    bind(ObjectMapper.class).in(Scopes.SINGLETON);

    // Bind singleton Jersey REST client
    bind(Client.class).toInstance(Client.create(CLIENT_CONFIG));

}
 
Example 6
Project: abhot   File: CassandraModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure()
{
	bind(Datastore.class).to(CassandraDatastore.class).in(Scopes.SINGLETON);
	bind(CassandraDatastore.class).in(Scopes.SINGLETON);
	bind(IncreaseMaxBufferSizesJob.class).in(Scopes.SINGLETON);
	bind(CleanRowKeyCache.class).in(Scopes.SINGLETON);
	bind(HectorConfiguration.class).in(Scopes.SINGLETON);
	bind(CassandraConfiguration.class).in(Scopes.SINGLETON);

	bind(new TypeLiteral<List<RowKeyListener>>()
	{
	}).toProvider(RowKeyListenerProvider.class);

	bind(new TypeLiteral<Map<String, String>>(){}).annotatedWith(Names.named(CASSANDRA_AUTH_MAP))
			.toInstance(m_authMap);

	bind(new TypeLiteral<Map<String, Object>>(){}).annotatedWith(Names.named(CASSANDRA_HECTOR_MAP))
			.toInstance(m_hectorMap);
}
 
Example 7
Project: presto-manager   File: ControllerServerModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    binder.disableCircularProxies();

    binder.bind(AgentMap.class).to(DiscoveryAgentMap.class).in(Scopes.SINGLETON);
    binder.bind(RequestDispatcher.class).in(Scopes.SINGLETON);
    binder.bind(Client.class).to(JerseyClient.class).in(Scopes.SINGLETON);
    binder.bind(ResponseWrapper.class);

    jaxrsBinder(binder).bind(ControllerConfigAPI.class);
    jaxrsBinder(binder).bind(ControllerConnectorAPI.class);
    jaxrsBinder(binder).bind(ControllerLogsAPI.class);
    jaxrsBinder(binder).bind(ControllerPackageAPI.class);
    jaxrsBinder(binder).bind(ControllerControlAPI.class);
    jaxrsBinder(binder).bind(InstantConverterProvider.class);

    discoveryBinder(binder).bindSelector("presto-manager");
}
 
Example 8
Project: ice   File: PropertyAccessor.java   Source Code and License 6 votes vote down vote up
public static <C> PrivateModule module(final PropertyIdentifier propertyIdentifier, final ConfigDescriptor desc)
{
    return new PrivateModule()
    {
        @Override
        protected void configure()
        {
            // Alias the private module scoped bindings for the un-annotated ConstantValuePropertyAccessor and PropertyIdentifier to globally scoped and annotated ones.
            // Intent here is to make the implementation of this nice and guicified but support a number of different instances.
            bind(ConstantValuePropertyAccessor.class).to(Key.get(ConstantValuePropertyAccessor.class, propertyIdentifier));
            bind(PropertyIdentifier.class).to(Key.get(PropertyIdentifier.class, propertyIdentifier));

            TypeLiteral<PropertyAccessor<C>> accessorType = (TypeLiteral<PropertyAccessor<C>>) TypeLiteral.get(Types.newParameterizedType(PropertyAccessor.class, desc.getConfigType()));
            bind(Key.get(accessorType, propertyIdentifier)).to(accessorType).in(Scopes.SINGLETON);
            expose(Key.get(accessorType, propertyIdentifier));
        }
    };
}
 
Example 9
Project: Mastering-Mesos   File: SingularityDataModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
  bind(RequestHelper.class).in(Scopes.SINGLETON);

  bind(MetadataManager.class).in(Scopes.SINGLETON);
  bind(StateManager.class).in(Scopes.SINGLETON);
  bind(TaskManager.class).in(Scopes.SINGLETON);
  bind(DeployManager.class).in(Scopes.SINGLETON);
  bind(RackManager.class).in(Scopes.SINGLETON);
  bind(RequestManager.class).in(Scopes.SINGLETON);
  bind(SlaveManager.class).in(Scopes.SINGLETON);
  bind(TaskRequestManager.class).in(Scopes.SINGLETON);
  bind(SandboxManager.class).in(Scopes.SINGLETON);
  bind(SingularityValidator.class).in(Scopes.SINGLETON);

  bind(ExecutorIdGenerator.class).in(Scopes.SINGLETON);
  bind(WebhookManager.class).in(Scopes.SINGLETON);
}
 
Example 10
Project: Mastering-Mesos   File: SingularityRunnerBaseModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
  bind(ObjectMapper.class).toInstance(JavaUtils.newObjectMapper());
  bind(MetricRegistry.class).toInstance(new MetricRegistry());

  SingularityRunnerBaseLogging.quietEagerLogging();
  bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
  bind(SingularityRunnerExceptionNotifier.class).in(Scopes.SINGLETON);

  final Optional<String> consolidatedConfigFilename = Optional.fromNullable(Strings.emptyToNull(System.getProperty(CONFIG_PROPERTY)));
  final ConfigurationBinder configurationBinder = ConfigurationBinder.newBinder(binder());

  configurationBinder.bindPrimaryConfiguration(primaryConfigurationClass, consolidatedConfigFilename);
  for (Class<? extends BaseRunnerConfiguration> additionalConfigurationClass : additionalConfigurationClasses) {
    configurationBinder.bindConfiguration(additionalConfigurationClass, consolidatedConfigFilename);
  }

  if (!additionalConfigurationClasses.contains(SingularityRunnerBaseConfiguration.class)) {
    configurationBinder.bindConfiguration(SingularityRunnerBaseConfiguration.class, consolidatedConfigFilename);
  }

  bind(SingularityRunnerBaseLogging.class).asEagerSingleton();

  bind(new TypeLiteral<Optional<String>>(){}).annotatedWith(Names.named(CONSOLIDATED_CONFIG_FILENAME)).toInstance(consolidatedConfigFilename);
}
 
Example 11
Project: metacat   File: PostgreSqlConnectorModule.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void configure() {
    this.bind(DataSource.class)
        .toInstance(DataSourceManager.get().load(this.name, this.configuration).get(this.name));
    this.bind(JdbcTypeConverter.class).to(PostgreSqlTypeConverter.class).in(Scopes.SINGLETON);
    this.bind(JdbcExceptionMapper.class).to(PostgreSqlExceptionMapper.class).in(Scopes.SINGLETON);
    this.bind(ConnectorDatabaseService.class)
        .to(ConnectorUtils.getDatabaseServiceClass(this.configuration, PostgreSqlConnectorDatabaseService.class))
        .in(Scopes.SINGLETON);
    this.bind(ConnectorTableService.class)
        .to(ConnectorUtils.getTableServiceClass(this.configuration, JdbcConnectorTableService.class))
        .in(Scopes.SINGLETON);
    this.bind(ConnectorPartitionService.class)
        .to(ConnectorUtils.getPartitionServiceClass(this.configuration, JdbcConnectorPartitionService.class))
        .in(Scopes.SINGLETON);
}
 
Example 12
Project: metacat   File: MySqlConnectorModule.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void configure() {
    this.bind(DataSource.class)
        .toInstance(DataSourceManager.get().load(this.name, this.configuration).get(this.name));
    this.bind(JdbcTypeConverter.class).to(MySqlTypeConverter.class).in(Scopes.SINGLETON);
    this.bind(JdbcExceptionMapper.class).to(MySqlExceptionMapper.class).in(Scopes.SINGLETON);
    this.bind(ConnectorDatabaseService.class)
        .to(ConnectorUtils.getDatabaseServiceClass(this.configuration, MySqlConnectorDatabaseService.class))
        .in(Scopes.SINGLETON);
    this.bind(ConnectorTableService.class)
        .to(ConnectorUtils.getTableServiceClass(this.configuration, JdbcConnectorTableService.class))
        .in(Scopes.SINGLETON);
    this.bind(ConnectorPartitionService.class)
        .to(ConnectorUtils.getPartitionServiceClass(this.configuration, JdbcConnectorPartitionService.class))
        .in(Scopes.SINGLETON);
}
 
Example 13
Project: metacat   File: RedshiftConnectorModule.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void configure() {
    this.bind(DataSource.class)
        .toInstance(DataSourceManager.get().load(this.name, this.configuration).get(this.name));
    this.bind(JdbcTypeConverter.class).to(RedshiftTypeConverter.class).in(Scopes.SINGLETON);
    this.bind(JdbcExceptionMapper.class).to(RedshiftExceptionMapper.class).in(Scopes.SINGLETON);
    this.bind(ConnectorDatabaseService.class)
        .to(ConnectorUtils.getDatabaseServiceClass(this.configuration, JdbcConnectorDatabaseService.class))
        .in(Scopes.SINGLETON);
    this.bind(ConnectorTableService.class)
        .to(ConnectorUtils.getTableServiceClass(this.configuration, RedshiftConnectorTableService.class))
        .in(Scopes.SINGLETON);
    this.bind(ConnectorPartitionService.class)
        .to(ConnectorUtils.getPartitionServiceClass(this.configuration, JdbcConnectorPartitionService.class))
        .in(Scopes.SINGLETON);
}
 
Example 14
Project: leopard   File: AlarmModule.java   Source Code and License 6 votes vote down vote up
@Override
public void configure(Binder binder) {
	binder.bind(AlarmDao.class).to(AlarmDaoAllImpl.class).in(Scopes.SINGLETON);

	binder.bind(AlarmService.class).to(AlarmServiceImpl.class).in(Scopes.SINGLETON);

	binder.bind(RobotDao.class).to(RobotDaoHttpImpl.class).in(Scopes.SINGLETON);
	binder.bind(RobotService.class).to(RobotServiceImpl.class).in(Scopes.SINGLETON);

	// binder.bind(Jdbc.class).to(JdbcH2Impl.class).in(Scopes.SINGLETON);
	// binder.bind(SqlSession.class).to(SqlSessionH2Impl.class).in(Scopes.SINGLETON);
	// binder.bind(H2Dao.class).to(H2DaoImpl.class).in(Scopes.SINGLETON);
	//
	// binder.bind(DataSource.class).toProvider(DataSourceProvider.class).in(Scopes.SINGLETON);
	//
	// binder.bind(JedisTestnbImpl.class).toInstance(new JedisTestnbImpl());
	// binder.bind(TransactionTestnbImpl.class).toInstance(new TransactionTestnbImpl());
}
 
Example 15
Project: EDDI   File: BehaviorModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
    bind(IBehaviorDeserialization.class).to(BehaviorDeserialization.class).in(Scopes.SINGLETON);
    MapBinder<String, ILifecycleTask> lifecycleTaskPlugins
            = MapBinder.newMapBinder(binder(), String.class, ILifecycleTask.class);
    lifecycleTaskPlugins.addBinding("ai.labs.behavior").to(BehaviorRulesEvaluationTask.class);

    MapBinder<String, IBehaviorExtension> behaviorExtensionPlugins
            = MapBinder.newMapBinder(binder(), String.class, IBehaviorExtension.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.inputmatcher").
            to(InputMatcher.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.actionmatcher").
            to(ActionMatcher.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.contextmatcher").
            to(ContextMatcher.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.connector").
            to(Connector.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.dependency").
            to(Dependency.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.negation").
            to(Negation.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.occurrence").
            to(Occurrence.class);
    behaviorExtensionPlugins.addBinding("ai.labs.behavior.extension.resultsize").
            to(ResultSize.class);
}
 
Example 16
Project: EDDI   File: RuntimeModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
    registerConfigFiles(this.configFiles);

    //init system runtime eagerly
    bind(SystemRuntime.IRuntime.class).to(BaseRuntime.class).asEagerSingleton();

    bind(IResourceClientLibrary.class).to(ResourceClientLibrary.class).in(Scopes.SINGLETON);
    bind(IBotStoreClientLibrary.class).to(BotStoreClientLibrary.class).in(Scopes.SINGLETON);
    bind(IPackageStoreClientLibrary.class).to(PackageStoreClientLibrary.class).in(Scopes.SINGLETON);
    bind(IPackageStoreService.class).to(PackageStoreService.class).in(Scopes.SINGLETON);
    bind(IBotStoreService.class).to(BotStoreService.class).in(Scopes.SINGLETON);

    bind(IBotFactory.class).to(BotFactory.class).in(Scopes.SINGLETON);
    bind(IPackageFactory.class).to(PackageFactory.class).in(Scopes.SINGLETON);

    bind(IAutoBotDeployment.class).to(AutoBotDeployment.class).in(Scopes.SINGLETON);

    //call init method of system runtime after creation
    bindListener(HasInitMethod.INSTANCE, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
            encounter.register(InitInvoker.INSTANCE);
        }
    });
}
 
Example 17
Project: biomedicus   File: BiomedicusScopes.java   Source Code and License 6 votes vote down vote up
@Override
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
  return () -> {
    Context context = contextRef.get();
    if (null != context) {
      @SuppressWarnings("unchecked")
      T t = (T) context.objectsMap.get(key);

      if (t == null) {
        t = unscoped.get();
        if (!Scopes.isCircularProxy(t)) {
          context.objectsMap.put(key, t);
        }
      }
      return t;
    } else {
      throw new OutOfScopeException("Not currently in a document scope");
    }
  };
}
 
Example 18
Project: jahhan   File: ControllerBindModule.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
	String[] packages = PackageUtil.packages("controller");
	List<String> classNameList = new ClassScaner().parse(packages);
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	for (String className : classNameList) {
		try {
			Class clazz = classLoader.loadClass(className);
			Named named = (Named) clazz.getAnnotation(Named.class);
			Controller controller = (Controller) clazz.getAnnotation(Controller.class);
			if (null != named) {
				bind(clazz).in(Scopes.SINGLETON);
			}
			if (null != controller) {
				Class[] interfaces = clazz.getInterfaces();
				Class interfaceClass = interfaces[0];
				bind(interfaceClass).to(clazz).in(Scopes.SINGLETON);
			}
		} catch (ClassNotFoundException e) {
		}
	}
}
 
Example 19
Project: gstrap   File: SimpleScope.java   Source Code and License 6 votes vote down vote up
public <T> Provider<T> scope(final Key<T> key, final Provider<T> unscoped) {
	return () -> {
		Map<Key<?>, Object> scopedObjects = getScopedObjects(key);

		@SuppressWarnings("unchecked")
		T current = (T) scopedObjects.get(key);
		if (current == null && !scopedObjects.containsKey(key)) {
			current = unscoped.get();

			// don't remember proxies; these exist only to serve circular dependencies
			if (Scopes.isCircularProxy(current)) {
				return current;
			}

			scopedObjects.put(key, current);
		}
		return current;
	};
}
 
Example 20
Project: incubator-tephra   File: TransactionLocalModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
  bind(SnapshotCodecProvider.class).in(Singleton.class);
  bind(TransactionStateStorage.class).annotatedWith(Names.named("persist"))
    .to(LocalFileTransactionStateStorage.class).in(Scopes.SINGLETON);
  bind(TransactionStateStorage.class).toProvider(TransactionStateStorageProvider.class).in(Scopes.SINGLETON);

  bind(TransactionManager.class).in(Scopes.SINGLETON);
  bind(TransactionSystemClient.class).to(InMemoryTxSystemClient.class).in(Singleton.class);
  bind(MetricsCollector.class).to(DefaultMetricsCollector.class);

  bindConstant().annotatedWith(Names.named(TxConstants.CLIENT_ID)).to(clientId);

  install(new FactoryModuleBuilder()
            .implement(TransactionExecutor.class, DefaultTransactionExecutor.class)
            .build(TransactionExecutorFactory.class));
}
 
Example 21
Project: incubator-tephra   File: TransactionDistributedModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
  // some of these classes need to be non-singleton in order to create a new instance during leader() in
  // TransactionService
  bind(SnapshotCodecProvider.class).in(Singleton.class);
  bind(TransactionStateStorage.class).annotatedWith(Names.named("persist")).to(HDFSTransactionStateStorage.class);
  bind(TransactionStateStorage.class).toProvider(TransactionStateStorageProvider.class);

  bindConstant().annotatedWith(Names.named(TxConstants.CLIENT_ID)).to(clientId);

  // to catch issues during configure time
  bind(TransactionManager.class);
  bind(TransactionSystemClient.class).to(TransactionServiceClient.class).in(Scopes.SINGLETON);
  bind(MetricsCollector.class).to(DefaultMetricsCollector.class);

  install(new FactoryModuleBuilder()
      .implement(TransactionExecutor.class, DefaultTransactionExecutor.class)
      .build(TransactionExecutorFactory.class));
}
 
Example 22
Project: OpenKAD-Shades   File: NoCacheProtocolModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
	bind(KadCache.class).to(KadCacheAndStorageWrapper.class).in(Scopes.SINGLETON);
	bind(KadCache.class).annotatedWith(Names.named("openkad.inner.cache")).to(DummyKadCache.class);
	
	bind(KadBuckets.class).in(Scopes.SINGLETON);
	bind(KBuckets.class).to(KadBuckets.class).in(Scopes.SINGLETON);
	bind(NodeStorage.class).to(KadBuckets.class).in(Scopes.SINGLETON);

	bind(FindNodeOperation.class).to(KadFindNodeOperation.class);
	bind(FindNodeHandler.class).to(KademliaFindNodeHandler.class);
	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.findvalue")).to(
			StorageLocalCacheFindValueOperation.class);
	bind(KeybasedRouting.class).to(KadNet.class).in(Scopes.SINGLETON);
	// unused...
	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.lastFindValue")).to(
			StorageLocalCacheFindValueOperation.class);

}
 
Example 23
Project: OpenKAD-Shades   File: KadCacheProtocolModuleLRU.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
	bind(KadCache.class).to(KadCacheAndStorageWrapper.class).in(Scopes.SINGLETON);
	bind(KadCache.class).annotatedWith(Names.named("openkad.inner.cache")).to(LRUKadCache.class);
	
	bind(KadBuckets.class).in(Scopes.SINGLETON);
	bind(KBuckets.class).to(KadBuckets.class).in(Scopes.SINGLETON);
	bind(NodeStorage.class).to(KadBuckets.class).in(Scopes.SINGLETON);


	bind(FindNodeOperation.class).to(KadFindNodeOperation.class);
	bind(FindNodeHandler.class).to(KademliaFindNodeHandler.class);
	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.findvalue")).to(
			StorageKadCacheFindValueOperation.class);
	bind(KeybasedRouting.class).to(KadNet.class).in(Scopes.SINGLETON);

	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.lastFindValue")).to(
			StorageKadCacheFindValueOperation.class);

}
 
Example 24
Project: OpenKAD-Shades   File: ShadesProtocolModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
	bind(ShadesFindNodeRequest.class);
	bind(NodesByColor.class).in(Scopes.SINGLETON);
	bind(ColorPalette.class).in(Scopes.SINGLETON);
	bind(ShadesBucketsWithColorRefAndPalette.class).in(Scopes.SINGLETON);
	bind(KBuckets.class).to(ShadesBucketsWithColorRefAndPalette.class).in(Scopes.SINGLETON);
	bind(ColoredKBuckets.class).to(ShadesBucketsWithColorRefAndPalette.class).in(Scopes.SINGLETON);

	bind(KadCache.class).to(TinyLfuKadCacheAndStorageWrapper.class).in(Scopes.SINGLETON);
	bind(NodeStorage.class).to(ShadesBucketsWithColorRefAndPalette.class).in(Scopes.SINGLETON);
	bind(FindNodeOperation.class).to(ShadesFindNodeOperation.class);
	bind(FindNodeHandler.class).to(ShadesFindNodeHandler.class);
	bind(SharingPolicy.class).to(LfuSharingPolicy.class).in(Scopes.SINGLETON);

	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.findvalue")).to(ShadesFindValueOperation.class);
	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.lastFindValue")).to(ShadesFindValueOperation.class);

	bind(KeybasedRouting.class).to(KadNet.class).in(Scopes.SINGLETON);
}
 
Example 25
Project: OpenKAD-Shades   File: LocalCacheProtocolModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
	bind(KadCache.class).to(KadCacheAndStorageWrapper.class).in(Scopes.SINGLETON);
	bind(KadCache.class).annotatedWith(Names.named("openkad.inner.cache")).to(LRUKadCache.class);
	
	bind(KadBuckets.class).in(Scopes.SINGLETON);
	bind(KBuckets.class).to(KadBuckets.class).in(Scopes.SINGLETON);
	bind(NodeStorage.class).to(KadBuckets.class).in(Scopes.SINGLETON);

	bind(FindNodeOperation.class).to(KadFindNodeOperation.class);
	bind(FindNodeHandler.class).to(KademliaFindNodeHandler.class);
	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.findvalue")).to(
			StorageLocalCacheFindValueOperation.class);
	bind(KeybasedRouting.class).to(KadNet.class).in(Scopes.SINGLETON);
	bind(FindValueOperation.class).annotatedWith(Names.named("openkad.op.lastFindValue")).to(
			StorageKadCacheFindValueOperation.class);

	


}
 
Example 26
Project: digdag   File: DatabaseModule.java   Source Code and License 6 votes vote down vote up
@Override
public void configure(Binder binder)
{
    binder.bind(DatabaseConfig.class).toProvider(DatabaseConfigProvider.class).in(Scopes.SINGLETON);
    binder.bind(DataSource.class).toProvider(DataSourceProvider.class).in(Scopes.SINGLETON);
    binder.bind(AutoMigrator.class);
    binder.bind(DBI.class).toProvider(DbiProvider.class);  // don't make this singleton because DBI.registerMapper is called for each StoreManager
    binder.bind(TransactionManager.class).to(ThreadLocalTransactionManager.class).in(Scopes.SINGLETON);
    binder.bind(ConfigMapper.class).in(Scopes.SINGLETON);
    binder.bind(DatabaseMigrator.class).in(Scopes.SINGLETON);
    binder.bind(ProjectStoreManager.class).to(DatabaseProjectStoreManager.class).in(Scopes.SINGLETON);
    binder.bind(QueueSettingStoreManager.class).to(DatabaseQueueSettingStoreManager.class).in(Scopes.SINGLETON);
    binder.bind(SessionStoreManager.class).to(DatabaseSessionStoreManager.class).in(Scopes.SINGLETON);
    binder.bind(ScheduleStoreManager.class).to(DatabaseScheduleStoreManager.class).in(Scopes.SINGLETON);
    binder.bind(DatabaseTaskQueueConfig.class).in(Scopes.SINGLETON);
    binder.bind(DatabaseTaskQueueServer.class).in(Scopes.SINGLETON);
}
 
Example 27
Project: ffwd   File: RiemannInputPlugin.java   Source Code and License 6 votes vote down vote up
@Override
public Module module(final Key<PluginSource> key, final String id) {
    return new PrivateModule() {
        @Override
        protected void configure() {
            bind(ProtocolServer.class).to(protocolServer).in(Scopes.SINGLETON);
            bind(Protocol.class).toInstance(protocol);

            bind(RiemannFrameDecoder.class);
            bind(RiemannResponder.class).in(Scopes.SINGLETON);
            bind(RiemannDatagramDecoder.class).in(Scopes.SINGLETON);
            bind(RiemannMessageDecoder.class).in(Scopes.SINGLETON);
            bind(Logger.class).toInstance(log);

            bind(RetryPolicy.class).toInstance(retry);

            bind(key).to(ProtocolPluginSource.class).in(Scopes.SINGLETON);
            expose(key);
        }
    };
}
 
Example 28
Project: ffwd   File: RiemannOutputPlugin.java   Source Code and License 6 votes vote down vote up
@Override
public Module module(final Key<PluginSink> key, final String id) {
    return new OutputPluginModule(id) {
        @Override
        protected void configure() {
            bind(Protocol.class).toInstance(protocol);
            bind(RiemannMessageDecoder.class).in(Scopes.SINGLETON);
            bind(ProtocolClient.class).to(protocolClient).in(Scopes.SINGLETON);

            if (flushInterval != null && flushInterval.isPresent()) {
                bind(BatchedPluginSink.class).toInstance(new ProtocolPluginSink(retry));
                bind(key).toInstance(new FlushingPluginSink(flushInterval.get()));
            } else {
                bind(key).toInstance(new ProtocolPluginSink(retry));
            }
            if (filter != null && filter.isPresent()) {
                bind(Filter.class).toInstance(filter.get());
            }

            expose(key);
        }
    };
}
 
Example 29
Project: ffwd   File: NoopOutputPlugin.java   Source Code and License 6 votes vote down vote up
@Override
public Module module(final Key<PluginSink> key, final String id) {
    return new OutputPluginModule(id) {
        @Override
        protected void configure() {
            if (flushInterval != null) {
                bind(BatchedPluginSink.class).to(NoopPluginSink.class).in(Scopes.SINGLETON);
                bind(key).toInstance(new FlushingPluginSink(flushInterval.get()));
            } else {
                bind(key).to(NoopPluginSink.class).in(Scopes.SINGLETON);
            }

            expose(key);
        }
    };
}
 
Example 30
Project: LanternServer   File: PluginConfigurationModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
    bind(Path.class).annotatedWith(ConfigDirAnnotation.NON_SHARED)
            .toProvider(NonSharedDirAsPath.class).in(Scopes.SINGLETON);
    bind(File.class).annotatedWith(ConfigDirAnnotation.NON_SHARED)
            .toProvider(NonSharedDirAsFile.class).in(Scopes.SINGLETON);
    // Plugin-private directory config file
    bind(Path.class).annotatedWith(DefaultConfigAnnotation.NON_SHARED)
            .toProvider(NonSharedPathAsPath.class).in(Scopes.SINGLETON);
    bind(File.class).annotatedWith(DefaultConfigAnnotation.NON_SHARED)
            .toProvider(NonSharedPathAsFile.class).in(Scopes.SINGLETON);
    // Shared-directory config file
    bind(Path.class).annotatedWith(DefaultConfigAnnotation.SHARED)
            .toProvider(SharedDirAsPath.class).in(Scopes.SINGLETON);
    bind(File.class).annotatedWith(DefaultConfigAnnotation.SHARED)
            .toProvider(SharedDirAsFile.class).in(Scopes.SINGLETON);
    // Loader for shared-directory config file
    bind(COMMENTED_CONFIGURATION_NODE_LOADER).annotatedWith(DefaultConfigAnnotation.SHARED)
            .toProvider(SharedCommentedConfigLoader.class);
    // Loader for plugin-private directory config file
    bind(COMMENTED_CONFIGURATION_NODE_LOADER).annotatedWith(DefaultConfigAnnotation.NON_SHARED)
            .toProvider(NonSharedCommentedConfigLoader.class);
}
 
Example 31
Project: guice-bootstrap   File: TestLifeCycleManager.java   Source Code and License 6 votes vote down vote up
@Test
public void testImmediateStarts()
        throws Exception
{
    Injector injector = Guice.createInjector(
            Stage.PRODUCTION,
            new LifeCycleModule(),
            new Module()
            {
                @Override
                public void configure(Binder binder)
                {
                    binder.bind(InstanceThatRequiresStart.class).in(Scopes.SINGLETON);
                    binder.bind(InstanceThatUsesInstanceThatRequiresStart.class).in(Scopes.SINGLETON);
                }
            });

    LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    lifeCycleManager.start();

    Assert.assertEquals(stateLog, ImmutableList.of("InstanceThatUsesInstanceThatRequiresStart:OK"));
}
 
Example 32
Project: guice-bootstrap   File: TestLifeCycleManager.java   Source Code and License 6 votes vote down vote up
@Test
public void testSubClassAnnotated()
        throws Exception
{
    Injector injector = Guice.createInjector(
            Stage.PRODUCTION,
            new LifeCycleModule(),
            new Module()
            {
                @Override
                public void configure(Binder binder)
                {
                    binder.bind(SimpleBase.class).to(SimpleBaseImpl.class).in(Scopes.SINGLETON);
                }
            });

    LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    lifeCycleManager.start();
    Assert.assertEquals(stateLog, ImmutableList.of("postSimpleBaseImpl"));

    lifeCycleManager.destroy();

    Assert.assertEquals(stateLog, ImmutableList.of("postSimpleBaseImpl", "preSimpleBaseImpl"));
}
 
Example 33
Project: guice-bootstrap   File: TestLifeCycleManager.java   Source Code and License 6 votes vote down vote up
@Test
public void testIllegalMethods()
        throws Exception
{
    try {
        Guice.createInjector(
                Stage.PRODUCTION,
                new Module()
                {
                    @Override
                    public void configure(Binder binder)
                    {
                        binder.bind(IllegalInstance.class).in(Scopes.SINGLETON);
                    }
                },
                new LifeCycleModule());
        Assert.fail();
    }
    catch (CreationException dummy) {
        // correct behavior
    }
}
 
Example 34
Project: guice-bootstrap   File: TestLifeCycleManager.java   Source Code and License 6 votes vote down vote up
@Test
public void testJITInjection()
        throws Exception
{
    Injector injector = Guice.createInjector(
            Stage.PRODUCTION,
            new LifeCycleModule(),
            new Module()
            {
                @Override
                public void configure(Binder binder)
                {
                    binder.bind(AnInstance.class).in(Scopes.SINGLETON);
                    binder.bind(DependentInstance.class).in(Scopes.SINGLETON);
                }
            });
    injector.getInstance(AnInstance.class);

    LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    lifeCycleManager.start();
    lifeCycleManager.destroy();

    Assert.assertEquals(stateLog, ImmutableList.of("postDependentInstance", "preDependentInstance"));
}
 
Example 35
Project: guice-bootstrap   File: TestLifeCycleManager.java   Source Code and License 6 votes vote down vote up
@Test
public void testNoPreDestroy()
        throws Exception
{
    Injector injector = Guice.createInjector(
            Stage.PRODUCTION,
            new LifeCycleModule(),
            new Module()
            {
                @Override
                public void configure(Binder binder)
                {
                    binder.bind(PostConstructOnly.class).in(Scopes.SINGLETON);
                    binder.bind(PreDestroyOnly.class).in(Scopes.SINGLETON);
                }
            });
    injector.getInstance(PostConstructOnly.class);

    LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    lifeCycleManager.start();
    Assert.assertEquals(stateLog, ImmutableList.of("makeMe"));

    lifeCycleManager.destroy();
    Assert.assertEquals(stateLog, ImmutableList.of("makeMe", "unmakeMe"));
}
 
Example 36
Project: guiceberry   File: Example2ScopesTest.java   Source Code and License 6 votes vote down vote up
@Override
protected void configure() {
  install(new GuiceBerryModule());
  IncrementingProvider unscopedIncrementingNumberProvider = 
    new IncrementingProvider(100);
  IncrementingProvider testScopedIncrementingNumberProvider = 
    new IncrementingProvider(200);
  IncrementingProvider singletonScopedIncrementingNumberProvider = 
    new IncrementingProvider(300);
  bind(Integer.class)
    .annotatedWith(UnscopedIncrementingNumber.class)
    .toProvider(unscopedIncrementingNumberProvider);
  bind(Integer.class)
    .annotatedWith(TestScopedIncrementingNumber.class)
    .toProvider(testScopedIncrementingNumberProvider)
    .in(TestScoped.class);
  bind(Integer.class)
    .annotatedWith(SingletonScopedIncrementingNumber.class)
    .toProvider(singletonScopedIncrementingNumberProvider)
    .in(Scopes.SINGLETON);
}
 
Example 37
Project: gerrit   File: AutoRegisterModules.java   Source Code and License 6 votes vote down vote up
private Module makeSystemModule() {
  return new AbstractModule() {
    @Override
    protected void configure() {
      for (Class<?> clazz : sysSingletons) {
        bind(clazz).in(Scopes.SINGLETON);
      }
      for (Map.Entry<TypeLiteral<?>, Class<?>> e : sysListen.entries()) {
        @SuppressWarnings("unchecked")
        TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();

        @SuppressWarnings("unchecked")
        Class<Object> impl = (Class<Object>) e.getValue();

        Annotation n = calculateBindAnnotation(impl);
        bind(type).annotatedWith(n).to(impl);
      }
      if (initJs != null) {
        DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin(initJs));
      }
    }
  };
}
 
Example 38
Project: presto   File: RaptorModule.java   Source Code and License 6 votes vote down vote up
@Override
public void configure(Binder binder)
{
    binder.bind(RaptorConnectorId.class).toInstance(new RaptorConnectorId(connectorId));
    binder.bind(RaptorConnector.class).in(Scopes.SINGLETON);
    binder.bind(RaptorMetadataFactory.class).in(Scopes.SINGLETON);
    binder.bind(RaptorSplitManager.class).in(Scopes.SINGLETON);
    binder.bind(RaptorPageSourceProvider.class).in(Scopes.SINGLETON);
    binder.bind(RaptorPageSinkProvider.class).in(Scopes.SINGLETON);
    binder.bind(RaptorSessionProperties.class).in(Scopes.SINGLETON);
    binder.bind(RaptorTableProperties.class).in(Scopes.SINGLETON);
    binder.bind(NodeSupplier.class).to(RaptorNodeSupplier.class).in(Scopes.SINGLETON);

    Multibinder<SystemTable> tableBinder = newSetBinder(binder, SystemTable.class);
    tableBinder.addBinding().to(ShardMetadataSystemTable.class).in(Scopes.SINGLETON);

    jsonCodecBinder(binder).bindJsonCodec(ShardInfo.class);
    jsonCodecBinder(binder).bindJsonCodec(ShardDelta.class);
}
 
Example 39
Project: presto   File: BackupModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    configBinder(binder).bindConfig(BackupConfig.class);

    String provider = buildConfigObject(BackupConfig.class).getProvider();
    if (provider == null) {
        binder.bind(BackupStore.class).toProvider(Providers.of(null));
    }
    else {
        Module module = providers.get(provider);
        if (module == null) {
            binder.addError("Unknown backup provider: %s", provider);
        }
        else {
            binder.install(module);
        }
    }
    binder.bind(BackupService.class).to(BackupServiceManager.class).in(Scopes.SINGLETON);
}
 
Example 40
Project: presto   File: StorageModule.java   Source Code and License 6 votes vote down vote up
@Override
public void configure(Binder binder)
{
    configBinder(binder).bindConfig(StorageManagerConfig.class);
    configBinder(binder).bindConfig(ShardCleanerConfig.class);

    binder.bind(StorageManager.class).to(OrcStorageManager.class).in(Scopes.SINGLETON);
    binder.bind(StorageService.class).to(FileStorageService.class).in(Scopes.SINGLETON);
    binder.bind(ShardManager.class).to(DatabaseShardManager.class).in(Scopes.SINGLETON);
    binder.bind(ShardRecorder.class).to(DatabaseShardManager.class).in(Scopes.SINGLETON);
    binder.bind(DatabaseShardManager.class).in(Scopes.SINGLETON);
    binder.bind(ShardRecoveryManager.class).in(Scopes.SINGLETON);
    binder.bind(BackupManager.class).in(Scopes.SINGLETON);
    binder.bind(ShardCompactionManager.class).in(Scopes.SINGLETON);
    binder.bind(ShardCompactor.class).in(Scopes.SINGLETON);
    binder.bind(ShardEjector.class).in(Scopes.SINGLETON);
    binder.bind(ShardCleaner.class).in(Scopes.SINGLETON);
    binder.bind(ReaderAttributes.class).in(Scopes.SINGLETON);

    newExporter(binder).export(ShardRecoveryManager.class).as(generatedNameOf(ShardRecoveryManager.class, connectorId));
    newExporter(binder).export(BackupManager.class).as(generatedNameOf(BackupManager.class, connectorId));
    newExporter(binder).export(StorageManager.class).as(generatedNameOf(OrcStorageManager.class, connectorId));
    newExporter(binder).export(ShardCompactionManager.class).as(generatedNameOf(ShardCompactionManager.class, connectorId));
    newExporter(binder).export(ShardCompactor.class).as(generatedNameOf(ShardCompactor.class, connectorId));
    newExporter(binder).export(ShardEjector.class).as(generatedNameOf(ShardEjector.class, connectorId));
}