mirror of https://github.com/apache/druid.git
Make Jetty Server lazy
JettyServerModule had been eagerly instantiating the Server object, which was causing things that didn't care about an HTTP interface to all of a sudden require host and port parameters. The change makes the JettyServerModule only setup the bindings without eagerly instantiating the Jetty Server. Each cli needs to register the Server class with the Lifecycle in order to make it actually get used.
This commit is contained in:
parent
dc8a119787
commit
cc632cdb30
|
@ -25,11 +25,9 @@ import com.google.inject.Binder;
|
|||
import com.google.inject.ConfigurationException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.name.Names;
|
||||
import com.metamx.common.lifecycle.Lifecycle;
|
||||
import com.metamx.common.logger.Logger;
|
||||
import com.sun.jersey.api.core.DefaultResourceConfig;
|
||||
|
@ -72,8 +70,6 @@ public class JettyServerModule extends JerseyServletModule
|
|||
|
||||
Jerseys.addResource(binder, StatusResource.class);
|
||||
binder.bind(StatusResource.class).in(LazySingleton.class);
|
||||
|
||||
binder.bind(Key.get(Server.class, Names.named("ForTheEagerness"))).to(Server.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
public static class DruidGuiceContainer extends GuiceContainer
|
||||
|
|
|
@ -34,6 +34,7 @@ import io.druid.curator.discovery.DiscoveryModule;
|
|||
import io.druid.guice.Jerseys;
|
||||
import io.druid.guice.JsonConfigProvider;
|
||||
import io.druid.guice.LazySingleton;
|
||||
import io.druid.guice.LifecycleModule;
|
||||
import io.druid.guice.ManageLifecycle;
|
||||
import io.druid.guice.annotations.Self;
|
||||
import io.druid.query.MapQueryToolChestWarehouse;
|
||||
|
@ -43,6 +44,7 @@ import io.druid.server.ClientInfoResource;
|
|||
import io.druid.server.ClientQuerySegmentWalker;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.metrics.MetricsModule;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -84,6 +86,8 @@ public class CliBroker extends ServerRunnable
|
|||
|
||||
DiscoveryModule.register(binder, Self.class);
|
||||
MetricsModule.register(binder, CacheMonitor.class);
|
||||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -54,6 +54,7 @@ import io.druid.server.master.DruidMaster;
|
|||
import io.druid.server.master.DruidMasterConfig;
|
||||
import io.druid.server.master.LoadQueueTaskMaster;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -110,6 +111,8 @@ public class CliCoordinator extends ServerRunnable
|
|||
Jerseys.addResource(binder, BackwardsCompatiableInfoResource.class);
|
||||
Jerseys.addResource(binder, InfoResource.class);
|
||||
Jerseys.addResource(binder, MasterResource.class);
|
||||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -34,6 +34,7 @@ import io.druid.server.coordination.ZkCoordinator;
|
|||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.metrics.MetricsModule;
|
||||
import io.druid.server.metrics.ServerMonitor;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -65,10 +66,12 @@ public class CliHistorical extends ServerRunnable
|
|||
binder.bind(ZkCoordinator.class).in(ManageLifecycle.class);
|
||||
binder.bind(QuerySegmentWalker.class).to(ServerManager.class).in(LazySingleton.class);
|
||||
|
||||
LifecycleModule.register(binder, ZkCoordinator.class);
|
||||
MetricsModule.register(binder, ServerMonitor.class);
|
||||
binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig("historical"));
|
||||
binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
|
||||
|
||||
LifecycleModule.register(binder, ZkCoordinator.class);
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -41,6 +41,7 @@ import io.druid.indexing.worker.config.WorkerConfig;
|
|||
import io.druid.indexing.worker.http.WorkerResource;
|
||||
import io.druid.server.DruidNode;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -81,6 +82,8 @@ public class CliMiddleManager extends ServerRunnable
|
|||
LifecycleModule.register(binder, WorkerTaskMonitor.class);
|
||||
binder.bind(JettyServerInitializer.class).toInstance(new MiddleManagerJettyServerInitializer());
|
||||
Jerseys.addResource(binder, WorkerResource.class);
|
||||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -34,6 +34,7 @@ import io.druid.guice.JacksonConfigProvider;
|
|||
import io.druid.guice.Jerseys;
|
||||
import io.druid.guice.JsonConfigProvider;
|
||||
import io.druid.guice.LazySingleton;
|
||||
import io.druid.guice.LifecycleModule;
|
||||
import io.druid.guice.ListProvider;
|
||||
import io.druid.guice.ManageLifecycle;
|
||||
import io.druid.guice.PolyBind;
|
||||
|
@ -138,6 +139,8 @@ public class CliOverlord extends ServerRunnable
|
|||
|
||||
binder.bind(JettyServerInitializer.class).toInstance(new OverlordJettyServerInitializer());
|
||||
Jerseys.addResource(binder, IndexerCoordinatorResource.class);
|
||||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
|
||||
private void configureTaskStorage(Binder binder)
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.druid.segment.realtime.RealtimeManager;
|
|||
import io.druid.segment.realtime.SegmentPublisher;
|
||||
import io.druid.segment.realtime.firehose.KafkaFirehoseFactory;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -54,6 +55,8 @@ public class RealtimeModule implements DruidModule
|
|||
binder.bind(QuerySegmentWalker.class).to(RealtimeManager.class).in(ManageLifecycle.class);
|
||||
binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig("realtime"));
|
||||
binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
|
||||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue