Skip to content

Commit

Permalink
Deprecate and remove usages of duplicatePluginClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Nov 14, 2023
1 parent e71bbdc commit b408b07
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ default PageIndexerFactory getPageIndexerFactory()
throw new UnsupportedOperationException();
}

@Deprecated(forRemoval = true)
default ClassLoader duplicatePluginClassLoader()
{
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@
import io.trino.spi.connector.ConnectorContext;
import io.trino.spi.connector.ConnectorFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Optional;

import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.inject.util.Modules.EMPTY_MODULE;
import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch;
import static io.trino.plugin.deltalake.InternalDeltaLakeConnectorFactory.createConnector;
import static java.util.Objects.requireNonNull;

public class DeltaLakeConnectorFactory
implements ConnectorFactory
{
public static final String CONNECTOR_NAME = "delta_lake";

private final Class<? extends Module> module;
private final Module module;

public DeltaLakeConnectorFactory(Class<? extends Module> module)
public DeltaLakeConnectorFactory()
{
this(EMPTY_MODULE);
}

public DeltaLakeConnectorFactory(Module module)
{
this.module = requireNonNull(module, "module is null");
}
Expand All @@ -48,22 +53,6 @@ public String getName()
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
checkStrictSpiVersionMatch(context, this);

ClassLoader classLoader = context.duplicatePluginClassLoader();
try {
Class<?> moduleClass = classLoader.loadClass(Module.class.getName());
Object moduleInstance = classLoader.loadClass(module.getName()).getConstructor().newInstance();
return (Connector) classLoader.loadClass(InternalDeltaLakeConnectorFactory.class.getName())
.getMethod("createConnector", String.class, Map.class, ConnectorContext.class, Optional.class, Optional.class, moduleClass)
.invoke(null, catalogName, config, context, Optional.empty(), Optional.empty(), moduleInstance);
}
catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
throwIfUnchecked(targetException);
throw new RuntimeException(targetException);
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return createConnector(catalogName, config, context, Optional.empty(), Optional.empty(), module);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package io.trino.plugin.deltalake;

import com.google.common.collect.ImmutableList;
import com.google.inject.Module;
import io.trino.plugin.hive.HiveConnectorFactory.EmptyModule;
import io.trino.spi.Plugin;
import io.trino.spi.connector.ConnectorFactory;

Expand All @@ -25,11 +23,6 @@ public class DeltaLakePlugin
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
return ImmutableList.of(getConnectorFactory(EmptyModule.class));
}

public ConnectorFactory getConnectorFactory(Class<? extends Module> module)
{
return new DeltaLakeConnectorFactory(module);
return ImmutableList.of(new DeltaLakeConnectorFactory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@
*/
package io.trino.plugin.hive;

import com.google.inject.Binder;
import com.google.inject.Module;
import io.trino.spi.connector.Connector;
import io.trino.spi.connector.ConnectorContext;
import io.trino.spi.connector.ConnectorFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.inject.util.Modules.EMPTY_MODULE;
import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch;
import static io.trino.plugin.hive.InternalHiveConnectorFactory.createConnector;
import static java.util.Objects.requireNonNull;

public class HiveConnectorFactory
implements ConnectorFactory
{
private final Class<? extends Module> module;
private final Module module;

public HiveConnectorFactory()
{
this(EmptyModule.class);
this(EMPTY_MODULE);
}

public HiveConnectorFactory(Class<? extends Module> module)
public HiveConnectorFactory(Module module)
{
this.module = requireNonNull(module, "module is null");
}
Expand All @@ -51,29 +50,6 @@ public String getName()
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
checkStrictSpiVersionMatch(context, this);

ClassLoader classLoader = context.duplicatePluginClassLoader();
try {
Object moduleInstance = classLoader.loadClass(module.getName()).getConstructor().newInstance();
Class<?> moduleClass = classLoader.loadClass(Module.class.getName());
return (Connector) classLoader.loadClass(InternalHiveConnectorFactory.class.getName())
.getMethod("createConnector", String.class, Map.class, ConnectorContext.class, moduleClass)
.invoke(null, catalogName, config, context, moduleInstance);
}
catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
throwIfUnchecked(targetException);
throw new RuntimeException(targetException);
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}

public static class EmptyModule
implements Module
{
@Override
public void configure(Binder binder) {}
return createConnector(catalogName, config, context, module);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
import io.trino.spi.connector.ConnectorContext;
import io.trino.spi.connector.ConnectorFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Optional;

import static com.google.common.base.Throwables.throwIfUnchecked;
import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch;
import static io.trino.plugin.hudi.InternalHudiConnectorFactory.createConnector;

public class HudiConnectorFactory
implements ConnectorFactory
{
public HudiConnectorFactory()
{}

@Override
public String getName()
{
Expand All @@ -40,20 +36,6 @@ public String getName()
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
checkStrictSpiVersionMatch(context, this);

ClassLoader classLoader = context.duplicatePluginClassLoader();
try {
return (Connector) classLoader.loadClass(InternalHudiConnectorFactory.class.getName())
.getMethod("createConnector", String.class, Map.class, ConnectorContext.class, Optional.class, Optional.class)
.invoke(null, catalogName, config, context, Optional.empty(), Optional.empty());
}
catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
throwIfUnchecked(targetException);
throw new RuntimeException(targetException);
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return createConnector(catalogName, config, context, Optional.empty(), Optional.empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@
*/
package io.trino.plugin.iceberg;

import com.google.inject.Binder;
import com.google.inject.Module;
import io.trino.spi.connector.Connector;
import io.trino.spi.connector.ConnectorContext;
import io.trino.spi.connector.ConnectorFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Optional;

import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.inject.util.Modules.EMPTY_MODULE;
import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch;
import static io.trino.plugin.iceberg.InternalIcebergConnectorFactory.createConnector;
import static java.util.Objects.requireNonNull;

public class IcebergConnectorFactory
implements ConnectorFactory
{
private final Class<? extends Module> module;
private final Module module;

public IcebergConnectorFactory()
{
this(EmptyModule.class);
this(EMPTY_MODULE);
}

public IcebergConnectorFactory(Class<? extends Module> module)
public IcebergConnectorFactory(Module module)
{
this.module = requireNonNull(module, "module is null");
}
Expand All @@ -52,29 +51,6 @@ public String getName()
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
checkStrictSpiVersionMatch(context, this);

ClassLoader classLoader = context.duplicatePluginClassLoader();
try {
Object moduleInstance = classLoader.loadClass(module.getName()).getConstructor().newInstance();
Class<?> moduleClass = classLoader.loadClass(Module.class.getName());
return (Connector) classLoader.loadClass(InternalIcebergConnectorFactory.class.getName())
.getMethod("createConnector", String.class, Map.class, ConnectorContext.class, moduleClass, Optional.class, Optional.class)
.invoke(null, catalogName, config, context, moduleInstance, Optional.empty(), Optional.empty());
}
catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
throwIfUnchecked(targetException);
throw new RuntimeException(targetException);
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}

public static class EmptyModule
implements Module
{
@Override
public void configure(Binder binder) {}
return createConnector(catalogName, config, context, module, Optional.empty(), Optional.empty());
}
}

0 comments on commit b408b07

Please sign in to comment.