Skip to content

Commit

Permalink
Make Jetty Server lazy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cheddar committed Sep 23, 2013
1 parent dc8a119 commit cc632cd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
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;
Expand Down Expand Up @@ -72,8 +70,6 @@ protected void configureServlets()

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
Expand Down
4 changes: 4 additions & 0 deletions services/src/main/java/io/druid/cli/CliBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand All @@ -43,6 +44,7 @@
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;

Expand Down Expand Up @@ -84,6 +86,8 @@ public void configure(Binder binder)

DiscoveryModule.register(binder, Self.class);
MetricsModule.register(binder, CacheMonitor.class);

LifecycleModule.register(binder, Server.class);
}
}
);
Expand Down
3 changes: 3 additions & 0 deletions services/src/main/java/io/druid/cli/CliCoordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
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;

Expand Down Expand Up @@ -110,6 +111,8 @@ public void configure(Binder binder)
Jerseys.addResource(binder, BackwardsCompatiableInfoResource.class);
Jerseys.addResource(binder, InfoResource.class);
Jerseys.addResource(binder, MasterResource.class);

LifecycleModule.register(binder, Server.class);
}

@Provides
Expand Down
5 changes: 4 additions & 1 deletion services/src/main/java/io/druid/cli/CliHistorical.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;

Expand Down Expand Up @@ -65,10 +66,12 @@ public void configure(Binder binder)
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);
}
}
);
Expand Down
3 changes: 3 additions & 0 deletions services/src/main/java/io/druid/cli/CliMiddleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;

Expand Down Expand Up @@ -81,6 +82,8 @@ public void configure(Binder binder)
LifecycleModule.register(binder, WorkerTaskMonitor.class);
binder.bind(JettyServerInitializer.class).toInstance(new MiddleManagerJettyServerInitializer());
Jerseys.addResource(binder, WorkerResource.class);

LifecycleModule.register(binder, Server.class);
}

@Provides
Expand Down
3 changes: 3 additions & 0 deletions services/src/main/java/io/druid/cli/CliOverlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -138,6 +139,8 @@ public void configure(Binder binder)

binder.bind(JettyServerInitializer.class).toInstance(new OverlordJettyServerInitializer());
Jerseys.addResource(binder, IndexerCoordinatorResource.class);

LifecycleModule.register(binder, Server.class);
}

private void configureTaskStorage(Binder binder)
Expand Down
3 changes: 3 additions & 0 deletions services/src/main/java/io/druid/guice/RealtimeModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand All @@ -54,6 +55,8 @@ public void configure(Binder binder)
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
Expand Down

0 comments on commit cc632cd

Please sign in to comment.