Kohei Nozaki's blog 

Job-wide artifact injection with CDI Producer


Posted on Tuesday Feb 25, 2014 at 05:37PM in Technology


Environment

  • jBeret 1.0.1Beta-SNAPSHOT
  • WildFly 8.0.0.Final

Why need it?

  • Logger injection through CDI is easy and useful, but for jBatch programming of some occasions, I guess that Job-wide Logger is better than typical class-wide logger. thus, I will try it this time.
  • With CDI, we can reduce some annoying code, even related to Job Properties so I also will try to inject a job-level property to a Batchlet through Producer.

Sample project

How does it work?

  • 2 Injections are declared in InjectBatchlet.
  • Both of them will be produced by JobWideArtifactProducer.
  • JobWideArtifactProducer creates:
    • a logger. the name contains job name.
    • a Date. it came from job-level property named “baseDate”.

Log

18:14:51,064 INFO  [job.jobwideproducer] (batch-batch - 3) process(): baseDate=14/02/25 0:00

Remarks

  • Injection of variables such as working directory of the job may be useful too.

References

  1. [Java] CDI - Slf4j Logger Producer
  2. SimpleDateFormat (Java Platform SE 6)



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed