Skip to content

Instantly share code, notes, and snippets.

@eswdd
Last active December 29, 2015 14:19
Show Gist options
  • Save eswdd/7683613 to your computer and use it in GitHub Desktop.
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
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";
}
}
<!-- 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>
@eswdd
Copy link
Author

eswdd commented Nov 28, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment