Skip to content

Commit

Permalink
Update PlatformSpecific to only detect App Engine Standard Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Cade Fassett committed Sep 20, 2016
1 parent a0e233a commit 023cd42
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public HystrixMetricsPoller(MetricsAsJsonPollerListener listener, int delay) {
this.listener = listener;

ThreadFactory threadFactory = null;
if (!PlatformSpecific.isAppEngine()) {
if (!PlatformSpecific.isAppEngineStandardEnvironment()) {
threadFactory = new MetricsPollerThreadFactory();
} else {
threadFactory = PlatformSpecific.getAppEngineThreadFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public abstract class HystrixConcurrencyStrategy {
*/
public ThreadPoolExecutor getThreadPool(final HystrixThreadPoolKey threadPoolKey, HystrixProperty<Integer> corePoolSize, HystrixProperty<Integer> maximumPoolSize, HystrixProperty<Integer> keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
ThreadFactory threadFactory = null;
if (!PlatformSpecific.isAppEngine()) {
if (!PlatformSpecific.isAppEngineStandardEnvironment()) {
threadFactory = new ThreadFactory() {
protected final AtomicInteger threadNumber = new AtomicInteger(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void initialize() {
int coreSize = propertiesStrategy.getTimerThreadPoolProperties().getCorePoolSize().get();

ThreadFactory threadFactory = null;
if (!PlatformSpecific.isAppEngine()) {
if (!PlatformSpecific.isAppEngineStandardEnvironment()) {
threadFactory = new ThreadFactory() {
final AtomicInteger counter = new AtomicInteger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@
import java.util.concurrent.ThreadFactory;

public class PlatformSpecific {
private final boolean isAppEngine;
private final boolean isAppEngineStandardEnvironment;

private static PlatformSpecific INSTANCE = new PlatformSpecific();

private PlatformSpecific() {
isAppEngine = determineAppEngineReflectively();
isAppEngineStandardEnvironment = determineAppEngineReflectively();
}

public static boolean isAppEngine() {
return INSTANCE.isAppEngine;
public static boolean isAppEngineStandardEnvironment() {
return INSTANCE.isAppEngineStandardEnvironment;
}

/*
* This detection mechanism is from Guava - specifically
* http://docs.guava-libraries.googlecode.com/git/javadoc/src-html/com/google/common/util/concurrent/MoreExecutors.html#line.766
* Added GAE_LONG_APP_ID check to detect only AppEngine Standard Environment
*/
private static boolean determineAppEngineReflectively() {
if (System.getProperty("com.google.appengine.runtime.environment") == null) {
return false;
}
// GAE_LONG_APP_ID is only set in the GAE Flexible Environment, where we want standard threading
if (System.getenv("GAE_LONG_APP_ID") != null) {
return false;
}
try {
// If the current environment is null, we're not inside AppEngine.
return Class.forName("com.google.apphosting.api.ApiProxy")
Expand Down

0 comments on commit 023cd42

Please sign in to comment.