diff --git a/rss-core/src/main/java/com/netflix/recipes/rss/netty/NettyServer.java b/rss-core/src/main/java/com/netflix/recipes/rss/netty/NettyServer.java index 43f4afd..26de4a0 100755 --- a/rss-core/src/main/java/com/netflix/recipes/rss/netty/NettyServer.java +++ b/rss-core/src/main/java/com/netflix/recipes/rss/netty/NettyServer.java @@ -17,7 +17,8 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Maps; -import com.netflix.recipes.rss.util.DescriptiveThreadFactory; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.*; import org.jboss.netty.channel.group.ChannelGroup; @@ -143,12 +144,14 @@ public NettyServer build() { ThreadPoolExecutor bossPool = new ThreadPoolExecutor( numBossThreads, numBossThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), - new DescriptiveThreadFactory("Boss-Thread")); + new ThreadFactoryBuilder().setNameFormat("Boss-Thread-%d") + .setDaemon(false).setPriority(Thread.NORM_PRIORITY).build()); ThreadPoolExecutor workerPool = new ThreadPoolExecutor( numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), - new DescriptiveThreadFactory("Worker-Thread")); + new ThreadFactoryBuilder().setNameFormat("Worker-Thread-%d") + .setDaemon(false).setPriority(Thread.NORM_PRIORITY).build()); ChannelFactory nioServer = new NioServerSocketChannelFactory( bossPool, workerPool, numWorkerThreads); @@ -191,7 +194,8 @@ public PipelineFactory(Map handlers, ThreadPoolExecutor executorThreadPool = new ThreadPoolExecutor( NettyServer.cpus, NettyServer.cpus * 4, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), - new DescriptiveThreadFactory("Executor-Thread")); + new ThreadFactoryBuilder().setNameFormat("Executor-Thread-%d") + .setDaemon(false).setPriority(Thread.NORM_PRIORITY).build()); this.executionHandler = new ExecutionHandler(executorThreadPool); } else { diff --git a/rss-core/src/main/java/com/netflix/recipes/rss/server/BaseJettyServer.java b/rss-core/src/main/java/com/netflix/recipes/rss/server/BaseJettyServer.java index ff2a7bd..8fa5e57 100755 --- a/rss-core/src/main/java/com/netflix/recipes/rss/server/BaseJettyServer.java +++ b/rss-core/src/main/java/com/netflix/recipes/rss/server/BaseJettyServer.java @@ -29,7 +29,6 @@ import com.netflix.config.DynamicPropertyFactory; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; import com.netflix.karyon.server.KaryonServer; -import com.netflix.recipes.rss.RSSConstants; /** * Base Jetty Server @@ -48,8 +47,19 @@ public class BaseJettyServer implements Closeable { protected final Injector injector; - public BaseJettyServer() { - System.setProperty(DynamicPropertyFactory.ENABLE_JMX, "true"); + private final String portPropertyName; + + private String webAppsDir; + + private String hystrixStreamPath; + + public BaseJettyServer(String portPropertyName, String webAppsDir, String hystrixStreamPath) { + + System.setProperty(DynamicPropertyFactory.ENABLE_JMX, "true"); + + this.portPropertyName = portPropertyName; + this.webAppsDir = webAppsDir; + this.hystrixStreamPath = hystrixStreamPath; this.karyonServer = new KaryonServer(); this.injector = karyonServer.initialize(); @@ -58,15 +68,15 @@ public BaseJettyServer() { public void start() { - final int port = ConfigurationManager.getConfigInstance().getInt(RSSConstants.JETTY_HTTP_PORT, Integer.MIN_VALUE); + final int port = ConfigurationManager.getConfigInstance().getInt(portPropertyName, Integer.MIN_VALUE); final Context context = new Context(jettyServer, "/", Context.SESSIONS); - context.setResourceBase(RSSConstants.WEBAPPS_DIR); + context.setResourceBase(webAppsDir); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.addServlet(JspServlet.class, "*.jsp"); // Enable hystrix.stream - context.addServlet(HystrixMetricsStreamServlet.class, RSSConstants.HYSTRIX_STREAM_PATH); + context.addServlet(HystrixMetricsStreamServlet.class, hystrixStreamPath); final Server server = new Server(port); server.setHandler(context); diff --git a/rss-core/src/main/java/com/netflix/recipes/rss/util/DescriptiveThreadFactory.java b/rss-core/src/main/java/com/netflix/recipes/rss/util/DescriptiveThreadFactory.java deleted file mode 100755 index 2bad022..0000000 --- a/rss-core/src/main/java/com/netflix/recipes/rss/util/DescriptiveThreadFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.netflix.recipes.rss.util; - -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Adds descriptive thread names for debugging purposes. Allows priority and daemon to be set, as well. - * - * @author Chris Fregly (chris@fregly.com) - */ -public class DescriptiveThreadFactory implements ThreadFactory { - private final String description; - private final int priority; - private final boolean daemon; - private final AtomicInteger n = new AtomicInteger(1); - - public DescriptiveThreadFactory(String description) { - this(description, Thread.NORM_PRIORITY, false); - } - - public DescriptiveThreadFactory(String description, int priority, - boolean daemon) { - this.description = description; - this.priority = priority; - this.daemon = daemon; - } - - public Thread newThread(Runnable runnable) { - String threadDescription = description + "-" + n.getAndIncrement(); - Thread thread = new Thread(runnable, threadDescription); - thread.setPriority(priority); - thread.setDaemon(daemon); - return thread; - } -} diff --git a/rss-edge/src/main/java/com/netflix/recipes/rss/server/EdgeServer.java b/rss-edge/src/main/java/com/netflix/recipes/rss/server/EdgeServer.java index 8471b51..0d4f4b3 100755 --- a/rss-edge/src/main/java/com/netflix/recipes/rss/server/EdgeServer.java +++ b/rss-edge/src/main/java/com/netflix/recipes/rss/server/EdgeServer.java @@ -20,6 +20,7 @@ import com.netflix.config.ConfigurationManager; import com.netflix.karyon.spi.PropertyNames; +import com.netflix.recipes.rss.RSSConstants; /** * Edge Server @@ -31,8 +32,10 @@ public class EdgeServer extends BaseJettyServer { .getLogger(EdgeServer.class); public EdgeServer() { + super(RSSConstants.JETTY_HTTP_PORT, RSSConstants.WEBAPPS_DIR, + RSSConstants.HYSTRIX_STREAM_PATH); } - + public static void main(final String[] args) throws Exception { System.setProperty("archaius.deployment.applicationId", "edge"); System.setProperty(PropertyNames.SERVER_BOOTSTRAP_BASE_PACKAGES_OVERRIDE, "com.netflix");