Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
23 changed files
with
876 additions
and
427 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
promagent-dist/promagent-api/src/main/java/io/promagent/annotations/Returned.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,45 @@ | ||
// Copyright 2017 The Promagent Authors | ||
// | ||
// 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.promagent.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A parameter annotated with @Returned can be used in a Hook's @After method to capture the return value of the instrumented method. | ||
* | ||
* Example: In order to instrument the following method: | ||
* | ||
* <pre> | ||
* int sum(int a, int b) {...} | ||
* </pre> | ||
* | ||
* A Hook could use an @After method like this: | ||
* | ||
* <pre> | ||
* {@literal @}After(method = "sum") | ||
* void after(int a, int b, @Returned int sum) {...} | ||
* </pre> | ||
* | ||
* The parameter annotated with @Returned is optional, if the hook does not use the return value, the parameter can be omitted. | ||
* <p/> | ||
* If the instrumented method terminates exceptionally, the type's default value is assigned to the parameter, | ||
* i.e. {@code 0} for numeric types and {@code null} for reference types. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.PARAMETER) | ||
public @interface Returned {} |
47 changes: 47 additions & 0 deletions
47
promagent-dist/promagent-api/src/main/java/io/promagent/annotations/Thrown.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,47 @@ | ||
// Copyright 2017 The Promagent Authors | ||
// | ||
// 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.promagent.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A parameter annotated with @Thrown can be used in a Hook's @After method to capture an Exception thrown in an instrumented method. | ||
* | ||
* Example: In order to instrument the following method: | ||
* | ||
* <pre> | ||
* int div(int a, int b) { | ||
* return a / b; | ||
* } | ||
* </pre> | ||
* | ||
* A Hook could use an @After method like this: | ||
* | ||
* <pre> | ||
* {@literal @}After(method = "div") | ||
* void after(int a, int b, @Returned int result, @Thrown Throwable exception) {...} | ||
* </pre> | ||
* | ||
* In case everything goes well, the {@code result} will be the return value of {@code div()}, and {@code excption} will be {@code null}. | ||
* If {@code b} is {@code 0}, the {@code result} will be {@code 0}, and {@code exception} will be an {@link ArithmeticException} (division by zero). | ||
* <p/> | ||
* The parameter annotated with @Thrown is optional, if the hook does not use the exception, the parameter can be omitted. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.PARAMETER) | ||
public @interface Thrown {} |
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
Oops, something went wrong.