Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vsilaev authored Sep 9, 2022
1 parent 3d2d343 commit dd94bda
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,47 @@ The project is based on the completely reworked Apache Jakarta-Commons JavaFlow

You have to add the following configuration to enable build-time instrumentation of classes during Maven build:
```xml
<dependencies>
<dependency>
<dependencies>
<dependency>
<groupId>net.tascalate.javaflow</groupId>
<artifactId>net.tascalate.javaflow.api</artifactId>
<version>2.7.3</version>
</dependency>
<!-- Add-on for Java 8 and above -->
<dependency>
<groupId>net.tascalate.javaflow</groupId>
<artifactId>net.tascalate.javaflow.extras</artifactId>
<version>2.4.2</version>
</dependency>
...
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- versions 1.6 -- 17 are supported -->
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>net.tascalate.javaflow</groupId>
<artifactId>net.tascalate.javaflow.api</artifactId>
<artifactId>net.tascalate.javaflow.tools.maven</artifactId>
<version>2.7.3</version>
</dependency>
<!-- Add-on for Java 8 and above -->
<dependency>
<groupId>net.tascalate.javaflow</groupId>
<artifactId>net.tascalate.javaflow.extras</artifactId>
<version>2.4.2</version>
</dependency>
...
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- versions 1.6 -- 17 are supported -->
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>net.tascalate.javaflow</groupId>
<artifactId>net.tascalate.javaflow.tools.maven</artifactId>
<version>2.7.3</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>javaflow-enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>javaflow-enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
Note that if you are using continuations with Java 1.8 lambdas then you need to add [Tascalate JavaFlow instrumentation agent](https://github.com/vsilaev/tascalate-javaflow/releases/download/2.7.3/javaflow.instrument-continuations.jar) at run-time as command-line option, while lambda-related classes are generated by JVM on the fly and there is no other way to instrument them. If this is not an option, then you can de-sugar all lambdas with [RetroLambda](https://github.com/luontola/retrolambda) Maven plugin at build-time (RetroLambda output is supported by Tascalate JavaFlow 2.3.2 or higher).

Expand All @@ -82,28 +82,28 @@ There is a separate Ant task for applying JavaFlow instrumentation at build-time

It's possibe to instrument compiled Java classes as below:
```xml
<target name="instrument-classes" description="JavaFlow Instrumentation" depends="compile">
<taskdef name="javaflow" classname="org.apache.commons.javaflow.tools.ant.ContinuableClassesInstrumentationTask"
classpathref="ant-lib-classpath"/>
<echo message="JavaFlow instrumentation of compiled classes in ${classes.dir}" />
<javaflow srcdir="${classes.dir}" destdir="${i-classes.dir}" classpathref="classpath"/>
</target>
<target name="instrument-classes" description="JavaFlow Instrumentation" depends="compile">
<taskdef name="javaflow" classname="org.apache.commons.javaflow.tools.ant.ContinuableClassesInstrumentationTask"
classpathref="ant-lib-classpath"/>
<echo message="JavaFlow instrumentation of compiled classes in ${classes.dir}" />
<javaflow srcdir="${classes.dir}" destdir="${i-classes.dir}" classpathref="classpath"/>
</target>
```
... as well as re-write packaged JAR file:
```xml
<target name="instrument-jar" description="JavaFlow Instrumentation" depends="jar">
<taskdef name="javaflow" classname="org.apache.commons.javaflow.tools.ant.ContinuableClassesInstrumentationTask"
classpathref="ant-lib-classpath"/>
<echo message="JavaFlow instrumentation of compiled classes in ${jar.dir}/${ant.project.name}.jar" />
<javaflow srcdir="${jar.dir}" destdir="${i-jar.dir}" classpathref="classpath"/>
</target>
<target name="instrument-jar" description="JavaFlow Instrumentation" depends="jar">
<taskdef name="javaflow" classname="org.apache.commons.javaflow.tools.ant.ContinuableClassesInstrumentationTask"
classpathref="ant-lib-classpath"/>
<echo message="JavaFlow instrumentation of compiled classes in ${jar.dir}/${ant.project.name}.jar" />
<javaflow srcdir="${jar.dir}" destdir="${i-jar.dir}" classpathref="classpath"/>
</target>
```
You may download a complete [examples project setup](https://github.com/vsilaev/tascalate-javaflow-examples/releases/download/1.0.10/tascalate-javaflow-ant-project-setup1.zip) from [the latest release](https://github.com/vsilaev/tascalate-javaflow-examples/releases/tag/1.0.10) for complete configuration template. Please pay attention to <code>ant-lib</code> folder with Ant TaskDef and <code>lib</code> folders with compile-/runtime-dependencies.

# Java Instrumentation Agent (Runt-time Instrumentation)
As an alternative to compile-time bytecode instrumentation, you MAY use [Tascalate JavaFlow Instrumentation Agent](https://github.com/vsilaev/tascalate-javaflow/releases/download/2.7.3/javaflow.instrument-continuations.jar) from [the latest release](https://github.com/vsilaev/tascalate-javaflow/releases/tag/2.7.3) to enable continuations support at class-loading time. Please note, that if you are using Java 8 and creating continuable lambda functions (either anonymous or/and as method references), and you don't replace them with tools like [RetroLambda](https://github.com/luontola/retrolambda) as mentioned above, then you SHOULD use this instrumentation agent always: as long as Java run-time generates implementation of functional interfaces on the fly there is no other option to instrument them. To enable Tascalate JavaFlow Instrumentation Agent please add the following arguments to Java command line:
```bash
java -javaagent:<path-to-jar>/javaflow.instrument-continuations.jar <rest-of arguments>
java -javaagent:<path-to-jar>/javaflow.instrument-continuations.jar <rest-of arguments>
```
The agent JAR file includes all necessary dependencies and requires no additional CLASSPATH settings. It's recommended to use this agent in conjunction with either Maven or Ant build tools supplied to minimize the associated overhead of the instrumentation during class-loading process at run-time.

Expand All @@ -113,20 +113,20 @@ Another useful application of the instrumentation agent is to apply it for debug
It's possible to use a stand-alone command-line utility [JavaFlowRewriteJar.jar](https://github.com/vsilaev/tascalate-javaflow/releases/download/2.7.3/JavaFlowRewriteJar.jar) to instrument JAR archives containing continuable classes. Please use the following command:

```bash
java -jar JavaFlowRewriteJar.jar src1.jar dst1.jar src2.jar dst2.jar...
java -jar JavaFlowRewriteJar.jar src1.jar dst1.jar src2.jar dst2.jar...
```
Note, that the source and the destination should be different files.

# CDI Support
To work correctly in CDI environment continuable methods should be advised only by continuation-aware CDI proxies (interceptors, scope proxies, etc). Obviously, generation of these proxies is out of our control. Plus, major CDI containers (JBoss Weld and Apache OpenWebBeans) generates such proxies dynamically at run-time. Therefore if you plan to use Tascalate JavaFlow continuations with managed beans' methods then it's necessary to instrument CDI-specific proxies with [javaflow.instrument-proxies.jar](https://github.com/vsilaev/tascalate-javaflow/releases/download/2.7.3/javaflow.instrument-proxies.jar) Java Agent:
```bash
java -javaagent:<path-to-jar>/javaflow.instrument-proxies.jar <rest-of arguments>
java -javaagent:<path-to-jar>/javaflow.instrument-proxies.jar <rest-of arguments>
```
Please note, that CDI-specific agent neither requires javaflow.instrument-continuations.jar to operate correctly nor provides class file transformers for continuable methods. So if your project runs with CDI environment AND uses Java 8 lambdas then you have to add 2 Java agents, every serving different purpose:
```bash
java -javaagent:<path-to-jar>/javaflow.instrument-continuations.jar \
-javaagent:<path-to-jar>/javaflow.instrument-proxies.jar \
<rest-of arguments>
java -javaagent:<path-to-jar>/javaflow.instrument-continuations.jar \
-javaagent:<path-to-jar>/javaflow.instrument-proxies.jar \
<rest-of arguments>
```
CDI functionality is tested with JBoss Weld 2.x - 3.1.7, 4.0.x and Apache OpenWebBeans 1.6.x - 2.0.23. Contribution for other CDI/CDI-like containers (Spring, Google Guice, etc) is welcome.

Expand Down

0 comments on commit dd94bda

Please sign in to comment.