/** * Lookup (or create and store) the RequestVariable for a given HystrixCollapserKey. * * @param commandCollapser collapser to retrieve {@link HystrixRequestVariableHolder} for * @return HystrixRequestVariableHolder */ @SuppressWarnings("unchecked") private HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> getRequestVariableForCommand(final HystrixCollapserBridge<BatchReturnType, ResponseType, RequestArgumentType> commandCollapser) { HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> requestVariable = requestScopedCollapsers.get(commandCollapser.getCollapserKey().name()); if (requestVariable == null) { // 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) @SuppressWarnings({ "rawtypes" }) HystrixRequestVariableHolder newCollapser = new RequestCollapserRequestVariable(commandCollapser, properties, timer, concurrencyStrategy); HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> existing = requestScopedCollapsers.putIfAbsent(commandCollapser.getCollapserKey().name(), newCollapser); if (existing == null) { // this thread won, so return the one we just created requestVariable = newCollapser; } else { // another thread beat us (this should only happen when we have concurrency on the FIRST request for the life of the app for this HystrixCollapser class) requestVariable = existing; /* * This *should* be okay to discard the created object without cleanup as the RequestVariable implementation * should properly do lazy-initialization and only call initialValue() the first time get() is called. * * If it does not correctly follow this contract then there is a chance of a memory leak here. */ } } return requestVariable; }
return existing.toObservable(); } else { return Observable.error(new IllegalArgumentException("Duplicate argument in collapser batch : [" + arg + "] This is not supported. Please turn request-caching on for HystrixCollapser:" + commandCollapser.getCollapserKey().name() + " or prevent duplicates from making it into the batch!"));
/** * Lookup (or create and store) the RequestVariable for a given HystrixCollapserKey. * * @param commandCollapser collapser to retrieve {@link HystrixRequestVariableHolder} for * @return HystrixRequestVariableHolder */ @SuppressWarnings("unchecked") private HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> getRequestVariableForCommand(final HystrixCollapserBridge<BatchReturnType, ResponseType, RequestArgumentType> commandCollapser) { HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> requestVariable = requestScopedCollapsers.get(commandCollapser.getCollapserKey().name()); if (requestVariable == null) { // 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) @SuppressWarnings({ "rawtypes" }) HystrixRequestVariableHolder newCollapser = new RequestCollapserRequestVariable(commandCollapser, properties, timer, concurrencyStrategy); HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> existing = requestScopedCollapsers.putIfAbsent(commandCollapser.getCollapserKey().name(), newCollapser); if (existing == null) { // this thread won, so return the one we just created requestVariable = newCollapser; } else { // another thread beat us (this should only happen when we have concurrency on the FIRST request for the life of the app for this HystrixCollapser class) requestVariable = existing; /* * This *should* be okay to discard the created object without cleanup as the RequestVariable implementation * should properly do lazy-initialization and only call initialValue() the first time get() is called. * * If it does not correctly follow this contract then there is a chance of a memory leak here. */ } } return requestVariable; }
return existing.toObservable(); } else { return Observable.error(new IllegalArgumentException("Duplicate argument in collapser batch : [" + arg + "] This is not supported. Please turn request-caching on for HystrixCollapser:" + commandCollapser.getCollapserKey().name() + " or prevent duplicates from making it into the batch!"));