-
Notifications
You must be signed in to change notification settings - Fork 319
Add NativeLoader listener support #9903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f80bcda
Adding listener support to NativeLoader
dougqh 54af840
Adding listener tests
dougqh 035ba29
isEmpty -> isNop to better convey purpose
dougqh fa9428e
Adding listener tests
dougqh f7edec9
Adding listener tests
dougqh fbe0943
spotless
dougqh ed518d1
More end-to-end listener tests
dougqh b376954
More end-to-end listener testing
dougqh 01ef204
More end-to-end listener tests
dougqh cd6affc
More end-to-end listener tests
dougqh 625b8c3
spotless
dougqh 2b2b9f9
Fixed errant text replacement in Javadoc
dougqh b00bbb6
Adding clarifying comments
dougqh 140ae13
Tweaking listener API
dougqh 9376016
More JavaDoc & spotless
dougqh 20c3e02
More end-to-end listener tests
dougqh f6381ed
More end-to-end listener testing
dougqh e8d44db
spotless
dougqh 0cbfd6e
Merge branch 'master' into dougqh/native-loader-listener
dougqh 3bd0567
Adding coverage
dougqh 1c0dccc
Merge branch 'dougqh/native-loader-listener' of github.com:DataDog/dd…
dougqh d77936d
API clean-up
dougqh 9ae3be8
API clean-up
dougqh 1f99359
Fixing up oversights in previous parameter reordering
dougqh 244807f
More test coverage
dougqh 1e458b2
More coverage
dougqh 517e3b4
spotless
dougqh 1f98b7f
More coverage
dougqh 5bdaa88
spotless
dougqh 0b8ab6c
Merge branch 'master' into dougqh/native-loader-listener
dougqh 3e9234d
Merge branch 'master' into dougqh/native-loader-listener
dougqh 5fff446
Merge branch 'master' into dougqh/native-loader-listener
dougqh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
...nts/native-loader/src/main/java/datadog/nativeloader/CompositeLibraryLoadingListener.java
This file contains hidden or 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,133 @@ | ||
| package datadog.nativeloader; | ||
|
|
||
| import java.net.URL; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| final class CompositeLibraryLoadingListener extends SafeLibraryLoadingListener { | ||
| private final Collection<? extends LibraryLoadingListener> listeners; | ||
|
|
||
| CompositeLibraryLoadingListener(LibraryLoadingListener... listeners) { | ||
| this(Arrays.asList(listeners)); | ||
| } | ||
|
|
||
| CompositeLibraryLoadingListener(Collection<? extends LibraryLoadingListener> listeners) { | ||
| this.listeners = listeners; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isNop() { | ||
| return this.listeners.isEmpty(); | ||
| } | ||
|
|
||
| int size() { | ||
| return this.listeners.size(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onResolveDynamic( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| boolean isPreloaded, | ||
| URL optionalUrl) { | ||
| for (LibraryLoadingListener listener : this.listeners) { | ||
| try { | ||
| listener.onResolveDynamic( | ||
| platformSpec, optionalComponent, libName, isPreloaded, optionalUrl); | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onResolveDynamicFailure( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| LibraryLoadException optionalCause) { | ||
| for (LibraryLoadingListener listener : this.listeners) { | ||
| try { | ||
| listener.onResolveDynamicFailure(platformSpec, optionalComponent, libName, optionalCause); | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onLoad( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| boolean isPreloaded, | ||
| Path optionalLibPath) { | ||
| for (LibraryLoadingListener listener : this.listeners) { | ||
| try { | ||
| listener.onLoad(platformSpec, optionalComponent, libName, isPreloaded, optionalLibPath); | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onTempFileCreated( | ||
| PlatformSpec platformSpec, String optionalComponent, String libName, Path tempFile) { | ||
| for (LibraryLoadingListener listener : this.listeners) { | ||
| try { | ||
| listener.onTempFileCreated(platformSpec, optionalComponent, libName, tempFile); | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onTempFileCreationFailure( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| Path tempDir, | ||
| String libExt, | ||
| Path optionalTempFile, | ||
| Throwable optionalCause) { | ||
| for (LibraryLoadingListener listener : this.listeners) { | ||
| try { | ||
| listener.onTempFileCreationFailure( | ||
| platformSpec, | ||
| optionalComponent, | ||
| libName, | ||
| tempDir, | ||
| libExt, | ||
| optionalTempFile, | ||
| optionalCause); | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onTempFileCleanup( | ||
| PlatformSpec platformSpec, String optionalComponent, String libName, Path tempPath) { | ||
| for (LibraryLoadingListener listener : this.listeners) { | ||
| try { | ||
| listener.onTempFileCleanup(platformSpec, optionalComponent, libName, tempPath); | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CompositeLibraryLoadingListener join(LibraryLoadingListener... listeners) { | ||
| ArrayList<LibraryLoadingListener> combinedListeners = | ||
| new ArrayList<>(this.listeners.size() + listeners.length); | ||
| combinedListeners.addAll(this.listeners); | ||
| combinedListeners.addAll(Arrays.asList(listeners)); | ||
| return new CompositeLibraryLoadingListener(combinedListeners); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return this.getClass().getSimpleName() + ":" + this.listeners.toString(); | ||
| } | ||
| } |
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
components/native-loader/src/main/java/datadog/nativeloader/LibraryLoadingListener.java
This file contains hidden or 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,53 @@ | ||
| package datadog.nativeloader; | ||
|
|
||
| import java.net.URL; | ||
| import java.nio.file.Path; | ||
|
|
||
| public interface LibraryLoadingListener { | ||
| default void onResolveDynamic( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| boolean isPreloaded, | ||
| URL optionalUrl) {} | ||
|
|
||
| default void onResolveDynamicFailure( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| LibraryLoadException optionalCause) {} | ||
|
|
||
| default void onLoad( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| boolean isPreloaded, | ||
| Path optionalLibPath) {} | ||
|
|
||
| default void onLoadFailure( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| LibraryLoadException optionalCause) {} | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll probably end up tweaking the methods for temp file notification if/when we add in pluggable temp file managers. |
||
| default void onTempFileCreated( | ||
| PlatformSpec platformSpec, String optionalComponent, String libName, Path tempFile) {} | ||
|
|
||
| default void onTempFileCreationFailure( | ||
| PlatformSpec platformSpec, | ||
| String optionalComponent, | ||
| String libName, | ||
| Path tempDir, | ||
| String libExt, | ||
| Path optionalTempFile, | ||
| Throwable optionalCause) {} | ||
|
|
||
| default void onTempFileCleanup( | ||
| PlatformSpec platformSpec, String optionalComponent, String libName, Path tempFile) {} | ||
| } | ||
|
|
||
| abstract class SafeLibraryLoadingListener implements LibraryLoadingListener { | ||
| public abstract SafeLibraryLoadingListener join(LibraryLoadingListener... listeners); | ||
|
|
||
| public abstract boolean isNop(); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.