forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ReactiveX#72: Created a resilience4j-metrics module for Dropwiz…
…ard metri… (ReactiveX#80) Issue ReactiveX#72: Created a resilience4j-metrics module for Dropwizard metrics and moved the Stopwatch class into a new resilience4j-core module.
- Loading branch information
Showing
16 changed files
with
569 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies { | ||
compile (libraries.metrics) | ||
testCompile project(':resilience4j-test') | ||
} |
120 changes: 120 additions & 0 deletions
120
resilience4j-metrics/src/main/java/io/github/resilience4j/metrics/Metrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* | ||
* Copyright 2017: Robert Winkler | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* | ||
*/ | ||
package io.github.resilience4j.metrics; | ||
|
||
import com.codahale.metrics.Timer; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import javaslang.control.Try; | ||
|
||
public interface Metrics { | ||
|
||
/** | ||
* Creates a timed checked supplier. | ||
* @param timer the timer to use | ||
* @param supplier the original supplier | ||
* @return a timed supplier | ||
*/ | ||
static <T> Try.CheckedSupplier<T> decorateCheckedSupplier(Timer timer, Try.CheckedSupplier<T> supplier){ | ||
return () -> { | ||
try (Timer.Context context = timer.time()) { | ||
return supplier.get(); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Creates a timed runnable. | ||
* @param timer the timer to use | ||
* @param runnable the original runnable | ||
* @return a timed runnable | ||
*/ | ||
static Try.CheckedRunnable decorateCheckedRunnable(Timer timer, Try.CheckedRunnable runnable){ | ||
return () -> { | ||
try (Timer.Context context = timer.time()) { | ||
runnable.run(); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Creates a timed checked supplier. | ||
* @param timer the timer to use | ||
* @param supplier the original supplier | ||
* @return a timed supplier | ||
*/ | ||
static <T> Supplier<T> decorateSupplier(Timer timer, Supplier<T> supplier){ | ||
return () -> { | ||
try (Timer.Context context = timer.time()) { | ||
return supplier.get(); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Creates a timed runnable. | ||
* @param timer the timer to use | ||
* @param runnable the original runnable | ||
* @return a timed runnable | ||
*/ | ||
static Runnable decorateRunnable(Timer timer, Runnable runnable){ | ||
return () -> { | ||
try (Timer.Context context = timer.time()) { | ||
runnable.run(); | ||
} | ||
}; | ||
} | ||
|
||
|
||
/** | ||
* Creates a timed function. | ||
* @param timer the timer to use | ||
* @param function the original function | ||
* @return a timed function | ||
*/ | ||
static <T, R> Function<T, R> decorateFunction(Timer timer, Function<T, R> function){ | ||
return (T t) -> { | ||
try (Timer.Context context = timer.time()) { | ||
return function.apply(t); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Creates a timed function. | ||
* @param timer the timer to use | ||
* @param function the original function | ||
* @return a timed function | ||
*/ | ||
static <T, R> Try.CheckedFunction<T, R> decorateCheckedFunction(Timer timer, Try.CheckedFunction<T, R> function){ | ||
return (T t) -> { | ||
try (Timer.Context context = timer.time()) { | ||
return function.apply(t); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.