diff --git a/build.gradle b/build.gradle index a1e4ef9c2..c4595f4d5 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,9 @@ subprojects { apply plugin: 'nebula.netflixoss' apply plugin: 'java' apply plugin: 'nebula.provided-base' + + sourceCompatibility = 1.7 + targetCompatibility = 1.7 repositories { jcenter() diff --git a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/CacheInvocationContextFactory.java b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/CacheInvocationContextFactory.java index e0c6c4737..1c6e152eb 100644 --- a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/CacheInvocationContextFactory.java +++ b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/CacheInvocationContextFactory.java @@ -44,7 +44,7 @@ public static CacheInvocationContext createCacheResultInvocationCon Method method = metaHolder.getMethod(); CacheResult cacheResult = method.getAnnotation(CacheResult.class); MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheResult.cacheKeyMethod(), metaHolder); - return new CacheInvocationContext(cacheResult, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs()); + return new CacheInvocationContext<>(cacheResult, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs()); } return null; } @@ -60,7 +60,7 @@ public static CacheInvocationContext createCacheRemoveInvocationCon Method method = metaHolder.getMethod(); CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class); MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheRemove.cacheKeyMethod(), metaHolder); - return new CacheInvocationContext(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs()); + return new CacheInvocationContext<>(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs()); } return null; } diff --git a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/HystrixCacheKeyGenerator.java b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/HystrixCacheKeyGenerator.java index 2a7f492d8..1fce06678 100644 --- a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/HystrixCacheKeyGenerator.java +++ b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/HystrixCacheKeyGenerator.java @@ -87,11 +87,7 @@ private Object getPropertyValue(String name, Object obj) throws HystrixCacheKeyG try { return new PropertyDescriptor(name, obj.getClass()) .getReadMethod().invoke(obj); - } catch (IllegalAccessException e) { - throw new HystrixCacheKeyGenerationException(e); - } catch (InvocationTargetException e) { - throw new HystrixCacheKeyGenerationException(e); - } catch (IntrospectionException e) { + } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) { throw new HystrixCacheKeyGenerationException(e); } } diff --git a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/command/MethodExecutionAction.java b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/command/MethodExecutionAction.java index 448c9c406..7fb707bb4 100644 --- a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/command/MethodExecutionAction.java +++ b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/command/MethodExecutionAction.java @@ -99,9 +99,7 @@ private Object execute(Object o, Method m, Object... args) throws CommandActionE try { m.setAccessible(true); // suppress Java language access result = m.invoke(o, args); - } catch (IllegalAccessException e) { - propagateCause(e); - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException e) { propagateCause(e); } return result; diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/cache/CacheTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/cache/CacheTest.java index 41aa0add3..baf0948bd 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/cache/CacheTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/cache/CacheTest.java @@ -257,7 +257,7 @@ public void testGetUserByName_givenNonexistentCacheKeyMethod_shouldThrowExceptio } public static class UserService { - private Map storage = new ConcurrentHashMap(); + private Map storage = new ConcurrentHashMap<>(); @PostConstruct private void init() { diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/error/ErrorPropagationTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/error/ErrorPropagationTest.java index 2445d4425..0973e8ef5 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/error/ErrorPropagationTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/error/ErrorPropagationTest.java @@ -38,7 +38,7 @@ public class ErrorPropagationTest { private static final Map USERS; static { - USERS = new HashMap(); + USERS = new HashMap<>(); USERS.put("1", new User("1", "user_1")); USERS.put("2", new User("2", "user_2")); USERS.put("3", new User("3", "user_3")); diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java index 267659256..463a9d436 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java @@ -203,7 +203,7 @@ private static class MetricJsonListener implements HystrixMetricsPoller.MetricsA *

* This is a safety check against a runaway poller causing memory leaks. */ - private final LinkedBlockingQueue jsonMetrics = new LinkedBlockingQueue(1000); + private final LinkedBlockingQueue jsonMetrics = new LinkedBlockingQueue<>(1000); /** * Store JSON messages in a queue. @@ -219,7 +219,7 @@ public void handleJsonMetric(String json) { * @return */ public List getJsonMetrics() { - ArrayList metrics = new ArrayList(); + ArrayList metrics = new ArrayList<>(); jsonMetrics.drainTo(metrics); return metrics; } diff --git a/hystrix-contrib/hystrix-rx-netty-metrics-stream/src/test/java/com/netflix/hystrix/contrib/rxnetty/metricsstream/HystrixMetricsStreamHandlerTest.java b/hystrix-contrib/hystrix-rx-netty-metrics-stream/src/test/java/com/netflix/hystrix/contrib/rxnetty/metricsstream/HystrixMetricsStreamHandlerTest.java index a607e20c6..d3d1e975e 100644 --- a/hystrix-contrib/hystrix-rx-netty-metrics-stream/src/test/java/com/netflix/hystrix/contrib/rxnetty/metricsstream/HystrixMetricsStreamHandlerTest.java +++ b/hystrix-contrib/hystrix-rx-netty-metrics-stream/src/test/java/com/netflix/hystrix/contrib/rxnetty/metricsstream/HystrixMetricsStreamHandlerTest.java @@ -100,7 +100,7 @@ private HttpServer createServer() { for (int i = 0; i < 3 && server == null; i++) { port = 10000 + random.nextInt(50000); try { - return RxNetty.newHttpServerBuilder(port, new HystrixMetricsStreamHandler( + return RxNetty.newHttpServerBuilder(port, new HystrixMetricsStreamHandler<>( DEFAULT_HYSTRIX_PREFIX, DEFAULT_INTERVAL, new RequestHandler() { // Application handler diff --git a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCollapser.java b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCollapser.java index 72428c448..f3e043695 100644 --- a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCollapser.java +++ b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCollapser.java @@ -111,7 +111,7 @@ protected Tag getServoInstanceTag() { */ private List> getServoMonitors() { - List> monitors = new ArrayList>(); + List> monitors = new ArrayList<>(); monitors.add(new InformationalMetric(MonitorConfig.builder("name").build()) { @Override diff --git a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCommand.java b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCommand.java index f2dc1938f..71ad73c95 100644 --- a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCommand.java +++ b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherCommand.java @@ -116,7 +116,7 @@ protected Tag getServoInstanceTag() { */ private List> getServoMonitors() { - List> monitors = new ArrayList>(); + List> monitors = new ArrayList<>(); monitors.add(new InformationalMetric(MonitorConfig.builder("isCircuitBreakerOpen").build()) { @Override diff --git a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java index 1843eeb22..ba5199af1 100644 --- a/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java +++ b/hystrix-contrib/hystrix-servo-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherThreadPool.java @@ -111,7 +111,7 @@ protected Tag getServoInstanceTag() { */ private List> getServoMonitors() { - List> monitors = new ArrayList>(); + List> monitors = new ArrayList<>(); monitors.add(new InformationalMetric(MonitorConfig.builder("name").build()) { @Override diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index b9c221241..f122eabae 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -87,16 +87,16 @@ protected static enum TimedOutStatus { /* FALLBACK Semaphore */ protected final TryableSemaphore fallbackSemaphoreOverride; /* each circuit has a semaphore to restrict concurrent fallback execution */ - protected static final ConcurrentHashMap fallbackSemaphorePerCircuit = new ConcurrentHashMap(); + protected static final ConcurrentHashMap fallbackSemaphorePerCircuit = new ConcurrentHashMap<>(); /* END FALLBACK Semaphore */ /* EXECUTION Semaphore */ protected final TryableSemaphore executionSemaphoreOverride; /* each circuit has a semaphore to restrict concurrent fallback execution */ - protected static final ConcurrentHashMap executionSemaphorePerCircuit = new ConcurrentHashMap(); + protected static final ConcurrentHashMap executionSemaphorePerCircuit = new ConcurrentHashMap<>(); /* END EXECUTION Semaphore */ - protected final AtomicReference> timeoutTimer = new AtomicReference>(); + protected final AtomicReference> timeoutTimer = new AtomicReference<>(); protected AtomicBoolean started = new AtomicBoolean(); protected volatile long invocationStartTime = -1; @@ -105,10 +105,10 @@ protected static enum TimedOutStatus { protected volatile ExecutionResult executionResult = ExecutionResult.EMPTY; /* If this command executed and timed-out */ - protected final AtomicReference isCommandTimedOut = new AtomicReference(TimedOutStatus.NOT_EXECUTED); + protected final AtomicReference isCommandTimedOut = new AtomicReference<>(TimedOutStatus.NOT_EXECUTED); protected final AtomicBoolean isExecutionComplete = new AtomicBoolean(false); protected final AtomicBoolean isExecutedInThread = new AtomicBoolean(false); - protected final AtomicReference endCurrentThreadExecutingCommand = new AtomicReference(); // don't like how this is being done + protected final AtomicReference endCurrentThreadExecutingCommand = new AtomicReference<>(); // don't like how this is being done /** @@ -119,7 +119,7 @@ protected static enum TimedOutStatus { // this is a micro-optimization but saves about 1-2microseconds (on 2011 MacBook Pro) // on the repetitive string processing that will occur on the same classes over and over again - private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap, String>(); + private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap<>(); /* package */static String getDefaultNameFromClass(Class cls) { String fromCache = defaultNameCache.get(cls); @@ -358,7 +358,7 @@ protected ObservableCommand toObservable(final boolean performAsyncTimeout) { if (fromCache != null) { /* mark that we received this response from cache */ metrics.markResponseFromCache(); - return new CachedObservableResponse((CachedObservableOriginal) fromCache, this); + return new CachedObservableResponse<>((CachedObservableOriginal) fromCache, this); } } @@ -478,17 +478,17 @@ public void call() { // put in cache if (isRequestCachingEnabled()) { // wrap it for caching - o = new CachedObservableOriginal(o.cache(), this); + o = new CachedObservableOriginal<>(o.cache(), this); Observable fromCache = requestCache.putIfAbsent(getCacheKey(), o); if (fromCache != null) { // another thread beat us so we'll use the cached value instead - o = new CachedObservableResponse((CachedObservableOriginal) fromCache, this); + o = new CachedObservableResponse<>((CachedObservableOriginal) fromCache, this); } // we just created an ObservableCommand so we cast and return it return (ObservableCommand) o; } else { // no request caching so a simple wrapper just to pass 'this' along with the Observable - return new ObservableCommand(o, this); + return new ObservableCommand<>(o, this); } } @@ -556,7 +556,7 @@ public void call(Notification n) { setRequestContextIfNeeded(currentRequestContext); } - }).lift(new HystrixObservableTimeoutOperator(_self, performAsyncTimeout)).map(new Func1() { + }).lift(new HystrixObservableTimeoutOperator<>(_self, performAsyncTimeout)).map(new Func1() { boolean once = false; @@ -967,7 +967,7 @@ public int getIntervalTimeInMilliseconds() { * This allows the blocking and non-blocking approaches to be coded basically the same way * though it is admittedly awkward if we were just blocking (the use of Reference annoys me for example) */ - _tl = new SoftReference(listener); + _tl = new SoftReference<>(listener); } final Reference tl = _tl; @@ -1463,7 +1463,7 @@ private ExecutionResult(List events, int executionTime, Except * @return */ public ExecutionResult addEvents(HystrixEventType... events) { - ArrayList newEvents = new ArrayList(); + ArrayList newEvents = new ArrayList<>(); newEvents.addAll(this.events); for (HystrixEventType e : events) { newEvents.add(e); diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java index 3f84385e2..645d20439 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java @@ -67,7 +67,7 @@ private static void _reset() { private static ThreadLocal> currentCommand = new ThreadLocal>() { @Override protected LinkedList initialValue() { - return new LinkedList(); + return new LinkedList<>(); } }; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCircuitBreaker.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCircuitBreaker.java index f31e8fe4a..6aaa2e794 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCircuitBreaker.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCircuitBreaker.java @@ -55,7 +55,7 @@ public interface HystrixCircuitBreaker { */ public static class Factory { // String is HystrixCommandKey.name() (we can't use HystrixCommandKey directly as we can't guarantee it implements hashcode/equals correctly) - private static ConcurrentHashMap circuitBreakersByCommand = new ConcurrentHashMap(); + private static ConcurrentHashMap circuitBreakersByCommand = new ConcurrentHashMap<>(); /** * Get the {@link HystrixCircuitBreaker} instance for a given {@link HystrixCommandKey}. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java index c281a62ae..98f065128 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java @@ -126,7 +126,7 @@ protected HystrixCollapser(Setter setter) { } HystrixCollapserProperties properties = HystrixPropertiesFactory.getCollapserProperties(collapserKey, propertiesBuilder); - this.collapserFactory = new RequestCollapserFactory(collapserKey, scope, timer, properties); + this.collapserFactory = new RequestCollapserFactory<>(collapserKey, scope, timer, properties); this.requestCache = HystrixRequestCache.getInstance(collapserKey, HystrixPlugins.getInstance().getConcurrencyStrategy()); if (metrics == null) { @@ -593,6 +593,6 @@ public Setter andCollapserPropertiesDefaults(HystrixCollapserProperties.Setter p // this is a micro-optimization but saves about 1-2microseconds (on 2011 MacBook Pro) // on the repetitive string processing that will occur on the same classes over and over again @SuppressWarnings("rawtypes") - private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap, String>(); + private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap<>(); } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserKey.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserKey.java index 3b7aa12ff..1963425af 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserKey.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserKey.java @@ -37,7 +37,7 @@ private Factory() { } // used to intern instances so we don't keep re-creating them millions of times for the same key - private static ConcurrentHashMap intern = new ConcurrentHashMap(); + private static ConcurrentHashMap intern = new ConcurrentHashMap<>(); /** * Retrieve (or create) an interned HystrixCollapserKey instance for a given name. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserMetrics.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserMetrics.java index 3ded36764..4d3721d21 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserMetrics.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserMetrics.java @@ -36,7 +36,7 @@ public class HystrixCollapserMetrics extends HystrixMetrics { private static final Logger logger = LoggerFactory.getLogger(HystrixCollapserMetrics.class); // String is HystrixCollapserKey.name() (we can't use HystrixCollapserKey directly as we can't guarantee it implements hashcode/equals correctly) - private static final ConcurrentHashMap metrics = new ConcurrentHashMap(); + private static final ConcurrentHashMap metrics = new ConcurrentHashMap<>(); /** * Get or create the {@link HystrixCollapserMetrics} instance for a given {@link HystrixCollapserKey}. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandGroupKey.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandGroupKey.java index d81c37dd2..06d91439b 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandGroupKey.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandGroupKey.java @@ -39,7 +39,7 @@ private Factory() { } // used to intern instances so we don't keep re-creating them millions of times for the same key - private static ConcurrentHashMap intern = new ConcurrentHashMap(); + private static ConcurrentHashMap intern = new ConcurrentHashMap<>(); /** * Retrieve (or create) an interned HystrixCommandGroup instance for a given name. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandKey.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandKey.java index 2e27366c9..22d769f82 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandKey.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandKey.java @@ -37,7 +37,7 @@ private Factory() { } // used to intern instances so we don't keep re-creating them millions of times for the same key - private static ConcurrentHashMap intern = new ConcurrentHashMap(); + private static ConcurrentHashMap intern = new ConcurrentHashMap<>(); /** * Retrieve (or create) an interned HystrixCommandKey instance for a given name. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandMetrics.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandMetrics.java index 87e1bc852..caddc270d 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandMetrics.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandMetrics.java @@ -41,7 +41,7 @@ public class HystrixCommandMetrics extends HystrixMetrics { private static final Logger logger = LoggerFactory.getLogger(HystrixCommandMetrics.class); // String is HystrixCommandKey.name() (we can't use HystrixCommandKey directly as we can't guarantee it implements hashcode/equals correctly) - private static final ConcurrentHashMap metrics = new ConcurrentHashMap(); + private static final ConcurrentHashMap metrics = new ConcurrentHashMap<>(); /** * Get or create the {@link HystrixCommandMetrics} instance for a given {@link HystrixCommandKey}. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java index dbaedb9ab..77f992988 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java @@ -121,7 +121,7 @@ protected HystrixObservableCollapser(Setter setter) { collapserKey = HystrixCollapserKey.Factory.asKey(defaultKeyName); } - this.collapserFactory = new RequestCollapserFactory(collapserKey, scope, timer, propertiesBuilder); + this.collapserFactory = new RequestCollapserFactory<>(collapserKey, scope, timer, propertiesBuilder); this.requestCache = HystrixRequestCache.getInstance(collapserKey, HystrixPlugins.getInstance().getConcurrencyStrategy()); final HystrixObservableCollapser self = this; @@ -153,7 +153,7 @@ public Observable mapResponseToRequests(Observable batchR final Func1 mapBatchTypeToResponseType = self.getBatchReturnTypeToResponseTypeMapper(); // index the requests by key - final Map> requestsByKey = new HashMap>(requests.size()); + final Map> requestsByKey = new HashMap<>(requests.size()); for (CollapsedRequest cr : requests) { requestsByKey.put(requestKeySelector.call(cr.getArgument()), cr); } @@ -510,6 +510,6 @@ public Setter andCollapserPropertiesDefaults(HystrixCollapserProperties.Setter p // this is a micro-optimization but saves about 1-2microseconds (on 2011 MacBook Pro) // on the repetitive string processing that will occur on the same classes over and over again @SuppressWarnings("rawtypes") - private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap, String>(); + private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap<>(); } \ No newline at end of file diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java index 9e170e185..dd0b13d59 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java @@ -37,7 +37,7 @@ public class HystrixRequestCache { private static final Logger logger = LoggerFactory.getLogger(HystrixRequestCache.class); // the String key must be: HystrixRequestCache.prefix + concurrencyStrategy + cacheKey - private final static ConcurrentHashMap caches = new ConcurrentHashMap(); + private final static ConcurrentHashMap caches = new ConcurrentHashMap<>(); private final RequestCacheKey rcKey; private final HystrixConcurrencyStrategy concurrencyStrategy; @@ -47,11 +47,11 @@ public class HystrixRequestCache { *

* Key => CommandPrefix + CacheKey : Future from queue() */ - private static final HystrixRequestVariableHolder>> requestVariableForCache = new HystrixRequestVariableHolder>>(new HystrixRequestVariableLifecycle>>() { + private static final HystrixRequestVariableHolder>> requestVariableForCache = new HystrixRequestVariableHolder<>(new HystrixRequestVariableLifecycle>>() { @Override public ConcurrentHashMap> initialValue() { - return new ConcurrentHashMap>(); + return new ConcurrentHashMap<>(); } @Override diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java index 6722c285f..6b77b33a9 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestLog.java @@ -50,7 +50,7 @@ public class HystrixRequestLog { */ /* package */static final int MAX_STORAGE = 1000; - private static final HystrixRequestVariableHolder currentRequestLog = new HystrixRequestVariableHolder(new HystrixRequestVariableLifecycle() { + private static final HystrixRequestVariableHolder currentRequestLog = new HystrixRequestVariableHolder<>(new HystrixRequestVariableLifecycle() { @Override public HystrixRequestLog initialValue() { return new HystrixRequestLog(); @@ -65,12 +65,12 @@ public void shutdown(HystrixRequestLog value) { /** * History of {@link HystrixCommand} executed in this request. */ - private LinkedBlockingQueue> executedCommands = new LinkedBlockingQueue>(MAX_STORAGE); + private LinkedBlockingQueue> executedCommands = new LinkedBlockingQueue<>(MAX_STORAGE); /** * History of {@link HystrixInvokableInfo} executed in this request. */ - private LinkedBlockingQueue> allExecutedCommands = new LinkedBlockingQueue>(MAX_STORAGE); + private LinkedBlockingQueue> allExecutedCommands = new LinkedBlockingQueue<>(MAX_STORAGE); // prevent public instantiation private HystrixRequestLog() { @@ -164,8 +164,8 @@ public Collection> getAllExecutedCommands() { */ public String getExecutedCommandsAsString() { try { - LinkedHashMap aggregatedCommandsExecuted = new LinkedHashMap(); - Map aggregatedCommandExecutionTime = new HashMap(); + LinkedHashMap aggregatedCommandsExecuted = new LinkedHashMap<>(); + Map aggregatedCommandExecutionTime = new HashMap<>(); StringBuilder builder = new StringBuilder(); int estimatedLength = 0; @@ -173,7 +173,7 @@ public String getExecutedCommandsAsString() { builder.setLength(0); builder.append(command.getCommandKey().name()); - List events = new ArrayList(command.getExecutionEvents()); + List events = new ArrayList<>(command.getExecutionEvents()); if (events.size() > 0) { Collections.sort(events); //replicate functionality of Arrays.toString(events.toArray()) to append directly to existing StringBuilder diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java index 119003e08..fbef25cd0 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java @@ -80,7 +80,7 @@ public interface HystrixThreadPool { * Use the String from HystrixThreadPoolKey.name() instead of the HystrixThreadPoolKey instance as it's just an interface and we can't ensure the object * we receive implements hashcode/equals correctly and do not want the default hashcode/equals which would create a new threadpool for every object we get even if the name is the same */ - /* package */final static ConcurrentHashMap threadPools = new ConcurrentHashMap(); + /* package */final static ConcurrentHashMap threadPools = new ConcurrentHashMap<>(); /** * Get the {@link HystrixThreadPool} instance for a given {@link HystrixThreadPoolKey}. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolKey.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolKey.java index 23ca6128a..1b56351c8 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolKey.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolKey.java @@ -39,7 +39,7 @@ private Factory() { } // used to intern instances so we don't keep re-creating them millions of times for the same key - private static ConcurrentHashMap intern = new ConcurrentHashMap(); + private static ConcurrentHashMap intern = new ConcurrentHashMap<>(); /** * Retrieve (or create) an interned HystrixThreadPoolKey instance for a given name. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java index 87fe32fa5..eacc7ea47 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolMetrics.java @@ -36,7 +36,7 @@ public class HystrixThreadPoolMetrics extends HystrixMetrics { private static final Logger logger = LoggerFactory.getLogger(HystrixThreadPoolMetrics.class); // String is HystrixThreadPoolKey.name() (we can't use HystrixThreadPoolKey directly as we can't guarantee it implements hashcode/equals correctly) - private static final ConcurrentHashMap metrics = new ConcurrentHashMap(); + private static final ConcurrentHashMap metrics = new ConcurrentHashMap<>(); /** * Get or create the {@link HystrixThreadPoolMetrics} instance for a given {@link HystrixThreadPoolKey}. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunction.java b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunction.java index 977167768..30f731e6c 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunction.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunction.java @@ -22,7 +22,7 @@ */ /* package */class CollapsedRequestObservableFunction implements CollapsedRequest, OnSubscribe { private final R argument; - private final AtomicReference> rh = new AtomicReference>(new CollapsedRequestObservableFunction.ResponseHolder()); + private final AtomicReference> rh = new AtomicReference<>(new CollapsedRequestObservableFunction.ResponseHolder()); private final BooleanSubscription subscription = new BooleanSubscription(); public CollapsedRequestObservableFunction(R arg) { @@ -209,15 +209,15 @@ private ResponseHolder(AtomicReference response, Exception exception, Observe } public ResponseHolder setResponse(T response) { - return new ResponseHolder(new AtomicReference(response), e, o); + return new ResponseHolder<>(new AtomicReference<>(response), e, o); } public ResponseHolder setObserver(Observer observer) { - return new ResponseHolder(r, e, observer); + return new ResponseHolder<>(r, e, observer); } public ResponseHolder setException(Exception exception) { - return new ResponseHolder(r, exception, o); + return new ResponseHolder<>(r, exception, o); } public Observer getObserver() { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java index fbbdf0b9f..04fdc0dc7 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestBatch.java @@ -29,7 +29,7 @@ public class RequestBatch { private static final Logger logger = LoggerFactory.getLogger(HystrixCollapser.class); private final HystrixCollapserBridge commandCollapser; - final ConcurrentLinkedQueue> requests = new ConcurrentLinkedQueue>(); + final ConcurrentLinkedQueue> requests = new ConcurrentLinkedQueue<>(); // use AtomicInteger to count so we can use ConcurrentLinkedQueue instead of LinkedBlockingQueue private final AtomicInteger count = new AtomicInteger(0); private final int maxBatchSize; @@ -65,7 +65,7 @@ public Observable offer(RequestArgumentType arg) { if (s > maxBatchSize) { return null; } else { - CollapsedRequestObservableFunction f = new CollapsedRequestObservableFunction(arg); + CollapsedRequestObservableFunction f = new CollapsedRequestObservableFunction<>(arg); requests.add(f); return Observable.create(f); } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapser.java b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapser.java index 7cac365a5..502f0b9ef 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapser.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapser.java @@ -30,8 +30,8 @@ public class RequestCollapser commandCollapser; // batch can be null once shutdown - private final AtomicReference> batch = new AtomicReference>(); - private final AtomicReference> timerListenerReference = new AtomicReference>(); + private final AtomicReference> batch = new AtomicReference<>(); + private final AtomicReference> timerListenerReference = new AtomicReference<>(); private final AtomicBoolean timerListenerRegistered = new AtomicBoolean(); private final CollapserTimer timer; private final HystrixCollapserProperties properties; @@ -49,7 +49,7 @@ public class RequestCollapser(properties, commandCollapser, properties.maxRequestsInBatch().get())); + batch.set(new RequestBatch<>(properties, commandCollapser, properties.maxRequestsInBatch().get())); } /** @@ -90,7 +90,7 @@ private void createNewBatchAndExecutePreviousIfNeeded(RequestBatch(properties, commandCollapser, properties.maxRequestsInBatch().get()))) { + if (batch.compareAndSet(previousBatch, new RequestBatch<>(properties, commandCollapser, properties.maxRequestsInBatch().get()))) { // this thread won so trigger the previous batch previousBatch.executeBatchIfNotAlreadyStarted(); } @@ -120,7 +120,7 @@ private class CollapsedTask implements TimerListener { CollapsedTask() { // this gets executed from the context of a HystrixCommand parent thread (such as a Tomcat thread) // so we create the callable now where we can capture the thread context - callableWithContextOfParent = new HystrixContextCallable(concurrencyStrategy, new Callable() { + callableWithContextOfParent = new HystrixContextCallable<>(concurrencyStrategy, new Callable() { // the wrapCallable call allows a strategy to capture thread-context if desired @Override diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java index 0772ac8d3..c782146f0 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/collapser/RequestCollapserFactory.java @@ -85,7 +85,7 @@ public RequestCollapser getR * Static global cache of RequestCollapsers for Scope.GLOBAL */ // String is CollapserKey.name() (we can't use CollapserKey directly as we can't guarantee it implements hashcode/equals correctly) - private static ConcurrentHashMap> globalScopedCollapsers = new ConcurrentHashMap>(); + private static ConcurrentHashMap> globalScopedCollapsers = new ConcurrentHashMap<>(); @SuppressWarnings("unchecked") private RequestCollapser getCollapserForGlobalScope(HystrixCollapserBridge commandCollapser) { @@ -94,7 +94,7 @@ private RequestCollapser get return (RequestCollapser) collapser; } // create new collapser using 'this' first instance as the one that will get cached for future executions ('this' is stateless so we can do that) - RequestCollapser newCollapser = new RequestCollapser(commandCollapser, properties, timer, concurrencyStrategy); + RequestCollapser newCollapser = new RequestCollapser<>(commandCollapser, properties, timer, concurrencyStrategy); RequestCollapser existing = globalScopedCollapsers.putIfAbsent(collapserKey.name(), newCollapser); if (existing == null) { // we won @@ -112,7 +112,7 @@ private RequestCollapser get * Static global cache of RequestVariables with RequestCollapsers for Scope.REQUEST */ // String is HystrixCollapserKey.name() (we can't use HystrixCollapserKey directly as we can't guarantee it implements hashcode/equals correctly) - private static ConcurrentHashMap>> requestScopedCollapsers = new ConcurrentHashMap>>(); + private static ConcurrentHashMap>> requestScopedCollapsers = new ConcurrentHashMap<>(); /* we are casting because the Map needs to be but we know it is for this thread */ @SuppressWarnings("unchecked") @@ -193,7 +193,7 @@ private RequestCollapserRequestVariable(final HystrixCollapserBridge initialValue() { // this gets calls once per request per HystrixCollapser instance - return new RequestCollapser(commandCollapser, properties, timer, concurrencyStrategy); + return new RequestCollapser<>(commandCollapser, properties, timer, concurrencyStrategy); } @Override @@ -274,6 +274,6 @@ public Setter andCollapserPropertiesDefaults(HystrixCollapserProperties.Setter p // this is a micro-optimization but saves about 1-2microseconds (on 2011 MacBook Pro) // on the repetitive string processing that will occur on the same classes over and over again @SuppressWarnings("rawtypes") - private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap, String>(); + private static ConcurrentHashMap, String> defaultNameCache = new ConcurrentHashMap<>(); } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/HystrixPlugins.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/HystrixPlugins.java index 57d7f3f1f..29af60688 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/HystrixPlugins.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/HystrixPlugins.java @@ -42,11 +42,11 @@ public class HystrixPlugins { private final static HystrixPlugins INSTANCE = new HystrixPlugins(); - /* package */ final AtomicReference notifier = new AtomicReference(); - /* package */ final AtomicReference concurrencyStrategy = new AtomicReference(); - /* package */ final AtomicReference metricsPublisher = new AtomicReference(); - /* package */ final AtomicReference propertiesFactory = new AtomicReference(); - /* package */ final AtomicReference commandExecutionHook = new AtomicReference(); + /* package */ final AtomicReference notifier = new AtomicReference<>(); + /* package */ final AtomicReference concurrencyStrategy = new AtomicReference<>(); + /* package */ final AtomicReference metricsPublisher = new AtomicReference<>(); + /* package */ final AtomicReference propertiesFactory = new AtomicReference<>(); + /* package */ final AtomicReference commandExecutionHook = new AtomicReference<>(); private HystrixPlugins() { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java index 322c17a52..a7d81a758 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java @@ -101,9 +101,9 @@ public BlockingQueue getBlockingQueue(int maxQueueSize) { * and rejecting is the preferred solution. */ if (maxQueueSize <= 0) { - return new SynchronousQueue(); + return new SynchronousQueue<>(); } else { - return new LinkedBlockingQueue(maxQueueSize); + return new LinkedBlockingQueue<>(maxQueueSize); } } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java index 81672f61d..64aca814f 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java @@ -153,7 +153,7 @@ public Subscription schedule(final Action0 action) { return Subscriptions.empty(); } - final AtomicReference sf = new AtomicReference(); + final AtomicReference sf = new AtomicReference<>(); Subscription s = Subscriptions.from(threadPool.getExecutor().submit(new Runnable() { @Override diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java index e17f8a8a1..2e52e9bed 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestContext.java @@ -72,7 +72,7 @@ public class HystrixRequestContext { * HystrixRequestContext object with the ConcurrentHashMap within it nulled out since once it is nullified * from the parent thread it is shared across all child threads. */ - private static ThreadLocal requestVariables = new ThreadLocal(); + private static ThreadLocal requestVariables = new ThreadLocal<>(); public static boolean isCurrentThreadInitialized() { HystrixRequestContext context = requestVariables.get(); @@ -115,7 +115,7 @@ public static HystrixRequestContext initializeContext() { * * Only HystrixRequestVariable has a reason to be accessing this field. */ - /* package */ConcurrentHashMap, HystrixRequestVariableDefault.LazyInitializer> state = new ConcurrentHashMap, HystrixRequestVariableDefault.LazyInitializer>(); + /* package */ConcurrentHashMap, HystrixRequestVariableDefault.LazyInitializer> state = new ConcurrentHashMap<>(); // instantiation should occur via static factory methods. private HystrixRequestContext() { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableDefault.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableDefault.java index 72f92b1d7..5d9417b2f 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableDefault.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableDefault.java @@ -93,7 +93,7 @@ public T get() { * Whichever instance of LazyInitializer succeeds will then have get() invoked which will call * the initialValue() method once-and-only-once. */ - LazyInitializer l = new LazyInitializer(this); + LazyInitializer l = new LazyInitializer<>(this); LazyInitializer existing = variableMap.putIfAbsent(this, l); if (existing == null) { /* @@ -132,7 +132,7 @@ public T initialValue() { * the value to set */ public void set(T value) { - HystrixRequestContext.getContextForCurrentThread().state.put(this, new LazyInitializer(this, value)); + HystrixRequestContext.getContextForCurrentThread().state.put(this, new LazyInitializer<>(this, value)); } /** diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableHolder.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableHolder.java index 95387ef44..3d7baeabd 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableHolder.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableHolder.java @@ -36,7 +36,7 @@ public class HystrixRequestVariableHolder { static final Logger logger = LoggerFactory.getLogger(HystrixRequestVariableHolder.class); - private static ConcurrentHashMap> requestVariableInstance = new ConcurrentHashMap>(); + private static ConcurrentHashMap> requestVariableInstance = new ConcurrentHashMap<>(); private final HystrixRequestVariableLifecycle lifeCycleMethods; diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java index e46c26926..c332f6976 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactory.java @@ -98,7 +98,7 @@ public static void reset() { /* package */ HystrixMetricsPublisherFactory() {} // String is CommandKey.name() (we can't use CommandKey directly as we can't guarantee it implements hashcode/equals correctly) - private final ConcurrentHashMap commandPublishers = new ConcurrentHashMap(); + private final ConcurrentHashMap commandPublishers = new ConcurrentHashMap<>(); /* package */ HystrixMetricsPublisherCommand getPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) { // attempt to retrieve from cache first @@ -123,7 +123,7 @@ public static void reset() { } // String is ThreadPoolKey.name() (we can't use ThreadPoolKey directly as we can't guarantee it implements hashcode/equals correctly) - private final ConcurrentHashMap threadPoolPublishers = new ConcurrentHashMap(); + private final ConcurrentHashMap threadPoolPublishers = new ConcurrentHashMap<>(); /* package */ HystrixMetricsPublisherThreadPool getPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, HystrixThreadPoolProperties properties) { // attempt to retrieve from cache first @@ -163,7 +163,7 @@ public static HystrixMetricsPublisherCollapser createOrRetrievePublisherForColla } // String is CollapserKey.name() (we can't use CollapserKey directly as we can't guarantee it implements hashcode/equals correctly) - private final ConcurrentHashMap collapserPublishers = new ConcurrentHashMap(); + private final ConcurrentHashMap collapserPublishers = new ConcurrentHashMap<>(); /* package */ HystrixMetricsPublisherCollapser getPublisherForCollapser(HystrixCollapserKey collapserKey, HystrixCollapserMetrics metrics, HystrixCollapserProperties properties) { // attempt to retrieve from cache first diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesChainedArchaiusProperty.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesChainedArchaiusProperty.java index 8981299a5..e289cb767 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesChainedArchaiusProperty.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesChainedArchaiusProperty.java @@ -65,8 +65,8 @@ public static abstract class ChainLink { */ public ChainLink() { next = null; - pReference = new AtomicReference>(this); - callbacks = new ArrayList(); + pReference = new AtomicReference<>(this); + callbacks = new ArrayList<>(); } /** @@ -74,8 +74,8 @@ public ChainLink() { */ public ChainLink(ChainLink nextProperty) { next = nextProperty; - pReference = new AtomicReference>(next); - callbacks = new ArrayList(); + pReference = new AtomicReference<>(next); + callbacks = new ArrayList<>(); } protected void checkAndFlip() { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesFactory.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesFactory.java index 94edfec75..31d4c6b89 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesFactory.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesFactory.java @@ -46,7 +46,7 @@ public static void reset() { } // String is CommandKey.name() (we can't use CommandKey directly as we can't guarantee it implements hashcode/equals correctly) - private static final ConcurrentHashMap commandProperties = new ConcurrentHashMap(); + private static final ConcurrentHashMap commandProperties = new ConcurrentHashMap<>(); /** * Get an instance of {@link HystrixCommandProperties} with the given factory {@link HystrixPropertiesStrategy} implementation for each {@link HystrixCommand} instance. @@ -85,7 +85,7 @@ public static HystrixCommandProperties getCommandProperties(HystrixCommandKey ke } // String is ThreadPoolKey.name() (we can't use ThreadPoolKey directly as we can't guarantee it implements hashcode/equals correctly) - private static final ConcurrentHashMap threadPoolProperties = new ConcurrentHashMap(); + private static final ConcurrentHashMap threadPoolProperties = new ConcurrentHashMap<>(); /** * Get an instance of {@link HystrixThreadPoolProperties} with the given factory {@link HystrixPropertiesStrategy} implementation for each {@link HystrixThreadPool} instance. @@ -124,7 +124,7 @@ public static HystrixThreadPoolProperties getThreadPoolProperties(HystrixThreadP } // String is CollapserKey.name() (we can't use CollapserKey directly as we can't guarantee it implements hashcode/equals correctly) - private static final ConcurrentHashMap collapserProperties = new ConcurrentHashMap(); + private static final ConcurrentHashMap collapserProperties = new ConcurrentHashMap<>(); /** * Get an instance of {@link HystrixCollapserProperties} with the given factory {@link HystrixPropertiesStrategy} implementation for each {@link HystrixCollapserKey} instance. diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixProperty.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixProperty.java index 3ccf82658..5d317f6fe 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixProperty.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixProperty.java @@ -133,6 +133,7 @@ public T get() { * @param values * @return first non-null value or null if none found */ + @SafeVarargs public static HystrixProperty asProperty(final HystrixProperty... values) { return new HystrixProperty() { diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingNumber.java b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingNumber.java index 133afae26..707a5ed1e 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingNumber.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingNumber.java @@ -547,7 +547,7 @@ private Bucket[] getArray() { * but since we never clear the data directly, only increment/decrement head/tail we would never get a NULL * just potentially return stale data which we are okay with doing */ - ArrayList array = new ArrayList(); + ArrayList array = new ArrayList<>(); for (int i = 0; i < size; i++) { array.add(data.get(convert(i))); } @@ -593,8 +593,8 @@ private int convert(int index) { } BucketCircularArray(int size) { - AtomicReferenceArray _buckets = new AtomicReferenceArray(size + 1); // + 1 as extra room for the add/remove; - state = new AtomicReference(new ListState(_buckets, 0, 0)); + AtomicReferenceArray _buckets = new AtomicReferenceArray<>(size + 1); // + 1 as extra room for the add/remove; + state = new AtomicReference<>(new ListState(_buckets, 0, 0)); dataLength = _buckets.length(); numBuckets = size; } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingPercentile.java b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingPercentile.java index f307bdfc0..07abb0cc4 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingPercentile.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixRollingPercentile.java @@ -471,7 +471,7 @@ private Bucket[] getArray() { * but since we never clear the data directly, only increment/decrement head/tail we would never get a NULL * just potentially return stale data which we are okay with doing */ - ArrayList array = new ArrayList(); + ArrayList array = new ArrayList<>(); for (int i = 0; i < size; i++) { array.add(data.get(convert(i))); } @@ -517,8 +517,8 @@ private int convert(int index) { } BucketCircularArray(int size) { - AtomicReferenceArray _buckets = new AtomicReferenceArray(size + 1); // + 1 as extra room for the add/remove; - state = new AtomicReference(new ListState(_buckets, 0, 0)); + AtomicReferenceArray _buckets = new AtomicReferenceArray<>(size + 1); // + 1 as extra room for the add/remove; + state = new AtomicReference<>(new ListState(_buckets, 0, 0)); dataLength = _buckets.length(); numBuckets = size; } diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java index 235be1c74..551729f26 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java @@ -63,7 +63,7 @@ public static void reset() { } } - /* package */ AtomicReference executor = new AtomicReference(); + /* package */ AtomicReference executor = new AtomicReference<>(); /** * Add a {@link TimerListener} that will be executed until it is garbage collected or removed by clearing the returned {@link Reference}. diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java index 4dadc33be..a14f5de59 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCollapserTest.java @@ -378,8 +378,8 @@ public void testRequestVariableLifecycle2() throws Exception { HystrixRequestContext requestContext = HystrixRequestContext.initializeContext(); final TestCollapserTimer timer = new TestCollapserTimer(); - final ConcurrentLinkedQueue> responses = new ConcurrentLinkedQueue>(); - ConcurrentLinkedQueue threads = new ConcurrentLinkedQueue(); + final ConcurrentLinkedQueue> responses = new ConcurrentLinkedQueue<>(); + ConcurrentLinkedQueue threads = new ConcurrentLinkedQueue<>(); // kick off work (simulating a single request with multiple threads) for (int t = 0; t < 5; t++) { @@ -685,7 +685,7 @@ public void testRequestCacheWithException() { // simulate request lifecycle HystrixRequestContext.initializeContext(); - ConcurrentLinkedQueue>> commands = new ConcurrentLinkedQueue>>(); + ConcurrentLinkedQueue>> commands = new ConcurrentLinkedQueue<>(); final TestCollapserTimer timer = new TestCollapserTimer(); // pass in 'null' which will cause an NPE to be thrown @@ -747,7 +747,7 @@ public void testRequestCacheWithTimeout() { // simulate request lifecycle HystrixRequestContext.initializeContext(); - ConcurrentLinkedQueue>> commands = new ConcurrentLinkedQueue>>(); + ConcurrentLinkedQueue>> commands = new ConcurrentLinkedQueue<>(); final TestCollapserTimer timer = new TestCollapserTimer(); // pass in 'null' which will cause an NPE to be thrown @@ -998,8 +998,8 @@ public TestShardedRequestCollapser(TestCollapserTimer timer, String value) { @Override protected Collection>> shardRequests(Collection> requests) { - Collection> typeA = new ArrayList>(); - Collection> typeB = new ArrayList>(); + Collection> typeA = new ArrayList<>(); + Collection> typeB = new ArrayList<>(); for (CollapsedRequest request : requests) { if (request.getArgument().endsWith("a")) { @@ -1009,7 +1009,7 @@ protected Collection>> shardRequests } } - ArrayList>> shards = new ArrayList>>(); + ArrayList>> shards = new ArrayList<>(); shards.add(typeA); shards.add(typeB); return shards; @@ -1091,7 +1091,7 @@ private static class TestCollapserCommand extends TestHystrixCommand run() { System.out.println(">>> TestCollapserCommand run() ... batch size: " + requests.size()); // simulate a batch request - ArrayList response = new ArrayList(); + ArrayList response = new ArrayList<>(); for (CollapsedRequest request : requests) { if (request.getArgument() == null) { throw new NullPointerException("Simulated Error"); @@ -1150,7 +1150,7 @@ protected ShortCircuitedCommand() { protected List run() throws Exception { System.out.println("*** execution (this shouldn't happen)"); // this won't ever get called as we're forcing short-circuiting - ArrayList values = new ArrayList(); + ArrayList values = new ArrayList<>(); values.add("hello"); return values; } @@ -1175,7 +1175,7 @@ protected Void run() throws Exception { /* package */ static class TestCollapserTimer implements CollapserTimer { - private final ConcurrentLinkedQueue tasks = new ConcurrentLinkedQueue(); + private final ConcurrentLinkedQueue tasks = new ConcurrentLinkedQueue<>(); @Override public Reference addListener(final TimerListener collapseTask) { @@ -1311,7 +1311,7 @@ public Integer getRequestArgument() { @Override protected HystrixCommand createCommand(Collection> requests) { - ArrayList args = new ArrayList(); + ArrayList args = new ArrayList<>(); for (CollapsedRequest request : requests) { args.add(request.getArgument()); } @@ -1344,7 +1344,7 @@ public Integer getRequestArgument() { @Override protected HystrixCommand createCommand(Collection> requests) { - ArrayList args = new ArrayList(); + ArrayList args = new ArrayList<>(); for (CollapsedRequest request : requests) { args.add(request.getArgument()); } diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java index 90f2207ea..0aab3b36a 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java @@ -545,8 +545,8 @@ public void testObserveSuccess() { @Test public void testCallbackThreadForThreadIsolation() throws Exception { - final AtomicReference commandThread = new AtomicReference(); - final AtomicReference subscribeThread = new AtomicReference(); + final AtomicReference commandThread = new AtomicReference<>(); + final AtomicReference subscribeThread = new AtomicReference<>(); TestHystrixCommand command = new TestHystrixCommand(TestHystrixCommand.testPropsBuilder()) { @@ -600,8 +600,8 @@ public void onNext(Boolean args) { @Test public void testCallbackThreadForSemaphoreIsolation() throws Exception { - final AtomicReference commandThread = new AtomicReference(); - final AtomicReference subscribeThread = new AtomicReference(); + final AtomicReference commandThread = new AtomicReference<>(); + final AtomicReference subscribeThread = new AtomicReference<>(); TestHystrixCommand command = new TestHystrixCommand(TestHystrixCommand.testPropsBuilder() .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) { @@ -1964,7 +1964,7 @@ public void testExecutionSemaphoreWithExecution() { throw new RuntimeException(e); } - final ArrayBlockingQueue results = new ArrayBlockingQueue(2); + final ArrayBlockingQueue results = new ArrayBlockingQueue<>(2); final AtomicBoolean exceptionReceived = new AtomicBoolean(); @@ -2031,7 +2031,7 @@ public void run() { @Test public void testRejectedExecutionSemaphoreWithFallbackViaExecute() { final TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); - final ArrayBlockingQueue results = new ArrayBlockingQueue(2); + final ArrayBlockingQueue results = new ArrayBlockingQueue<>(2); final AtomicBoolean exceptionReceived = new AtomicBoolean(); @@ -2095,7 +2095,7 @@ public void run() { @Test public void testRejectedExecutionSemaphoreWithFallbackViaObserve() { final TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); - final ArrayBlockingQueue> results = new ArrayBlockingQueue>(2); + final ArrayBlockingQueue> results = new ArrayBlockingQueue<>(2); final AtomicBoolean exceptionReceived = new AtomicBoolean(); @@ -3330,7 +3330,7 @@ public void testCheckedExceptionViaExecute() { public void testCheckedExceptionViaObserve() throws InterruptedException { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); CommandWithCheckedException command = new CommandWithCheckedException(circuitBreaker); - final AtomicReference t = new AtomicReference(); + final AtomicReference t = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); try { command.observe().subscribe(new Observer() { @@ -3440,7 +3440,7 @@ public void testErrorThrownViaQueue() { public void testErrorThrownViaObserve() throws InterruptedException { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); CommandWithErrorThrown command = new CommandWithErrorThrown(circuitBreaker); - final AtomicReference t = new AtomicReference(); + final AtomicReference t = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); try { command.observe().subscribe(new Observer() { @@ -5148,9 +5148,9 @@ protected String getFallback() { */ @Test public void testObservableTimeoutNoFallbackThreadContext() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); - final AtomicReference onErrorThread = new AtomicReference(); + final AtomicReference onErrorThread = new AtomicReference<>(); final AtomicBoolean isRequestContextInitialized = new AtomicBoolean(); TestHystrixCommand command = new TestCommandWithTimeout(50, TestCommandWithTimeout.FALLBACK_NOT_IMPLEMENTED); @@ -5684,7 +5684,7 @@ public SingleThreadedPoolWithQueue(int queueSize) { } public SingleThreadedPoolWithQueue(int queueSize, int rejectionQueueSizeThreshold) { - queue = new LinkedBlockingQueue(queueSize); + queue = new LinkedBlockingQueue<>(queueSize); pool = new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, queue); this.rejectionQueueSizeThreshold = rejectionQueueSizeThreshold; } @@ -5725,7 +5725,7 @@ private static class SingleThreadedPoolWithNoQueue implements HystrixThreadPool final ThreadPoolExecutor pool; public SingleThreadedPoolWithNoQueue() { - queue = new SynchronousQueue(); + queue = new SynchronousQueue<>(); pool = new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, queue); } diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java index cb5689e32..5ea8c08e8 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java @@ -87,7 +87,7 @@ public void cleanup() { */ int count = Runtime.getRuntime().availableProcessors(); final CountDownLatch latch = new CountDownLatch(count); - ArrayList> futures = new ArrayList>(); + ArrayList> futures = new ArrayList<>(); for (int i = 0; i < count; ++i) { futures.add(Observable.create(new OnSubscribe() { @Override @@ -106,9 +106,7 @@ public void call(Subscriber sub) { for (Future future : futures) { try { future.get(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } catch (ExecutionException e) { + } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } } @@ -741,8 +739,8 @@ public void testThreadIsolatedObserveFailureWithTimeoutAndFallback() { @Test public void testObserveOnImmediateSchedulerByDefaultForSemaphoreIsolation() throws Exception { - final AtomicReference commandThread = new AtomicReference(); - final AtomicReference subscribeThread = new AtomicReference(); + final AtomicReference commandThread = new AtomicReference<>(); + final AtomicReference subscribeThread = new AtomicReference<>(); TestHystrixCommand command = new TestHystrixCommand(TestHystrixCommand.testPropsBuilder() .setCommandPropertiesDefaults(HystrixCommandPropertiesTest.getUnitTestPropertiesSetter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) { @@ -1583,7 +1581,7 @@ public void testExecutionSemaphoreWithExecution() { throw new RuntimeException(e); } - final ArrayBlockingQueue results = new ArrayBlockingQueue(2); + final ArrayBlockingQueue results = new ArrayBlockingQueue<>(2); final AtomicBoolean exceptionReceived = new AtomicBoolean(); @@ -1649,7 +1647,7 @@ public void run() { @Test public void testRejectedExecutionSemaphoreWithFallback() { final TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); - final ArrayBlockingQueue results = new ArrayBlockingQueue(2); + final ArrayBlockingQueue results = new ArrayBlockingQueue<>(2); final AtomicBoolean exceptionReceived = new AtomicBoolean(); @@ -2937,7 +2935,7 @@ public void testCheckedExceptionViaExecute() { public void testCheckedExceptionViaObserve() throws InterruptedException { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); CommandWithCheckedException command = new CommandWithCheckedException(circuitBreaker); - final AtomicReference t = new AtomicReference(); + final AtomicReference t = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); try { command.observe().subscribe(new Observer() { @@ -3059,7 +3057,7 @@ public void testErrorThrownViaQueue() { public void testErrorThrownViaObserve() throws InterruptedException { TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); CommandWithErrorThrown command = new CommandWithErrorThrown(circuitBreaker); - final AtomicReference t = new AtomicReference(); + final AtomicReference t = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); try { command.observe().subscribe(new Observer() { @@ -4788,9 +4786,9 @@ protected Observable resumeWithFallback() { */ @Test public void testObservableTimeoutNoFallbackThreadContext() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); - final AtomicReference onErrorThread = new AtomicReference(); + final AtomicReference onErrorThread = new AtomicReference<>(); final AtomicBoolean isRequestContextInitialized = new AtomicBoolean(); TestHystrixCommand command = new TestCommandWithTimeout(50, TestCommandWithTimeout.FALLBACK_NOT_IMPLEMENTED); @@ -4854,9 +4852,9 @@ public void call(Throwable t1) { */ @Test public void testObservableTimeoutFallbackThreadContext() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); - final AtomicReference onErrorThread = new AtomicReference(); + final AtomicReference onErrorThread = new AtomicReference<>(); final AtomicBoolean isRequestContextInitialized = new AtomicBoolean(); TestHystrixCommand command = new TestCommandWithTimeout(50, TestCommandWithTimeout.FALLBACK_SUCCESS); @@ -4910,7 +4908,7 @@ public void call(Boolean t1) { @Test public void testRejectedViaSemaphoreIsolation() { final TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); - final ArrayBlockingQueue results = new ArrayBlockingQueue(2); + final ArrayBlockingQueue results = new ArrayBlockingQueue<>(2); final List executionThreads = Collections.synchronizedList(new ArrayList(2)); final List responseThreads = Collections.synchronizedList(new ArrayList(2)); @@ -4980,7 +4978,7 @@ public Boolean call(Boolean b) { @Test public void testRejectedViaThreadIsolation() throws InterruptedException { final TestCircuitBreaker circuitBreaker = new TestCircuitBreaker(); - final ArrayBlockingQueue results = new ArrayBlockingQueue(10); + final ArrayBlockingQueue results = new ArrayBlockingQueue<>(10); final List executionThreads = Collections.synchronizedList(new ArrayList(20)); final List responseThreads = Collections.synchronizedList(new ArrayList(10)); @@ -5689,11 +5687,11 @@ public void call(Notification n) { private final class RequestContextTestResults { volatile TestHystrixCommand command; - final AtomicReference originThread = new AtomicReference(); + final AtomicReference originThread = new AtomicReference<>(); final AtomicBoolean isContextInitialized = new AtomicBoolean(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); final AtomicBoolean isContextInitializedObserveOn = new AtomicBoolean(); - final AtomicReference observeOnThread = new AtomicReference(); + final AtomicReference observeOnThread = new AtomicReference<>(); } /* *************************************** testSuccessfuleRequestContext *********************************** */ @@ -6677,7 +6675,7 @@ public void testExecutionPartialSuccess() { assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.FAILURE)); assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT)); assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS)); - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); command.toObservable().subscribe(ts); ts.awaitTerminalEvent(); ts.assertReceivedOnNext(Arrays.asList(1, 2, 3)); @@ -6728,7 +6726,7 @@ public void testExecutionPartialSuccessWithFallback() { assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.FAILURE)); assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT)); assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS)); - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); command.toObservable().subscribe(ts); ts.awaitTerminalEvent(); ts.assertReceivedOnNext(Arrays.asList(1, 2, 3, 1, 2, 3, 4)); @@ -6778,7 +6776,7 @@ public void testExecutionPartialSuccessWithMoreIntelligentFallback() { assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.FAILURE)); assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT)); assertEquals(0, command.builder.metrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS)); - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); command.toObservable().subscribe(ts); ts.awaitTerminalEvent(); ts.assertReceivedOnNext(Arrays.asList(1, 2, 3, 4)); @@ -7443,7 +7441,7 @@ public SingleThreadedPoolWithQueue(int queueSize) { } public SingleThreadedPoolWithQueue(int queueSize, int rejectionQueueSizeThreshold) { - queue = new LinkedBlockingQueue(queueSize); + queue = new LinkedBlockingQueue<>(queueSize); pool = new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, queue); this.rejectionQueueSizeThreshold = rejectionQueueSizeThreshold; } @@ -7484,7 +7482,7 @@ private static class SingleThreadedPoolWithNoQueue implements HystrixThreadPool final ThreadPoolExecutor pool; public SingleThreadedPoolWithNoQueue() { - queue = new SynchronousQueue(); + queue = new SynchronousQueue<>(); pool = new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, queue); } diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunctionTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunctionTest.java index a1fffbe98..42aa4bc7d 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunctionTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/collapser/CollapsedRequestObservableFunctionTest.java @@ -14,7 +14,7 @@ public class CollapsedRequestObservableFunctionTest { @Test public void testSetResponseSuccess() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); @@ -26,7 +26,7 @@ public void testSetResponseSuccess() throws InterruptedException, ExecutionExcep @Test public void testSetNullResponseSuccess() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); @@ -38,7 +38,7 @@ public void testSetNullResponseSuccess() throws InterruptedException, ExecutionE @Test public void testSetException() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); @@ -55,7 +55,7 @@ public void testSetException() throws InterruptedException, ExecutionException { @Test public void testSetExceptionAfterResponse() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); @@ -73,7 +73,7 @@ public void testSetExceptionAfterResponse() throws InterruptedException, Executi @Test public void testSetResponseAfterException() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); @@ -96,7 +96,7 @@ public void testSetResponseAfterException() throws InterruptedException, Executi @Test public void testSetResponseDuplicate() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); @@ -114,7 +114,7 @@ public void testSetResponseDuplicate() throws InterruptedException, ExecutionExc @Test(expected = CancellationException.class) public void testSetResponseAfterUnsubscribe() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future f = o.toBlocking().toFuture(); @@ -133,7 +133,7 @@ public void testSetResponseAfterUnsubscribe() throws InterruptedException, Execu @Test(expected = CancellationException.class) public void testSetExceptionAfterUnsubscribe() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future f = o.toBlocking().toFuture(); @@ -152,7 +152,7 @@ public void testSetExceptionAfterUnsubscribe() throws InterruptedException, Exec @Test public void testUnsubscribeAfterSetResponse() throws InterruptedException, ExecutionException { - CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction("hello"); + CollapsedRequestObservableFunction cr = new CollapsedRequestObservableFunction<>("hello"); Observable o = Observable.create(cr); Future v = o.toBlocking().toFuture(); diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java index 5cfd9a185..937a9c0c0 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/HystrixPluginsTest.java @@ -221,7 +221,7 @@ public T call() throws Exception { } } - private static final ThreadLocal testRequestIdThreadLocal = new ThreadLocal(); + private static final ThreadLocal testRequestIdThreadLocal = new ThreadLocal<>(); public static class DummyCommand extends HystrixCommand { diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java index 32d072d40..0ae6b6139 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/strategy/metrics/HystrixMetricsPublisherFactoryTest.java @@ -34,7 +34,7 @@ public void testSingleInitializePerKey() { final TestHystrixMetricsPublisher publisher = new TestHystrixMetricsPublisher(); HystrixPlugins.getInstance().registerMetricsPublisher(publisher); final HystrixMetricsPublisherFactory factory = new HystrixMetricsPublisherFactory(); - ArrayList threads = new ArrayList(); + ArrayList threads = new ArrayList<>(); for (int i = 0; i < 20; i++) { threads.add(new Thread(new Runnable() { diff --git a/hystrix-dashboard/src/main/java/com/netflix/hystrix/dashboard/stream/MockStreamServlet.java b/hystrix-dashboard/src/main/java/com/netflix/hystrix/dashboard/stream/MockStreamServlet.java index 55687d0d5..78d307457 100644 --- a/hystrix-dashboard/src/main/java/com/netflix/hystrix/dashboard/stream/MockStreamServlet.java +++ b/hystrix-dashboard/src/main/java/com/netflix/hystrix/dashboard/stream/MockStreamServlet.java @@ -92,8 +92,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t private String getFileFromPackage(String filename) { try { String file = "/" + this.getClass().getPackage().getName().replace('.', '/') + "/" + filename; - InputStream is = this.getClass().getResourceAsStream(file); - try { + try (InputStream is = this.getClass().getResourceAsStream(file)) { /* this is FAR too much work just to get a string from a file */ BufferedReader in = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); StringWriter s = new StringWriter(); @@ -102,8 +101,6 @@ private String getFileFromPackage(String filename) { s.write(c); } return s.toString(); - } finally { - is.close(); } } catch (Exception e) { throw new RuntimeException("Could not find file: " + filename, e); diff --git a/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandCollapserGetValueForKey.java b/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandCollapserGetValueForKey.java index 778c4acff..b420bcc9e 100644 --- a/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandCollapserGetValueForKey.java +++ b/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandCollapserGetValueForKey.java @@ -74,7 +74,7 @@ private BatchCommand(Collection> requests) { @Override protected List run() { - ArrayList response = new ArrayList(); + ArrayList response = new ArrayList<>(); for (CollapsedRequest request : requests) { // artificial response for each argument received in the batch response.add("ValueForKey: " + request.getArgument()); diff --git a/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandThatFailsSilently.java b/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandThatFailsSilently.java index 37ed285d1..35c35c145 100644 --- a/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandThatFailsSilently.java +++ b/hystrix-examples/src/main/java/com/netflix/hystrix/examples/basic/CommandThatFailsSilently.java @@ -46,7 +46,7 @@ protected List run() { if (throwException) { throw new RuntimeException("failure from CommandThatFailsFast"); } else { - ArrayList values = new ArrayList(); + ArrayList values = new ArrayList<>(); values.add("success"); return values; } diff --git a/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/CreditCardCommand.java b/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/CreditCardCommand.java index 4c980074d..a6ee7ba30 100644 --- a/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/CreditCardCommand.java +++ b/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/CreditCardCommand.java @@ -168,9 +168,9 @@ public Result submit(String creditCardNumber, String expirationMont } if (Math.random() < 0.8) { - return new Result(true); + return new Result<>(true); } else { - return new Result(false); + return new Result<>(false); } }