Skip to content

Commit 84bcd57

Browse files
committed
NativeBinaryLoadingListener: inspecting the failing calling stack using CallingStackMetaData
1 parent 37ab5af commit 84bcd57

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

snaploader/src/main/java/electrostatic4j/snaploader/NativeBinaryLoadingListener.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
2+
* Copyright (c) 2023-2025, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -33,13 +33,14 @@
3333
package electrostatic4j.snaploader;
3434

3535
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
36+
import electrostatic4j.snaploader.util.CallingStackMetaData;
3637

3738
/**
3839
* Provides executable functions binding the user applications to
3940
* the loading lifecycle.
4041
* <p>
4142
* Note: All the functions on this interface are dispatched
42-
* by the {@link NativeBinaryLoader#loadBinary(NativeDynamicLibrary)}.
43+
* by the {@link NativeBinaryLoader#loadBinary(NativeDynamicLibrary, LoadingCriterion)}
4344
*
4445
* @author pavl_g
4546
*/
@@ -48,16 +49,19 @@ public interface NativeBinaryLoadingListener {
4849
/**
4950
* Dispatched when loading the system-specific binary has succeeded.
5051
*
51-
* @param nativeBinaryLoader the dispatching loader
52+
* @param nativeBinaryLoader the dispatching loader.
53+
* @param callingStackMetaData a data structure representing the meta data of the calling stack.
5254
*/
53-
void onLoadingSuccess(NativeBinaryLoader nativeBinaryLoader);
55+
void onLoadingSuccess(NativeBinaryLoader nativeBinaryLoader, CallingStackMetaData callingStackMetaData);
5456

5557
/**
5658
* Dispatched when loading the system-specific binary has failed.
5759
*
58-
* @param nativeBinaryLoader the dispatching loader
60+
* @param nativeBinaryLoader the dispatching loader.
61+
* @param callingStackMetaData a data structure representing the meta data of the calling stack.
5962
*/
60-
void onLoadingFailure(NativeBinaryLoader nativeBinaryLoader);
63+
void onLoadingFailure(NativeBinaryLoader nativeBinaryLoader,
64+
CallingStackMetaData callingStackMetaData);
6165

6266
/**
6367
* Dispatched when loading the system-specific binary has failed,
@@ -66,7 +70,8 @@ public interface NativeBinaryLoadingListener {
6670
* Note: this dispatching function could be overridden to add
6771
* your own anti-failure mechanisms (i.e., Retry Criterion).
6872
*
69-
* @param nativeBinaryLoader the dispatching loader
73+
* @param nativeBinaryLoader the dispatching loader.
74+
* @param callingStackMetaData a data structure representing the meta data of the calling stack.
7075
*/
71-
void onRetryCriterionExecution(NativeBinaryLoader nativeBinaryLoader);
76+
void onRetryCriterionExecution(NativeBinaryLoader nativeBinaryLoader, CallingStackMetaData callingStackMetaData);
7277
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023-2025, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'Electrostatic-Sandbox' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package electrostatic4j.snaploader.util;
34+
35+
import electrostatic4j.snaploader.LoadingCriterion;
36+
37+
/**
38+
* A record-like structure representing immutable
39+
* state objects for a calling stack invoking the
40+
* library loading.
41+
*
42+
* @author pavl_g.
43+
*/
44+
public final class CallingStackMetaData {
45+
private final StackTraceElement callingStack;
46+
private final LoadingCriterion loadingCriterion;
47+
private Throwable errorCause;
48+
49+
public CallingStackMetaData(StackTraceElement callingStack, LoadingCriterion loadingCriterion,
50+
Throwable errorCause) {
51+
this(callingStack, loadingCriterion);
52+
this.errorCause = errorCause;
53+
}
54+
55+
public CallingStackMetaData(StackTraceElement callingStack, LoadingCriterion loadingCriterion) {
56+
this.callingStack = callingStack;
57+
this.loadingCriterion = loadingCriterion;
58+
}
59+
60+
public LoadingCriterion getLoadingCriterion() {
61+
return loadingCriterion;
62+
}
63+
64+
public StackTraceElement getCallingStack() {
65+
return callingStack;
66+
}
67+
68+
public Throwable getErrorCause() {
69+
return errorCause;
70+
}
71+
}

0 commit comments

Comments
 (0)