Java Code Examples for io.prestosql.spi.connector.ConnectorContext

The following examples show how to use io.prestosql.spi.connector.ConnectorContext. 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 check out the related API usage on the sidebar.
Example 1
Source Project: presto   Source File: KafkaConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new KafkaConnectorModule(),
            extension,
            binder -> {
                binder.bind(ClassLoader.class).toInstance(KafkaConnectorFactory.class.getClassLoader());
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(KafkaConnector.class);
}
 
Example 2
Source Project: presto   Source File: PrometheusConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");
    try {
        // A plugin is not required to use Guice; it is just very convenient
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new PrometheusModule(context.getTypeManager()));

        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(requiredConfig)
                .initialize();

        return injector.getInstance(PrometheusConnector.class);
    }
    catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example 3
Source Project: presto   Source File: ExampleConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    // A plugin is not required to use Guice; it is just very convenient
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new ExampleModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(requiredConfig)
            .initialize();

    return injector.getInstance(ExampleConnector.class);
}
 
Example 4
Source Project: presto   Source File: TestCoordinatorDynamicFiltering.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
    return ImmutableList.of(new ConnectorFactory()
    {
        private final ConnectorMetadata metadata = new TestingMetadata();

        @Override
        public String getName()
        {
            return "test";
        }

        @Override
        public ConnectorHandleResolver getHandleResolver()
        {
            return new TestingHandleResolver();
        }

        @Override
        public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
        {
            return new TestConnector(metadata, Duration.valueOf("10s"), expectedDynamicFilter);
        }
    });
}
 
Example 5
Source Project: presto   Source File: TestBeginQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
    return ImmutableList.of(new ConnectorFactory()
    {
        @Override
        public String getName()
        {
            return "test";
        }

        @Override
        public ConnectorHandleResolver getHandleResolver()
        {
            return new TestingHandleResolver();
        }

        @Override
        public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
        {
            return new TestConnector(metadata);
        }
    });
}
 
Example 6
Source Project: presto   Source File: JmxConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    Bootstrap app = new Bootstrap(
            new MBeanServerModule(),
            binder -> {
                configBinder(binder).bindConfig(JmxConnectorConfig.class);
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
                binder.bind(JmxConnector.class).in(Scopes.SINGLETON);
                binder.bind(JmxHistoricalData.class).in(Scopes.SINGLETON);
                binder.bind(JmxMetadata.class).in(Scopes.SINGLETON);
                binder.bind(JmxSplitManager.class).in(Scopes.SINGLETON);
                binder.bind(JmxPeriodicSampler.class).in(Scopes.SINGLETON);
                binder.bind(JmxRecordSetProvider.class).in(Scopes.SINGLETON);
            });

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(JmxConnector.class);
}
 
Example 7
Source Project: presto   Source File: AccumuloConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "requiredConfig is null");
    requireNonNull(context, "context is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new AccumuloModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(AccumuloConnector.class);
}
 
Example 8
Source Project: presto   Source File: JdbcConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    Bootstrap app = new Bootstrap(
            binder -> binder.bind(TypeManager.class).toInstance(context.getTypeManager()),
            binder -> binder.bind(NodeManager.class).toInstance(context.getNodeManager()),
            binder -> binder.bind(VersionEmbedder.class).toInstance(context.getVersionEmbedder()),
            new JdbcModule(catalogName),
            moduleProvider.getModule(catalogName));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(requiredConfig)
            .initialize();

    return injector.getInstance(JdbcConnector.class);
}
 
Example 9
Source Project: presto   Source File: PhoenixConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new MBeanServerModule(),
                new MBeanModule(),
                new PhoenixClientModule(catalogName),
                binder -> {
                    binder.bind(ClassLoader.class).toInstance(PhoenixConnectorFactory.class.getClassLoader());
                    binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                });

        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(requiredConfig)
                .initialize();

        return injector.getInstance(PhoenixConnector.class);
    }
}
 
Example 10
Source Project: presto   Source File: MockConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
private MockConnector(
        ConnectorContext context,
        Function<ConnectorSession, List<String>> listSchemaNames,
        BiFunction<ConnectorSession, String, List<SchemaTableName>> listTables,
        BiFunction<ConnectorSession, SchemaTablePrefix, Map<SchemaTableName, ConnectorViewDefinition>> getViews,
        BiFunction<ConnectorSession, SchemaTableName, ConnectorTableHandle> getTableHandle,
        Function<SchemaTableName, List<ColumnMetadata>> getColumns,
        ApplyProjection applyProjection,
        BiFunction<ConnectorSession, SchemaTableName, Optional<ConnectorNewTableLayout>> getInsertLayout,
        BiFunction<ConnectorSession, ConnectorTableMetadata, Optional<ConnectorNewTableLayout>> getNewTableLayout,
        Supplier<Iterable<EventListener>> eventListeners,
        ListRoleGrants roleGrants)
{
    this.context = requireNonNull(context, "context is null");
    this.listSchemaNames = requireNonNull(listSchemaNames, "listSchemaNames is null");
    this.listTables = requireNonNull(listTables, "listTables is null");
    this.getViews = requireNonNull(getViews, "getViews is null");
    this.getTableHandle = requireNonNull(getTableHandle, "getTableHandle is null");
    this.getColumns = requireNonNull(getColumns, "getColumns is null");
    this.applyProjection = requireNonNull(applyProjection, "applyProjection is null");
    this.getInsertLayout = requireNonNull(getInsertLayout, "getInsertLayout is null");
    this.getNewTableLayout = requireNonNull(getNewTableLayout, "getNewTableLayout is null");
    this.eventListeners = requireNonNull(eventListeners, "eventListeners is null");
    this.roleGrants = requireNonNull(roleGrants, "roleGrants is null");
}
 
Example 11
Source Project: presto   Source File: MongoConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MongoClientModule(),
            binder -> binder.bind(TypeManager.class).toInstance(context.getTypeManager()));

    Injector injector = app.strictConfig().doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(MongoConnector.class);
}
 
Example 12
Source Project: presto   Source File: MemoryConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    // A plugin is not required to use Guice; it is just very convenient
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MemoryModule(context.getTypeManager(), context.getNodeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(requiredConfig)
            .initialize();

    return injector.getInstance(MemoryConnector.class);
}
 
Example 13
Source Project: presto   Source File: ElasticsearchConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new MBeanModule(),
            new MBeanServerModule(),
            new ConnectorObjectNameGeneratorModule(catalogName, "io.prestosql.elasticsearch", "presto.plugin.elasticsearch"),
            new JsonModule(),
            new ElasticsearchConnectorModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(ElasticsearchConnector.class);
}
 
Example 14
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new ElasticsearchConnectorModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(ElasticsearchConnector.class);
}
 
Example 15
Source Project: presto   Source File: ThriftConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    Bootstrap app = new Bootstrap(
            new MBeanModule(),
            new MBeanServerModule(),
            new ConnectorObjectNameGeneratorModule(catalogName, "io.prestosql.plugin.thrift", "presto.plugin.thrift"),
            new DriftNettyClientModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            },
            locationModule,
            new ThriftModule());

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(ThriftConnector.class);
}
 
Example 16
Source Project: presto   Source File: BigQueryConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new BigQueryConnectorModule(context.getNodeManager()),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(BigQueryConnector.class);
}
 
Example 17
Source Project: presto   Source File: LocalFileConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            binder -> binder.bind(NodeManager.class).toInstance(context.getNodeManager()),
            new LocalFileModule());

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(LocalFileConnector.class);
}
 
Example 18
Source Project: presto   Source File: CassandraConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new MBeanModule(),
            new JsonModule(),
            new CassandraClientModule(),
            new MBeanServerModule());

    Injector injector = app.strictConfig().doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(CassandraConnector.class);
}
 
Example 19
Source Project: presto   Source File: KuduConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new KuduModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(KuduConnector.class);
}
 
Example 20
Source Project: presto   Source File: SheetsConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new SheetsModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(SheetsConnector.class);
}
 
Example 21
Source Project: presto   Source File: PinotConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "connectorId is null");
    requireNonNull(config, "config is null");
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MBeanModule(),
            new PinotModule(catalogName, context.getTypeManager(), context.getNodeManager()));

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(PinotConnector.class);
}
 
Example 22
Source Project: presto   Source File: RedisConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new RedisConnectorModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());

                if (tableDescriptionSupplier.isPresent()) {
                    binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, RedisTableDescription>>>() {}).toInstance(tableDescriptionSupplier.get());
                }
                else {
                    binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, RedisTableDescription>>>() {})
                            .to(RedisTableDescriptionSupplier.class)
                            .in(Scopes.SINGLETON);
                }
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(RedisConnector.class);
}
 
Example 23
Source Project: presto   Source File: BlackHoleConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    ListeningScheduledExecutorService executorService = listeningDecorator(newSingleThreadScheduledExecutor(daemonThreadsNamed("blackhole")));
    return new BlackHoleConnector(
            new BlackHoleMetadata(),
            new BlackHoleSplitManager(),
            new BlackHolePageSourceProvider(executorService),
            new BlackHolePageSinkProvider(executorService),
            new BlackHoleNodePartitioningProvider(context.getNodeManager()),
            context.getTypeManager(),
            executorService);
}
 
