Last active
December 29, 2015 14:19
-
-
Save eswdd/7683613 to your computer and use it in GitHub Desktop.
Setting up a QoS interceptor to meet the usecase in https://github.com/betfair/cougar/issues/19
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
public class RejectCalls implements ExecutionPreProcessor { | |
private Set<String> toReject = new HashSet<String>(); | |
public void setToReject(String s) { | |
for (String r : s.split(",")) { | |
toReject.add(r.trim()); | |
} | |
} | |
@Override | |
public ExecutionRequirement getExecutionRequirement() { | |
// won't get called | |
return ExecutionRequirement.EVERY_OPPORTUNITY; | |
} | |
@Override | |
public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) { | |
if (toReject.contains(key.getOperationName())) { | |
return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION, new CougarServiceException(ServerFaultCode.FrameworkError, "Execution rejected"); | |
} | |
return new InterceptorResult(InterceptorState.CONTINUE); | |
} | |
@Override | |
public String getName() { | |
return "RejectCalls"; | |
} | |
} |
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
<!-- Define the inner processor bean --> | |
<bean name="rejectCalls" class="RejectCalls"> | |
<property name="toReject" value="unimportantCall" /> | |
</bean> | |
<!-- Define the status source --> | |
<!-- TODO --> | |
<!-- Define the QoS processor --> | |
<bean name="highLoadAverageRejectUnimportantCalls" class="com.betfair.cougar.core.impl.ev.QoSProcessor"> | |
<constructor-arg index="0" ref="loadAverageMonitor"/> | |
<constructor-arg index="1" value="WARN"/> | |
<constructor-arg index="2" ref="rejectCalls"/> | |
</bean> | |
<!-- register the qos processor --> | |
<bean parent="preProcessorInterceptorRegistrationHelper"> | |
<property name="interceptor" ref="highLoadAverageRejectUnimportantCalls"/> | |
</bean> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The upshot of this would be to reject all calls to any operation of the name "unimportantCall" when the given load average monitor is in either a WARN or a FAIL state.