Skip to content

Upgraded to below Spring and dependencies versions: #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jrugged-aspects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.2</version>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.2</version>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.fishwife</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,45 @@
@Target(ElementType.METHOD)
public @interface CircuitBreaker {

/**
* Name of the circuit. Each annotation with a shared value shares
* the same CircuitBreaker.
* @return the value
*/
String name();
/**
* Name of the circuit. Each annotation with a shared value shares the same
* CircuitBreaker.
*
* @return the value
*/
String name();

/**
* Exception types that the {@link
* org.fishwife.jrugged.CircuitBreaker} will ignore (pass through
* transparently without tripping).
* @return the Exception types.
*/
Class<? extends Throwable>[] ignore() default {};
/**
* Exception types that the {@link org.fishwife.jrugged.CircuitBreaker} will
* ignore (pass through transparently without tripping).
*
* @return the Exception types.
*/
Class<? extends Throwable>[] ignore() default {};

/**
* Specifies the length of the measurement window for failure
* tolerances in milliseconds. i.e. if <code>limit</code>
* failures occur within <code>windowMillis</code> milliseconds,
* the breaker will trip.
* @return the length of the measurement window.
*/
long windowMillis() default -1;
/**
* Specifies the length of the measurement window for failure tolerances in
* milliseconds. i.e. if <code>limit</code> failures occur within
* <code>windowMillis</code> milliseconds, the breaker will trip.
*
* @return the length of the measurement window.
*/
long windowMillis() default -1;

/**
* Specifies the number of failures that must occur within a
* configured time window in order to trip the circuit breaker.
* @return the number of failures.
*/
int limit() default -1;
/**
* Specifies the number of failures that must occur within a configured time
* window in order to trip the circuit breaker.
*
* @return the number of failures.
*/
int limit() default -1;


/**
* Amount of time in milliseconds after tripping after which the
* {@link org.fishwife.jrugged.CircuitBreaker} is reset and will
* allow a test request through.
* @return the amount of time in milliseconds.
*/
long resetMillis() default -1;
/**
* Amount of time in milliseconds after tripping after which the
* {@link org.fishwife.jrugged.CircuitBreaker} is reset and will allow a test
* request through.
*
* @return the amount of time in milliseconds.
*/
long resetMillis() default -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,95 +33,90 @@
@Aspect
public class CircuitBreakerAspect {

private static final Logger logger =
LoggerFactory.getLogger(CircuitBreakerAspect.class);

/**
* Maps names to CircuitBreakers.
*/
private CircuitBreakerFactory circuitBreakerFactory;

/** Default constructor. */
public CircuitBreakerAspect() {
circuitBreakerFactory = new CircuitBreakerFactory();
}

/**
* Sets the {@link org.fishwife.jrugged.CircuitBreakerFactory} to use when creating new
* {@link org.fishwife.jrugged.CircuitBreaker} instances.
* @param circuitBreakerFactory the {@link org.fishwife.jrugged.CircuitBreakerFactory} to
* use.
*/
public void setCircuitBreakerFactory(
CircuitBreakerFactory circuitBreakerFactory) {
this.circuitBreakerFactory = circuitBreakerFactory;
}

/**
* Get the {@link org.fishwife.jrugged.CircuitBreakerFactory} that is being used to create
* new {@link org.fishwife.jrugged.CircuitBreaker} instances.
* @return the {@link org.fishwife.jrugged.CircuitBreakerFactory}.
*/
public CircuitBreakerFactory getCircuitBreakerFactory() {
return circuitBreakerFactory;
}

/** Runs a method call through the configured
* {@link org.fishwife.jrugged.CircuitBreaker}.
* @param pjp a {@link ProceedingJoinPoint} representing an annotated
* method call.
* @param circuitBreakerAnnotation the {@link org.fishwife.jrugged.CircuitBreaker} annotation
* that wrapped the method.
* @throws Throwable if the method invocation itself or the wrapping
* {@link org.fishwife.jrugged.CircuitBreaker} throws one during execution.
* @return The return value from the method call.
*/
@Around("@annotation(circuitBreakerAnnotation)")
public Object monitor(final ProceedingJoinPoint pjp,
CircuitBreaker circuitBreakerAnnotation) throws Throwable {
final String name = circuitBreakerAnnotation.name();

org.fishwife.jrugged.CircuitBreaker circuitBreaker =
circuitBreakerFactory.findCircuitBreaker(name);

if (circuitBreaker == null) {
DefaultFailureInterpreter dfi =
new DefaultFailureInterpreter(
circuitBreakerAnnotation.ignore(),
circuitBreakerAnnotation.limit(),
circuitBreakerAnnotation.windowMillis());

CircuitBreakerConfig config = new CircuitBreakerConfig(
circuitBreakerAnnotation.resetMillis(), dfi);

circuitBreaker =
circuitBreakerFactory.createCircuitBreaker(name, config);
}

if (logger.isDebugEnabled()) {
logger.debug("Have @CircuitBreaker method with breaker name {}, " +
"wrapping call on method {} of target object {} with status {}",
new Object[]{
name,
pjp.getSignature().getName(),
pjp.getTarget(),
circuitBreaker.getStatus()});
}

return circuitBreaker.invoke(new Callable<Object>() {
public Object call() throws Exception {
try {
return pjp.proceed();
} catch (Throwable e) {
if (e instanceof Exception) {
throw (Exception) e;
} else if (e instanceof Error) {
throw (Error) e;
} else {
throw new RuntimeException(e);
}
}
}
});
}
private static final Logger logger = LoggerFactory.getLogger(CircuitBreakerAspect.class);

/**
* Maps names to CircuitBreakers.
*/
private CircuitBreakerFactory circuitBreakerFactory;

/** Default constructor. */
public CircuitBreakerAspect() {
circuitBreakerFactory = new CircuitBreakerFactory();
}

/**
* Sets the {@link org.fishwife.jrugged.CircuitBreakerFactory} to use when
* creating new {@link org.fishwife.jrugged.CircuitBreaker} instances.
*
* @param circuitBreakerFactory the
* {@link org.fishwife.jrugged.CircuitBreakerFactory}
* to use.
*/
public void setCircuitBreakerFactory(CircuitBreakerFactory circuitBreakerFactory) {
this.circuitBreakerFactory = circuitBreakerFactory;
}

/**
* Get the {@link org.fishwife.jrugged.CircuitBreakerFactory} that is being used
* to create new {@link org.fishwife.jrugged.CircuitBreaker} instances.
*
* @return the {@link org.fishwife.jrugged.CircuitBreakerFactory}.
*/
public CircuitBreakerFactory getCircuitBreakerFactory() {
return circuitBreakerFactory;
}

/**
* Runs a method call through the configured
* {@link org.fishwife.jrugged.CircuitBreaker}.
*
* @param pjp a {@link ProceedingJoinPoint} representing an
* annotated method call.
* @param circuitBreakerAnnotation the
* {@link org.fishwife.jrugged.CircuitBreaker}
* annotation that wrapped the method.
* @throws Throwable if the method invocation itself or the wrapping
* {@link org.fishwife.jrugged.CircuitBreaker} throws one
* during execution.
* @return The return value from the method call.
*/
@Around("@annotation(circuitBreakerAnnotation)")
public Object monitor(final ProceedingJoinPoint pjp, CircuitBreaker circuitBreakerAnnotation) throws Throwable {
final String name = circuitBreakerAnnotation.name();

org.fishwife.jrugged.CircuitBreaker circuitBreaker = circuitBreakerFactory.findCircuitBreaker(name);

if (circuitBreaker == null) {
DefaultFailureInterpreter dfi = new DefaultFailureInterpreter(circuitBreakerAnnotation.ignore(),
circuitBreakerAnnotation.limit(), circuitBreakerAnnotation.windowMillis());

CircuitBreakerConfig config = new CircuitBreakerConfig(circuitBreakerAnnotation.resetMillis(), dfi);

circuitBreaker = circuitBreakerFactory.createCircuitBreaker(name, config);
}

if (logger.isDebugEnabled()) {
logger.debug(
"Have @CircuitBreaker method with breaker name {}, "
+ "wrapping call on method {} of target object {} with status {}",
new Object[] { name, pjp.getSignature().getName(), pjp.getTarget(), circuitBreaker.getStatus() });
}

return circuitBreaker.invoke(new Callable<Object>() {
public Object call() throws Exception {
try {
return pjp.proceed();
} catch (Throwable e) {
if (e instanceof Exception) {
throw (Exception) e;
} else if (e instanceof Error) {
throw (Error) e;
} else {
throw new RuntimeException(e);
}
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
import java.lang.annotation.Target;

/**
* Annotation that is used to indicate that a method should be
* wrapped by a {@link org.fishwife.jrugged.PerformanceMonitor}. The value
* passed to the annotation serves as a key for a PerformanceMonitor instance.
* You may have a unique PerformanceMonitor for individual methods by using
* unique key names in the PerformanceMonitor annotation for the method, or you
* may share a PerformanceMonitor across classes and methods by using the
* same key value for many PerformanceMonitor annotations.
* Annotation that is used to indicate that a method should be wrapped by a
* {@link org.fishwife.jrugged.PerformanceMonitor}. The value passed to the
* annotation serves as a key for a PerformanceMonitor instance. You may have a
* unique PerformanceMonitor for individual methods by using unique key names in
* the PerformanceMonitor annotation for the method, or you may share a
* PerformanceMonitor across classes and methods by using the same key value for
* many PerformanceMonitor annotations.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PerformanceMonitor {
/**
* The value for the configured
* {@link org.fishwife.jrugged.PerformanceMonitor}.
* @return the value.
*/
String value();
/**
* The value for the configured {@link org.fishwife.jrugged.PerformanceMonitor}.
*
* @return the value.
*/
String value();
}
Loading