Example 24
Source Project: presto   Source File: TpcdsConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    int splitsPerNode = getSplitsPerNode(config);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector()
    {
        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
        {
            return TpcdsTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle)
        {
            return new TpcdsMetadata();
        }

        @Override
        public ConnectorSplitManager getSplitManager()
        {
            return new TpcdsSplitManager(nodeManager, splitsPerNode, isWithNoSexism(config));
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider()
        {
            return new TpcdsRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider()
        {
            return new TpcdsNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
 
Example 25
Source Project: presto   Source File: ConnectorManager.java    License: Apache License 2.0 5 votes vote down vote up
private Connector createConnector(CatalogName catalogName, InternalConnectorFactory factory, Map<String, String> properties)
{
    ConnectorContext context = new ConnectorContextInstance(
            new ConnectorAwareNodeManager(nodeManager, nodeInfo.getEnvironment(), catalogName),
            versionEmbedder,
            new InternalTypeManager(metadataManager),
            pageSorter,
            pageIndexerFactory,
            factory.getDuplicatePluginClassLoaderFactory());

    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getConnectorFactory().getClass().getClassLoader())) {
        return factory.getConnectorFactory().create(catalogName.getCatalogName(), properties, context);
    }
}
 
Example 26
Source Project: presto   Source File: RaptorConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MBeanModule(),
            new ConnectorObjectNameGeneratorModule(catalogName, "io.prestosql.plugin.raptor.legacy", "presto.plugin.raptor.legacy"),
            new MBeanServerModule(),
            binder -> {
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
                binder.bind(PageSorter.class).toInstance(context.getPageSorter());
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            },
            metadataModule,
            new BackupModule(backupProviders),
            new StorageModule(),
            new RaptorModule(catalogName),
            new RaptorSecurityModule(catalogName));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(RaptorConnector.class);
}
 
Example 27
Source Project: presto   Source File: KinesisConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    try {
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new KinesisModule(),
                binder -> {
                    binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                    binder.bind(NodeManager.class).toInstance(context.getNodeManager());
                    binder.bind(KinesisHandleResolver.class).toInstance(new KinesisHandleResolver());
                    binder.bind(KinesisClientProvider.class).to(KinesisClientManager.class).in(Scopes.SINGLETON);
                    binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KinesisStreamDescription>>>() {}).to(KinesisTableDescriptionSupplier.class).in(Scopes.SINGLETON);
                });

        Injector injector = app.strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(config)
                .initialize();

        KinesisConnector connector = injector.getInstance(KinesisConnector.class);
        return connector;
    }
    catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example 28
Source Project: presto   Source File: TestingKinesisConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "connectorId is null");
    requireNonNull(config, "config is null");

    try {
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new KinesisModule(),
                binder -> {
                    binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                    binder.bind(NodeManager.class).toInstance(context.getNodeManager());
                    binder.bind(KinesisHandleResolver.class).toInstance(new KinesisHandleResolver());
                    binder.bind(KinesisClientProvider.class).toInstance(kinesisClientProvider);
                    binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KinesisStreamDescription>>>() {}).to(KinesisTableDescriptionSupplier.class).in(Scopes.SINGLETON);
                });

        Injector injector = app.strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(config)
                .initialize();

        KinesisConnector connector = injector.getInstance(KinesisConnector.class);
        return connector;
    }
    catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example 29
Source Project: presto   Source File: AtopConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(
                new AtopModule(
                        atopFactoryClass,
                        context.getTypeManager(),
                        context.getNodeManager(),
                        context.getNodeManager().getEnvironment(),
                        catalogName),
                installModuleIf(
                        AtopConnectorConfig.class,
                        config -> config.getSecurity() == AtopSecurity.NONE,
                        new AllowAllAccessControlModule()),
                installModuleIf(
                        AtopConnectorConfig.class,
                        config -> config.getSecurity() == AtopSecurity.FILE,
                        binder -> {
                            binder.install(new FileBasedAccessControlModule(catalogName));
                            binder.install(new JsonModule());
                        }));

        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(requiredConfig)
                .initialize();

        return injector.getInstance(AtopConnector.class);
    }
}
 
Example 30
Source Project: pulsar   Source File: PulsarConnectorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "requiredConfig is null");
    if (log.isDebugEnabled()) {
        log.debug("Creating Pulsar connector with configs: %s", config);
    }
    try {
        // A plugin is not required to use Guice; it is just very convenient
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new PulsarConnectorModule(connectorId, context.getTypeManager())
        );

        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(config)
                .initialize();

        PulsarConnector connector = injector.getInstance(PulsarConnector.class);
        connector.initConnectorCache();
        return connector;
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}