/[projects]/miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/CircuitBreaker.java
ViewVC logotype

Diff of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/CircuitBreaker.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3211 by torben, Tue Jun 9 09:28:14 2015 UTC revision 3212 by torben, Thu Dec 28 09:34:47 2017 UTC
# Line 5  import java.util.concurrent.ExecutorServ Line 5  import java.util.concurrent.ExecutorServ
5  import java.util.concurrent.Executors;  import java.util.concurrent.Executors;
6    
7  import dk.thoerup.circuitbreaker.config.BreakerConfig;  import dk.thoerup.circuitbreaker.config.BreakerConfig;
 import dk.thoerup.circuitbreaker.config.StaticConfig;  
8  import dk.thoerup.circuitbreaker.notification.NotiferHelper;  import dk.thoerup.circuitbreaker.notification.NotiferHelper;
9  import dk.thoerup.circuitbreaker.notification.Notifier;  import dk.thoerup.circuitbreaker.notification.Notifier;
10  import dk.thoerup.circuitbreaker.notification.NullNotifier;  import dk.thoerup.circuitbreaker.notification.NullNotifier;
# Line 16  import dk.thoerup.circuitbreaker.statist Line 15  import dk.thoerup.circuitbreaker.statist
15   *   *
16   *  example of how it can be used   *  example of how it can be used
17    
18   private CircuitBreaker cb = new CircuitBreaker("test", 5, 10000);   private CircuitBreaker<String> cb = new CircuitBreaker<>("test", 5, 10000);
19   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20                  class TestInvocation implements CircuitInvocation {                  class TestInvocation implements CircuitInvocation<String> {
21                          String url;                          String url;
22                          public TestInvocation(String url) {                          public TestInvocation(String url) {
23                                  this.url = url;                                  this.url = url;
24                          }                          }
25                          public Object proceed() throws Exception{                          public String proceed() throws Exception{
26                                                                    
27                                  URL u = new URL(url);                                  URL u = new URL(url);
28                                  URLConnection c = u.openConnection();                                  URLConnection c = u.openConnection();
# Line 37  import dk.thoerup.circuitbreaker.statist Line 36  import dk.thoerup.circuitbreaker.statist
36                                                    
37                  }                  }
38                  try {                  try {
39                          String s = (String) cb.invoke(new TestInvocation("http://rafiki/test"));                          String s = cb.invoke(new TestInvocation("http://rafiki/test"));
40                          response.getWriter().print(s);                          response.getWriter().print(s);
41                  } catch (Exception e) {                  } catch (Exception e) {
42                          logger.warning( e.getMessage() );                          logger.warning( e.getMessage() );
# Line 49  import dk.thoerup.circuitbreaker.statist Line 48  import dk.thoerup.circuitbreaker.statist
48   */   */
49    
50    
51  public class CircuitBreaker{  public class CircuitBreaker<T>{
52                    
53          private volatile CircuitBreakerState currentState;          private volatile CircuitBreakerState currentState;
54                    
# Line 63  public class CircuitBreaker{ Line 62  public class CircuitBreaker{
62          private Notifier notifier = new NullNotifier();          private Notifier notifier = new NullNotifier();
63          private Statistics stats = new NullStatistics();          private Statistics stats = new NullStatistics();
64                    
         @Deprecated  
         public CircuitBreaker(String name, int threshold, int timeoutMS) {  
                 this(name, new StaticConfig(threshold, timeoutMS) );  
         }  
65                    
66          public CircuitBreaker(String name, BreakerConfig config) {          public CircuitBreaker(String name, BreakerConfig config) {
67                  closed.setThreshold(config);                  closed.setThreshold(config);
# Line 85  public class CircuitBreaker{ Line 80  public class CircuitBreaker{
80          }          }
81                    
82                    
83      public Object invoke(CircuitInvocation invocation) throws Exception      public T invoke(CircuitInvocation<T> invocation) throws Exception
84      {      {
85          stats.addStatistics(Event.Invocation);          stats.addStatistics(Event.Invocation);
86                    
87          Object result = null;          T result = null;
88          try          try
89          {          {
90              getState().preInvoke(this);              getState().preInvoke(this);

Legend:
Removed from v.3211  
changed lines
  Added in v.3212

  ViewVC Help
Powered by ViewVC 1.1.20