1 package net.secodo.jcircuitbreaker.breaker.execution; 2 3 import java.util.Collection; 4 5 6 /** 7 * Defines context which is specific to single execution of Task (target method) by circuit breaker. Can be used to 8 * share state, get information about currently running tasks by 9 * {@link net.secodo.jcircuitbreaker.breakstrategy.BreakStrategy} or 10 * {@link net.secodo.jcircuitbreaker.breakhandler.BreakHandler}. 11 * 12 * @param <R> the return type of real-method that is being executed 13 */ 14 public interface ExecutionContext<R> { 15 /** 16 * Returns collection of Tasks which are currently executed by circuit breaker. 17 * @return collection of {@link ExecutedTask}. 18 */ 19 Collection<ExecutedTask<R>> getExecutionsInProgress(); 20 21 /** 22 * Returns custom data that could haven been passed to the circuit breaker when executing Task. This data is specific 23 * only to current execution. 24 * 25 * @param <U> user custom data passed to the breaker 26 * @return custom user data 27 */ 28 <U> U getUserData(); 29 30 /** 31 * Creates or sets new value for context attribute with given name. 32 * 33 * @param name the name under which the attribute will be available 34 * @param value the value of the atribute 35 * @param <T> the type of attribute to set 36 */ 37 <T> void setContextAttribute(String name, T value); 38 39 /** 40 * Return true if context attribute with given name exists. 41 * 42 * @param name name of the attribute that might have been set for current execution 43 * 44 * @return true if attribute with given name exist 45 */ 46 boolean hasContextAttribute(String name); 47 48 /** 49 * Returns value of given context attribute or null of there is no such attribute. 50 * 51 * @see #hasContextAttribute(String) 52 * 53 * @param name name of the attribute that might have been set for current execution 54 * @param <T> the type to which the value of the attribute with given name should be cast to 55 * 56 * @return attribute with given name of null if such attribute does not exist 57 */ 58 <T> T getContextAttribute(String name); 59 60 61 }