Batch Core

I decided to extract the core classes of my last Java batch example and put them in their own project. The project is uploaded to Maven Central. There are two versions of batch-core:

  • version 1.x.x = JBoss Weld 4.x
  • version 2.x.x = JBoss Weld 6.x

So far I mostly used Weld 4 but as I have no conflicting dependencies I wanted to give Weld 6 a try.

1
2
3
4
5
<dependency>
<groupId>com.rpgnextgen</groupId>
<artifactId>batch-core</artifactId>
<version>2.0.0</version>
</dependen

Most simple example

The simplest example is to just implement WorkflowStep and be done.

1
2
3
4
5
6
7
8
9
10
11
12
@ApplicationScoped
@Named("hello")
public class HelloStep implements TypedWorkflowStep<Void> {

@Override
public Void execute(Void parameter) {
System.out.println("Hello World");

return null;
}

}

That’s it! No other classes need. No other files needed (besides those for CDI support).

Note: Don’t forget to setup your project for CDI because your step implementation needs to be a bean.

More icing on the cake

And as the step implementation is a bean I can inject a configuration value directly into the bean without any fuzz.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@ApplicationScoped
@Named("hello")
public class HelloStep implements TypedWorkflowStep<Void> {

@Inject
@ConfigProperty(name = "name", defaultValue = "World")
private String name;

@Override
public Void execute(Void parameter) {
System.out.println("Hello " + name);

return null;
}

}

… or I could inject other beans here. Feel free! :)

Happy batching!

Mihael