-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSzCoreProduct.java
89 lines (77 loc) · 2.56 KB
/
SzCoreProduct.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.senzing.g2.engine;
import static com.senzing.g2.engine.SzException.*;
/**
* The package-protected implementation of {@link SzProduct} that works with the {@link
* SzCoreEnvironment} class.
*/
public class SzCoreProduct implements SzProduct {
/** Gets the class prefix to use for {@link SzException} construction. */
private static final String CLASS_PREFIX = SzCoreProduct.class.getSimpleName();
/** The {@link SzCoreEnvironment} that constructed this instance. */
private SzCoreEnvironment env = null;
/** The underlying {@link G2ProductJNI} instance. */
G2ProductJNI nativeApi = null;
/**
* Default constructor.
*
* @throws IllegalStateException If the underlying {@link SzCoreEnvironment} instance has already
* been destroyed.
* @throws SzException If a Senzing failure occurs during initialization.
*/
SzCoreProduct(SzCoreEnvironment environment) throws IllegalStateException, SzException {
this.env = environment;
this.env.execute(
() -> {
this.nativeApi = new G2ProductJNI();
int returnCode =
this.nativeApi.init(
this.env.getInstanceName(), this.env.getSettings(), this.env.isVerboseLogging());
if (returnCode != 0) {
this.env.handleReturnCode(
returnCode,
this.nativeApi,
CLASS_PREFIX + "()",
paramsOf(
"instanceName",
this.env.getInstanceName(),
"settings",
redact(this.env.getSettings()),
"verboseLogging",
this.env.isVerboseLogging()));
}
return null;
});
}
/** The package-protected function to destroy the Senzing Product SDK. */
void destroy() {
synchronized (this) {
if (this.nativeApi == null) return;
this.nativeApi.destroy();
this.nativeApi = null;
}
}
/**
* Checks if this instance has been destroyed by the associated {@link SzEnvironment}.
*
* @return <code>true</code> if this instance has been destroyed, otherwise <code>false</code>.
*/
protected boolean isDestroyed() {
synchronized (this) {
return (this.nativeApi == null);
}
}
@Override
public String getLicense() throws SzException {
return this.env.execute(
() -> {
return this.nativeApi.license();
});
}
@Override
public String getVersion() throws SzException {
return this.env.execute(
() -> {
return this.nativeApi.version();
});
}
}