Search in sources :

Example 16 with JsonModule

use of io.airlift.json.JsonModule 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 JsonModule

use of io.airlift.json.JsonModule 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 JsonModule

use of io.airlift.json.JsonModule 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)

Example 19 with JsonModule

use of io.airlift.json.JsonModule in project presto by prestodb.

the class TestHttpBackupStore method setup.

@BeforeMethod
public void setup() throws Exception {
    temporary = createTempDir();
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("backup.http.uri", "http://localhost:8080").build();
    Bootstrap app = new Bootstrap(new TestingNodeModule(), new TestingHttpServerModule(), new JsonModule(), new JaxrsModule(true), binder -> jaxrsBinder(binder).bind(TestingHttpBackupResource.class), override(new HttpBackupModule()).with(new TestingModule()));
    Injector injector = app.strictConfig().setRequiredConfigurationProperties(properties).doNotInitializeLogging().initialize();
    lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    store = injector.getInstance(BackupStore.class);
}
Also used : TestingHttpServerModule(io.airlift.http.server.testing.TestingHttpServerModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) JaxrsModule(io.airlift.jaxrs.JaxrsModule) JsonModule(io.airlift.json.JsonModule) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Injector (com.google.inject.Injector)19 JsonModule (io.airlift.json.JsonModule)19 Bootstrap (io.airlift.bootstrap.Bootstrap)17 ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)6 MBeanModule (org.weakref.jmx.guice.MBeanModule)4 NodeManager (com.facebook.presto.spi.NodeManager)3 TypeManager (com.facebook.presto.spi.type.TypeManager)3 Module (com.google.inject.Module)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)3 JaxrsModule (io.airlift.jaxrs.JaxrsModule)3 Map (java.util.Map)3 MBeanServer (javax.management.MBeanServer)3 BeforeMethod (org.testng.annotations.BeforeMethod)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 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Binder (com.google.inject.Binder)2 TypeLiteral (com.google.inject.TypeLiteral)2 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)2