Search in sources :

Example 16 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project carbondata by apache.

the class CarbondataConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new JsonModule(), new CarbondataModule(connectorId, context.getTypeManager()));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
        CarbondataMetadata metadata = injector.getInstance(CarbondataMetadata.class);
        ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
        ConnectorRecordSetProvider connectorRecordSet = injector.getInstance(ConnectorRecordSetProvider.class);
        ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
        return new CarbondataConnector(lifeCycleManager, metadata, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), connectorRecordSet, classLoader, new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : JsonModule(io.airlift.json.JsonModule) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) Injector(com.google.inject.Injector) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) Bootstrap(io.airlift.bootstrap.Bootstrap) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader)

Example 17 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class MongoConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try {
        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);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) JsonModule(io.airlift.json.JsonModule)

Example 18 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class JmxConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    try {
        Bootstrap app = new Bootstrap(binder -> {
            configBinder(binder).bindConfig(JmxConnectorConfig.class);
            binder.bind(MBeanServer.class).toInstance(new RebindSafeMBeanServer(mbeanServer));
            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);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : NodeManager(com.facebook.presto.spi.NodeManager) RebindSafeMBeanServer(com.facebook.presto.connector.jmx.util.RebindSafeMBeanServer) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) MBeanServer(javax.management.MBeanServer) RebindSafeMBeanServer(com.facebook.presto.connector.jmx.util.RebindSafeMBeanServer)

Example 19 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class LocalFileConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try {
        Bootstrap app = new Bootstrap(binder -> binder.bind(NodeManager.class).toInstance(context.getNodeManager()), new LocalFileModule(connectorId));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(LocalFileConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap)

Example 20 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class AccumuloConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(connectorId, "connectorId is null");
    requireNonNull(config, "requiredConfig is null");
    requireNonNull(context, "context is null");
    try {
        // A plugin is not required to use Guice; it is just very convenient
        // Unless you don't really know how to Guice, then it is less convenient
        Bootstrap app = new Bootstrap(new JsonModule(), new AccumuloModule(connectorId, context.getTypeManager()));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(AccumuloConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) JsonModule(io.airlift.json.JsonModule)

Aggregations

Injector (com.google.inject.Injector)21 Bootstrap (io.airlift.bootstrap.Bootstrap)21 JsonModule (io.airlift.json.JsonModule)17 ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)7 NodeManager (com.facebook.presto.spi.NodeManager)4 Module (com.google.inject.Module)4 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)4 MBeanServer (javax.management.MBeanServer)4 MBeanModule (org.weakref.jmx.guice.MBeanModule)4 TypeManager (com.facebook.presto.spi.type.TypeManager)3 TypeLiteral (com.google.inject.TypeLiteral)3 JaxrsModule (io.airlift.jaxrs.JaxrsModule)3 Map (java.util.Map)3 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 ClassLoaderSafeConnectorPageSourceProvider (com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider)2 ClassLoaderSafeConnectorSplitManager (com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager)2 ImmutableList (com.google.common.collect.ImmutableList)2 Binder (com.google.inject.Binder)2 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)2 Supplier (java.util.function.Supplier)2