Skip to content

Commit 7c53473

Browse files
authored
Provide GraalVM descriptors for temporal-sdk, add docs for users using native-image (temporalio#1660)
1 parent ba838fe commit 7c53473

File tree

25 files changed

+599
-454
lines changed

25 files changed

+599
-454
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ before we can merge in any of your changes
88

99
## Development Environment
1010

11-
* Java 11
12-
* Docker
11+
* Java 11+
12+
* Docker to run Temporal Server
1313

1414
## Build
1515

README.md

+3-15
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ Java SDK:
1111
- [Javadoc API reference](https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/index.html)
1212
- [Sample applications](https://github.com/temporalio/samples-java#samples-directory)
1313

14-
Temporal in general:
14+
Temporal:
1515

1616
- [Temporal docs](https://docs.temporal.io/)
1717
- [Install Temporal Server](https://docs.temporal.io/docs/server/quick-install)
1818
- [Temporal CLI](https://docs.temporal.io/docs/devtools/tctl/)
1919

20-
## Requirements
20+
## Supported Java runtimes
2121

2222
- Java 1.8+
23+
- [GraalVM native-image](docs/AOT-native-image.md)
2324

2425
## Build configuration
2526

@@ -37,19 +38,6 @@ or to *build.gradle*:
3738

3839
compile group: 'io.temporal', name: 'temporal-sdk', version: 'N.N.N'
3940

40-
## macOS Users
41-
42-
Due to issues with default hostname resolution
43-
(see [this StackOverflow question](https://stackoverflow.com/questions/33289695/inetaddress-getlocalhost-slow-to-run-30-seconds) for more details),
44-
macOS Users may see gRPC `DEADLINE_EXCEEDED` errors and other slowdowns when running the SDK.
45-
46-
To solve the problem add the following entries to your `/etc/hosts` file (where my-macbook is your hostname):
47-
48-
```conf
49-
127.0.0.1 my-macbook
50-
::1 my-macbook
51-
```
52-
5341
## Contributing
5442

5543
We'd love your help in improving the Temporal Java SDK. Please review our [contribution guidelines](CONTRIBUTING.md).

build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
33
palantirGitVersionVersion = "${JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11) ? '0.15.0' : '0.13.0'}"
4-
kotlinVersion = "${project.hasProperty("edgeDepsTest") ? '1.8.0' : (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16) ? '1.5.32' : '1.4.32')}"
4+
kotlinVersion = "${project.hasProperty("edgeDepsTest") ? '1.8.10' : (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16) ? '1.5.32' : '1.4.32')}"
55
}
66
}
77

@@ -17,7 +17,7 @@ plugins {
1717
// id 'org.jetbrains.kotlin.jvm' version '1.5.32'
1818
// id 'org.jetbrains.kotlin.jvm' version '1.6.21'
1919
// id 'org.jetbrains.kotlin.jvm' version '1.7.22'
20-
// id 'org.jetbrains.kotlin.jvm' version '1.8.0'
20+
// id 'org.jetbrains.kotlin.jvm' version '1.8.10'
2121
id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" apply false
2222
id 'base'
2323
}
@@ -38,10 +38,10 @@ ext {
3838
// stay on 1.x for a while to don't use any APIs from 2.x which may break our users which still stay on 1.x
3939
// also slf4j 2.x is not compatible with spring boot 2.x
4040
slf4jVersion = project.hasProperty("edgeDepsTest") ? '2.0.6' : '1.7.36' // [1.4.0,)
41-
protoVersion = '3.21.12' // [3.12.0,) 3.12 is brought by min gRPC 1.38
41+
protoVersion = '3.22.0' // [3.12.0,) 3.12 is brought by min gRPC 1.38
4242
annotationApiVersion = '1.3.2'
4343
guavaVersion = '31.1-jre' // [10.0,)
44-
tallyVersion = '0.12.0' // [0.4.0,)
44+
tallyVersion = '0.13.0' // [0.4.0,)
4545

4646
gsonVersion = '2.10.1' // [2.0,)
4747

docs/AOT-native-image.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Ahead Of Time (AOT) compilation
2+
3+
Ahead Of Time compilation build tools such as those provided by [GraalVM's `native-image`](https://www.graalvm.org/reference-manual/native-image/) require some configuration when using Temporal JavaSDK.
4+
Temporal JavaSDK uses Java proxies to provide Workflow and Activity stubs and the target classes of these proxies are application-specific. Proxy classes need to be generated at a build time by the current AOT tools.
5+
Temporal JavaSDK dependencies like gRPC and Protobuf use reflection and some of its target classes are sometimes not possible to determine in advance during the static analysis.
6+
7+
## [native-image](https://www.graalvm.org/reference-manual/native-image/)
8+
9+
Temporal JavaSDK and Test Server support and can be used with GraalVM `native-image`.
10+
11+
Temporal JavaSDK team does its best effort to maintain as complete `native-image` descriptors as technically possible for the following modules:
12+
`temporal-sdk`, `temporal-testing`, `temporal-serviceclient`, `temporal-test-server`.
13+
These modules are distributed with the embedded `native-image` descriptors.
14+
While these descriptors provide enough information for `native-image` to build and run a fully functional Temporal Test Server,
15+
any user building an application with Temporal JavaSDK will require an additional configuration for the reasons mentioned above: user interfaces are used by the JavaSDK for proxy creation, and they need to know in advance for `native-image`.
16+
17+
`native-image` build can be configured with respect to JNI, java proxying, reflection, etc
18+
by providing [JSON configuration descriptors](https://www.graalvm.org/22.3/reference-manual/native-image/metadata/#specifying-metadata-with-json)
19+
which help `native-image` during building of the native execution file.
20+
This can be done manually, but it's labor-intensive and requires good understanding of `native-image` build [process](https://www.graalvm.org/22.3/reference-manual/native-image/basics/) and [configuration](https://www.graalvm.org/22.3/reference-manual/native-image/overview/Build-Overview/).
21+
22+
Instead we recommend users to run their JVM application along with
23+
[the native-image Tracing agent](https://www.graalvm.org/22.3/reference-manual/native-image/metadata/AutomaticMetadataCollection/).
24+
For example, the agent can be run with the full set of integration tests of the app to cover the largest variety of code paths.
25+
This agent will automatically generate additional descriptor files that users should [place and retain with their project's source code](https://www.graalvm.org/22.3/reference-manual/native-image/overview/BuildConfiguration/#embed-a-configuration-file) under `META-INF/native-image`.

temporal-kotlin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
plugins {
4-
id 'org.jlleitschuh.gradle.ktlint' version '11.1.0'
4+
id 'org.jlleitschuh.gradle.ktlint' version '11.2.0'
55
}
66

77
apply plugin: 'org.jetbrains.kotlin.jvm'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3+
#
4+
# Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
#
6+
# Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this material except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
Args = -H:DynamicProxyConfigurationResources=${.}/proxy-config.json \
22+
-H:JNIConfigurationResources=${.}/jni-config.json \
23+
-H:ReflectionConfigurationResources=${.}/reflect-config.json \
24+
-H:ResourceConfigurationResources=${.}/resource-config.json \
25+
-H:SerializationConfigurationResources=${.}/serialization-config.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"name":"[Lcom.fasterxml.jackson.databind.deser.Deserializers;"
4+
},
5+
{
6+
"name":"[Lcom.fasterxml.jackson.databind.deser.KeyDeserializers;"
7+
},
8+
{
9+
"name":"[Lcom.fasterxml.jackson.databind.deser.ValueInstantiators;"
10+
},
11+
{
12+
"name":"[Lcom.fasterxml.jackson.databind.ser.Serializers;"
13+
},
14+
{
15+
"name":"com.fasterxml.jackson.databind.ext.Java7HandlersImpl",
16+
"methods":[{"name":"<init>","parameterTypes":[] }]
17+
},
18+
{
19+
"name":"com.fasterxml.jackson.databind.ext.Java7SupportImpl",
20+
"methods":[{"name":"<init>","parameterTypes":[] }]
21+
},
22+
{
23+
"name":"com.fasterxml.jackson.datatype.jsr310.JavaTimeModule",
24+
"methods":[{"name":"<init>","parameterTypes":[] }]
25+
}
26+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"resources":{
3+
"includes":[
4+
]},
5+
"bundles":[]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"types":[
3+
],
4+
"lambdaCapturingTypes":[
5+
],
6+
"proxies":[
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"name":"java.lang.ClassLoader",
4+
"methods":[
5+
{"name":"getPlatformClassLoader","parameterTypes":[] },
6+
{"name":"loadClass","parameterTypes":["java.lang.String"] }
7+
]
8+
},
9+
{
10+
"name":"jdk.internal.loader.ClassLoaders$PlatformClassLoader"
11+
},
12+
{
13+
"name":"sun.management.VMManagementImpl",
14+
"fields":[
15+
{"name":"compTimeMonitoringSupport"},
16+
{"name":"currentThreadCpuTimeSupport"},
17+
{"name":"objectMonitorUsageSupport"},
18+
{"name":"otherThreadCpuTimeSupport"},
19+
{"name":"remoteDiagnosticCommandsSupport"},
20+
{"name":"synchronizerUsageSupport"},
21+
{"name":"threadAllocatedMemorySupport"},
22+
{"name":"threadContentionMonitoringSupport"}
23+
]
24+
}
25+
]

temporal-testing/src/main/resources/META-INF/native-image/io.temporal/temporal-testing/native-image.properties temporal-serviceclient/src/main/resources/META-INF/native-image/io/temporal/temporal-serviceclient/native-image.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Args = --initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder \
2222
--initialize-at-build-time=org.slf4j.LoggerFactory \
2323
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.channel.epoll \
2424
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.channel.unix \
25+
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory$NopInstanceHolder \
2526
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.util.internal.logging.Log4JLogger \
2627
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.internal.tcnative \
2728
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.handler.ssl \
2829
-H:DynamicProxyConfigurationResources=${.}/proxy-config.json \
2930
-H:JNIConfigurationResources=${.}/jni-config.json \
3031
-H:ReflectionConfigurationResources=${.}/reflect-config.json \
3132
-H:ResourceConfigurationResources=${.}/resource-config.json \
32-
-H:SerializationConfigurationResources=${.}/serialization-config.json
33-
33+
-H:SerializationConfigurationResources=${.}/serialization-config.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"interfaces":["io.temporal.client.WorkflowClient"]
4+
}
5+
]

0 commit comments

Comments
 (0)