polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [3/4] polygene-java git commit: Code cleaning in CircuitBeaker.
Date Sat, 25 Feb 2017 05:30:05 GMT
Code cleaning in CircuitBeaker.


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/8005b4c0
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/8005b4c0
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/8005b4c0

Branch: refs/heads/develop
Commit: 8005b4c0792ff94dd8c6ddded51b15353383f065
Parents: d85f00f
Author: niclas <niclas@spicter.com>
Authored: Sat Feb 25 13:28:31 2017 +0800
Committer: niclas <niclas@spicter.com>
Committed: Sat Feb 25 13:28:31 2017 +0800

----------------------------------------------------------------------
 .../library/circuitbreaker/CircuitBreaker.java  |  4 ---
 .../library/circuitbreaker/CircuitBreakers.java | 32 ++++++++------------
 2 files changed, 12 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/8005b4c0/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreaker.java
----------------------------------------------------------------------
diff --git a/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreaker.java
b/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreaker.java
index 1e09b6e..72fbb0e 100644
--- a/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreaker.java
+++ b/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreaker.java
@@ -194,11 +194,8 @@ public class CircuitBreaker
             else
             {
                 countDown--;
-
                 lastThrowable = throwable;
-
                 pcs.firePropertyChange( "serviceLevel", ( countDown + 1 ) / ( (double) threshold
), countDown / ( (double) threshold ) );
-
                 if( countDown == 0 )
                 {
                     trip();
@@ -212,7 +209,6 @@ public class CircuitBreaker
         if( status == Status.on && countDown < threshold )
         {
             countDown++;
-
             pcs.firePropertyChange( "serviceLevel", ( countDown - 1 ) / ( (double) threshold
), countDown / ( (double) threshold ) );
         }
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/8005b4c0/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreakers.java
----------------------------------------------------------------------
diff --git a/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreakers.java
b/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreakers.java
index f786eea..2ef559b 100644
--- a/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreakers.java
+++ b/libraries/circuitbreaker/src/main/java/org/apache/polygene/library/circuitbreaker/CircuitBreakers.java
@@ -34,38 +34,30 @@ public class CircuitBreakers
     */
    public static Predicate<Throwable> in( final Class<? extends Throwable>...
throwables)
    {
-      return new Predicate<Throwable>()
+      return item ->
       {
-         @Override
-         public boolean test( Throwable item )
+         Class<? extends Throwable> throwableClass = item.getClass();
+         for (Class<? extends Throwable> throwable : throwables)
          {
-            Class<? extends Throwable> throwableClass = item.getClass();
-            for (Class<? extends Throwable> throwable : throwables)
-            {
-               if (throwable.isAssignableFrom( throwableClass ))
-                  return true;
-            }
-            return false;
+            if (throwable.isAssignableFrom( throwableClass ))
+               return true;
          }
+         return false;
       };
    }
 
    public static Predicate<Throwable> rootCause( final Predicate<Throwable> specification)
    {
-      return new Predicate<Throwable>()
+      return item ->
       {
-         @Override
-         public boolean test( Throwable item )
+         Throwable cause = item.getCause();
+         if( cause != null )
          {
-            return specification.test( unwrap(item) );
+            return specification.test( cause );
          }
-
-         private Throwable unwrap(Throwable item)
+         else
          {
-            if (item.getCause() != null)
-               return item.getCause();
-            else
-               return item;
+            return specification.test( item );
          }
       };
    }


Mime
View raw message