Skip to content

Commit

Permalink
Merge pull request #577 from mattrjacobs/java7
Browse files Browse the repository at this point in the history
Upgrade to Java7
  • Loading branch information
mattrjacobs committed Jan 28, 2015
2 parents e115d31 + 4b05910 commit f2600f7
Show file tree
Hide file tree
Showing 53 changed files with 162 additions and 169 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static CacheInvocationContext<CacheResult> createCacheResultInvocationCon
Method method = metaHolder.getMethod();
CacheResult cacheResult = method.getAnnotation(CacheResult.class);
MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheResult.cacheKeyMethod(), metaHolder);
return new CacheInvocationContext<CacheResult>(cacheResult, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
return new CacheInvocationContext<>(cacheResult, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
}
return null;
}
Expand All @@ -60,7 +60,7 @@ public static CacheInvocationContext<CacheRemove> createCacheRemoveInvocationCon
Method method = metaHolder.getMethod();
CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheRemove.cacheKeyMethod(), metaHolder);
return new CacheInvocationContext<CacheRemove>(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
return new CacheInvocationContext<>(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void testGetUserByName_givenNonexistentCacheKeyMethod_shouldThrowExceptio
}

public static class UserService {
private Map<String, User> storage = new ConcurrentHashMap<String, User>();
private Map<String, User> storage = new ConcurrentHashMap<>();

@PostConstruct
private void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ErrorPropagationTest {
private static final Map<String, User> USERS;

static {
USERS = new HashMap<String, User>();
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static class MetricJsonListener implements HystrixMetricsPoller.MetricsA
* <p>
* This is a safety check against a runaway poller causing memory leaks.
*/
private final LinkedBlockingQueue<String> jsonMetrics = new LinkedBlockingQueue<String>(1000);
private final LinkedBlockingQueue<String> jsonMetrics = new LinkedBlockingQueue<>(1000);

/**
* Store JSON messages in a queue.
Expand All @@ -219,7 +219,7 @@ public void handleJsonMetric(String json) {
* @return
*/
public List<String> getJsonMetrics() {
ArrayList<String> metrics = new ArrayList<String>();
ArrayList<String> metrics = new ArrayList<>();
jsonMetrics.drainTo(metrics);
return metrics;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private HttpServer<ByteBuf, ByteBuf> createServer() {
for (int i = 0; i < 3 && server == null; i++) {
port = 10000 + random.nextInt(50000);
try {
return RxNetty.newHttpServerBuilder(port, new HystrixMetricsStreamHandler<ByteBuf, ByteBuf>(
return RxNetty.newHttpServerBuilder(port, new HystrixMetricsStreamHandler<>(
DEFAULT_HYSTRIX_PREFIX,
DEFAULT_INTERVAL,
new RequestHandler<ByteBuf, ByteBuf>() { // Application handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected Tag getServoInstanceTag() {
*/
private List<Monitor<?>> getServoMonitors() {

List<Monitor<?>> monitors = new ArrayList<Monitor<?>>();
List<Monitor<?>> monitors = new ArrayList<>();

monitors.add(new InformationalMetric<String>(MonitorConfig.builder("name").build()) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected Tag getServoInstanceTag() {
*/
private List<Monitor<?>> getServoMonitors() {

List<Monitor<?>> monitors = new ArrayList<Monitor<?>>();
List<Monitor<?>> monitors = new ArrayList<>();

monitors.add(new InformationalMetric<Boolean>(MonitorConfig.builder("isCircuitBreakerOpen").build()) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected Tag getServoInstanceTag() {
*/
private List<Monitor<?>> getServoMonitors() {

List<Monitor<?>> monitors = new ArrayList<Monitor<?>>();
List<Monitor<?>> monitors = new ArrayList<>();

monitors.add(new InformationalMetric<String>(MonitorConfig.builder("name").build()) {
@Override
Expand Down
26 changes: 13 additions & 13 deletions hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, TryableSemaphore> fallbackSemaphorePerCircuit = new ConcurrentHashMap<String, TryableSemaphore>();
protected static final ConcurrentHashMap<String, TryableSemaphore> 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<String, TryableSemaphore> executionSemaphorePerCircuit = new ConcurrentHashMap<String, TryableSemaphore>();
protected static final ConcurrentHashMap<String, TryableSemaphore> executionSemaphorePerCircuit = new ConcurrentHashMap<>();
/* END EXECUTION Semaphore */

protected final AtomicReference<Reference<TimerListener>> timeoutTimer = new AtomicReference<Reference<TimerListener>>();
protected final AtomicReference<Reference<TimerListener>> timeoutTimer = new AtomicReference<>();

protected AtomicBoolean started = new AtomicBoolean();
protected volatile long invocationStartTime = -1;
Expand All @@ -105,10 +105,10 @@ protected static enum TimedOutStatus {
protected volatile ExecutionResult executionResult = ExecutionResult.EMPTY;

/* If this command executed and timed-out */
protected final AtomicReference<TimedOutStatus> isCommandTimedOut = new AtomicReference<TimedOutStatus>(TimedOutStatus.NOT_EXECUTED);
protected final AtomicReference<TimedOutStatus> isCommandTimedOut = new AtomicReference<>(TimedOutStatus.NOT_EXECUTED);
protected final AtomicBoolean isExecutionComplete = new AtomicBoolean(false);
protected final AtomicBoolean isExecutedInThread = new AtomicBoolean(false);
protected final AtomicReference<Action0> endCurrentThreadExecutingCommand = new AtomicReference<Action0>(); // don't like how this is being done
protected final AtomicReference<Action0> endCurrentThreadExecutingCommand = new AtomicReference<>(); // don't like how this is being done


/**
Expand All @@ -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<Class<?>, String> defaultNameCache = new ConcurrentHashMap<Class<?>, String>();
private static ConcurrentHashMap<Class<?>, String> defaultNameCache = new ConcurrentHashMap<>();

/* package */static String getDefaultNameFromClass(Class<?> cls) {
String fromCache = defaultNameCache.get(cls);
Expand Down Expand Up @@ -358,7 +358,7 @@ protected ObservableCommand<R> toObservable(final boolean performAsyncTimeout) {
if (fromCache != null) {
/* mark that we received this response from cache */
metrics.markResponseFromCache();
return new CachedObservableResponse<R>((CachedObservableOriginal<R>) fromCache, this);
return new CachedObservableResponse<>((CachedObservableOriginal<R>) fromCache, this);
}
}

Expand Down Expand Up @@ -478,17 +478,17 @@ public void call() {
// put in cache
if (isRequestCachingEnabled()) {
// wrap it for caching
o = new CachedObservableOriginal<R>(o.cache(), this);
o = new CachedObservableOriginal<>(o.cache(), this);
Observable<R> fromCache = requestCache.putIfAbsent(getCacheKey(), o);
if (fromCache != null) {
// another thread beat us so we'll use the cached value instead
o = new CachedObservableResponse<R>((CachedObservableOriginal<R>) fromCache, this);
o = new CachedObservableResponse<>((CachedObservableOriginal<R>) fromCache, this);
}
// we just created an ObservableCommand so we cast and return it
return (ObservableCommand<R>) o;
} else {
// no request caching so a simple wrapper just to pass 'this' along with the Observable
return new ObservableCommand<R>(o, this);
return new ObservableCommand<>(o, this);
}
}

Expand Down Expand Up @@ -556,7 +556,7 @@ public void call(Notification<? super R> n) {
setRequestContextIfNeeded(currentRequestContext);
}

}).lift(new HystrixObservableTimeoutOperator<R>(_self, performAsyncTimeout)).map(new Func1<R, R>() {
}).lift(new HystrixObservableTimeoutOperator<>(_self, performAsyncTimeout)).map(new Func1<R, R>() {

boolean once = false;

Expand Down Expand Up @@ -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<TimerListener>(listener);
_tl = new SoftReference<>(listener);
}
final Reference<TimerListener> tl = _tl;

Expand Down Expand Up @@ -1463,7 +1463,7 @@ private ExecutionResult(List<HystrixEventType> events, int executionTime, Except
* @return
*/
public ExecutionResult addEvents(HystrixEventType... events) {
ArrayList<HystrixEventType> newEvents = new ArrayList<HystrixEventType>();
ArrayList<HystrixEventType> newEvents = new ArrayList<>();
newEvents.addAll(this.events);
for (HystrixEventType e : events) {
newEvents.add(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void _reset() {
private static ThreadLocal<LinkedList<HystrixCommandKey>> currentCommand = new ThreadLocal<LinkedList<HystrixCommandKey>>() {
@Override
protected LinkedList<HystrixCommandKey> initialValue() {
return new LinkedList<HystrixCommandKey>();
return new LinkedList<>();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HystrixCircuitBreaker> circuitBreakersByCommand = new ConcurrentHashMap<String, HystrixCircuitBreaker>();
private static ConcurrentHashMap<String, HystrixCircuitBreaker> circuitBreakersByCommand = new ConcurrentHashMap<>();

/**
* Get the {@link HystrixCircuitBreaker} instance for a given {@link HystrixCommandKey}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected HystrixCollapser(Setter setter) {
}

HystrixCollapserProperties properties = HystrixPropertiesFactory.getCollapserProperties(collapserKey, propertiesBuilder);
this.collapserFactory = new RequestCollapserFactory<BatchReturnType, ResponseType, RequestArgumentType>(collapserKey, scope, timer, properties);
this.collapserFactory = new RequestCollapserFactory<>(collapserKey, scope, timer, properties);
this.requestCache = HystrixRequestCache.getInstance(collapserKey, HystrixPlugins.getInstance().getConcurrencyStrategy());

if (metrics == null) {
Expand Down Expand Up @@ -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<Class<? extends HystrixCollapser>, String> defaultNameCache = new ConcurrentHashMap<Class<? extends HystrixCollapser>, String>();
private static ConcurrentHashMap<Class<? extends HystrixCollapser>, String> defaultNameCache = new ConcurrentHashMap<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HystrixCollapserKey> intern = new ConcurrentHashMap<String, HystrixCollapserKey>();
private static ConcurrentHashMap<String, HystrixCollapserKey> intern = new ConcurrentHashMap<>();

/**
* Retrieve (or create) an interned HystrixCollapserKey instance for a given name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HystrixCollapserMetrics> metrics = new ConcurrentHashMap<String, HystrixCollapserMetrics>();
private static final ConcurrentHashMap<String, HystrixCollapserMetrics> metrics = new ConcurrentHashMap<>();

/**
* Get or create the {@link HystrixCollapserMetrics} instance for a given {@link HystrixCollapserKey}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HystrixCommandGroupKey> intern = new ConcurrentHashMap<String, HystrixCommandGroupKey>();
private static ConcurrentHashMap<String, HystrixCommandGroupKey> intern = new ConcurrentHashMap<>();

/**
* Retrieve (or create) an interned HystrixCommandGroup instance for a given name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HystrixCommandKey> intern = new ConcurrentHashMap<String, HystrixCommandKey>();
private static ConcurrentHashMap<String, HystrixCommandKey> intern = new ConcurrentHashMap<>();

/**
* Retrieve (or create) an interned HystrixCommandKey instance for a given name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HystrixCommandMetrics> metrics = new ConcurrentHashMap<String, HystrixCommandMetrics>();
private static final ConcurrentHashMap<String, HystrixCommandMetrics> metrics = new ConcurrentHashMap<>();

/**
* Get or create the {@link HystrixCommandMetrics} instance for a given {@link HystrixCommandKey}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected HystrixObservableCollapser(Setter setter) {
collapserKey = HystrixCollapserKey.Factory.asKey(defaultKeyName);
}

this.collapserFactory = new RequestCollapserFactory<BatchReturnType, ResponseType, RequestArgumentType>(collapserKey, scope, timer, propertiesBuilder);
this.collapserFactory = new RequestCollapserFactory<>(collapserKey, scope, timer, propertiesBuilder);
this.requestCache = HystrixRequestCache.getInstance(collapserKey, HystrixPlugins.getInstance().getConcurrencyStrategy());

final HystrixObservableCollapser<K, BatchReturnType, ResponseType, RequestArgumentType> self = this;
Expand Down Expand Up @@ -153,7 +153,7 @@ public Observable<Void> mapResponseToRequests(Observable<BatchReturnType> batchR
final Func1<BatchReturnType, ResponseType> mapBatchTypeToResponseType = self.getBatchReturnTypeToResponseTypeMapper();

// index the requests by key
final Map<K, CollapsedRequest<ResponseType, RequestArgumentType>> requestsByKey = new HashMap<K, CollapsedRequest<ResponseType, RequestArgumentType>>(requests.size());
final Map<K, CollapsedRequest<ResponseType, RequestArgumentType>> requestsByKey = new HashMap<>(requests.size());
for (CollapsedRequest<ResponseType, RequestArgumentType> cr : requests) {
requestsByKey.put(requestKeySelector.call(cr.getArgument()), cr);
}
Expand Down Expand Up @@ -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<Class<? extends HystrixObservableCollapser>, String> defaultNameCache = new ConcurrentHashMap<Class<? extends HystrixObservableCollapser>, String>();
private static ConcurrentHashMap<Class<? extends HystrixObservableCollapser>, String> defaultNameCache = new ConcurrentHashMap<>();

}

0 comments on commit f2600f7

Please sign in to comment.