forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not load hystrix when hystrix does not exist on the classpath. (sofas…
- Loading branch information
Showing
4 changed files
with
65 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
import com.alipay.sofa.rpc.core.request.SofaRequest; | ||
import com.alipay.sofa.rpc.core.response.SofaResponse; | ||
import com.alipay.sofa.rpc.filter.FilterInvoker; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import com.netflix.hystrix.HystrixCommand; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
@@ -32,12 +34,14 @@ | |
* | ||
* @author <a href=mailto:[email protected]>ScienJus</a> | ||
*/ | ||
public class SofaHystrixCommand extends HystrixCommand<SofaResponse> implements SofaHystrixInvokable<SofaResponse> { | ||
public class SofaHystrixCommand extends HystrixCommand<SofaResponse> implements SofaHystrixInvokable { | ||
|
||
private RpcInternalContext rpcInternalContext; | ||
private RpcInvokeContext rpcInvokeContext; | ||
protected FilterInvoker invoker; | ||
protected SofaRequest request; | ||
private final static Logger LOGGER = LoggerFactory.getLogger(SofaHystrixCommand.class); | ||
|
||
private RpcInternalContext rpcInternalContext; | ||
private RpcInvokeContext rpcInvokeContext; | ||
protected FilterInvoker invoker; | ||
protected SofaRequest request; | ||
|
||
public SofaHystrixCommand(FilterInvoker invoker, SofaRequest request) { | ||
super(SofaHystrixConfig.loadSetterFactory((ConsumerConfig) invoker.getConfig()).createSetter(invoker, request)); | ||
|
@@ -47,6 +51,15 @@ public SofaHystrixCommand(FilterInvoker invoker, SofaRequest request) { | |
this.request = request; | ||
} | ||
|
||
@Override | ||
public SofaResponse invoke() { | ||
if (isCircuitBreakerOpen() && LOGGER.isWarnEnabled(invoker.getConfig().getAppName())) { | ||
LOGGER.warnWithApp(invoker.getConfig().getAppName(), "Circuit Breaker is opened, method: {}#{}", | ||
invoker.getConfig().getInterfaceId(), request.getMethodName()); | ||
} | ||
return execute(); | ||
} | ||
|
||
@Override | ||
protected SofaResponse run() throws Exception { | ||
RpcInternalContext.setContext(rpcInternalContext); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,13 @@ | |
package com.alipay.sofa.rpc.hystrix; | ||
|
||
import com.alipay.sofa.rpc.core.response.SofaResponse; | ||
import com.netflix.hystrix.HystrixInvokableInfo; | ||
|
||
/** | ||
* Basic interface for {@link SofaHystrixCommand} and {@link SofaHystrixObservableCommand} | ||
* @param <R> | ||
* | ||
* @author <a href=mailto:[email protected]>ScienJus</a> | ||
*/ | ||
public interface SofaHystrixInvokable<R> extends HystrixInvokableInfo<R> { | ||
public interface SofaHystrixInvokable { | ||
|
||
SofaResponse execute(); | ||
SofaResponse invoke(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters