This repository was archived by the owner on Jan 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathbatch-processing004.html
More file actions
854 lines (840 loc) · 32.7 KB
/
batch-processing004.html
File metadata and controls
854 lines (840 loc) · 32.7 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Using the Job Specification Language</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet">
<script src="https://use.fontawesome.com/96c4d89611.js"></script>
</head>
<body>
<table id="doc-title" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<b>Java Platform, Enterprise Edition (Java EE) 8</b><br />
<b>The Java EE Tutorial</b>
<!-- <p class="beta">Beta Draft (Pre-General Availability)</p> -->
</td>
</tr>
</table>
<hr />
<table width="90%" id="top-nav" cellspacing="0" cellpadding="0">
<colgroup>
<col width="12%"/>
<col width="12%"/>
<col width="*"/>
</colgroup>
<tr>
<td align="left">
<a href="batch-processing003.html">
<span class="vector-font"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Previous</span>
</a>
</td>
<td align="left">
<a href="batch-processing005.html">
<span class=" vector-font"><i class="fa fa-arrow-circle-right vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Next</span>
</a>
</td>
<td align="right">
<a href="toc.html">
<span class=" vector-font"><i class="fa fa-list vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Contents</span>
</a>
</td>
</tr>
</table>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><a id="BCGDDBBG"></a><a id="using-the-job-specification-language"></a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_using_the_job_specification_language">Using the Job Specification Language</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Job Specification Language (JSL) enables you to define the steps in
a job and their execution order using an XML file. The following example
shows how to define a simple job that contains one chunk step and one
task step:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><job id="loganalysis" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
version="1.0">
<properties>
<property name="input_file" value="input1.txt"/>
<property name="output_file" value="output2.txt"/>
</properties>
<step id="logprocessor" next="cleanup">
<chunk checkpoint-policy="item" item-count="10">
<reader ref="com.example.pkg.LogItemReader"></reader>
<processor ref="com.example.pkg.LogItemProcessor"></processor>
<writer ref="com.example.pkg.LogItemWriter"></writer>
</chunk>
</step>
<step id="cleanup">
<batchlet ref="com.example.pkg.CleanUp"></batchlet>
<end on="COMPLETED"/>
</step>
</job></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example defines the <code>loganalysis</code> batch job, which consists of the
<code>logprocessor</code> chunk step and the <code>cleanup</code> task step. The
<code>logprocessor</code> step transitions to the <code>cleanup</code> step, which terminates
the job when completed.</p>
</div>
<div class="paragraph">
<p>The <code>job</code> element defines two properties, <code>input_file</code> and
<code>output_file</code>. Specifying properties in this manner enables you to run a
batch job with different configuration parameters without having to
recompile its Java batch artifacts. The batch artifacts can access these
properties using the context objects from the batch runtime.</p>
</div>
<div class="paragraph">
<p>The <code>logprocessor</code> step is a chunk step that specifies batch artifacts
for the reader (<code>LogItemReader</code>), the processor (<code>LogItemProcessor</code>),
and the writer (<code>LogItemWriter</code>). This step creates a checkpoint for
every ten items processed.</p>
</div>
<div class="paragraph">
<p>The <code>cleanup</code> step is a task step that specifies the <code>CleanUp</code> class as
its batch artifact. The job terminates when this step completes.</p>
</div>
<div class="paragraph">
<p>The following sections describe the elements of the Job Specification
Language (JSL) in more detail and show the most common attributes and
child elements.</p>
</div>
<div class="paragraph">
<p><a id="sthref270"></a><a id="the-job-element"></a></p>
</div>
<div class="sect2">
<h3 id="_the_job_element">The job Element</h3>
<div class="paragraph">
<p>The <code>job</code> element is always the top-level element in a job definition
file. Its main attributes are <code>id</code> and <code>restartable</code>. The <code>job</code> element
can contain one <code>properties</code> element and zero or more of each of the
following elements: <code>listener</code>, <code>step</code>, <code>flow</code>, and <code>split</code>. For
example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><job id="jobname" restartable="true">
<listeners>
<listener ref="com.example.pkg.ListenerBatchArtifact"/>
</listeners>
<properties>
<property name="propertyName1" value="propertyValue1"/>
<property name="propertyName2" value="propertyValue2"/>
</properties>
<step ...> ... </step>
<step ...> ... </step>
<decision ...> ... </decision>
<flow ...> ... </flow>
<split ...> ... </split>
</job></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>listener</code> element specifies a batch artifact whose methods are
invoked before and after the execution of the job. The batch artifact is
an implementation of the <code>javax.batch.api.listener.JobListener</code>
interface. See <a href="batch-processing008.html#BCGCCFAC">The Listener Batch
Artifacts</a> for an example of a job listener implementation.</p>
</div>
<div class="paragraph">
<p>The first <code>step</code>, <code>flow</code>, or <code>split</code> element inside the <code>job</code> element
executes first.</p>
</div>
<div class="paragraph">
<p><a id="sthref271"></a><a id="the-step-element"></a></p>
</div>
</div>
<div class="sect2">
<h3 id="_the_step_element">The step Element</h3>
<div class="paragraph">
<p>The <code>step</code> element can be a child of the <code>job</code> and <code>flow</code> elements. Its
main attributes are <code>id</code> and <code>next</code>. The <code>step</code> element can contain the
following elements.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>One <code>chunk</code> element for chunk-oriented steps or one <code>batchlet</code> element
for task-oriented steps.</p>
</li>
<li>
<p>One <code>properties</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a set of properties that batch artifacts can
access using batch context objects.</p>
</div>
</li>
<li>
<p>One <code>listener</code> element (optional); one <code>listeners</code> element if more
than one listener is specified.</p>
<div class="paragraph">
<p>This element specifies listener artifacts that intercept various phases
of step execution.</p>
</div>
<div class="paragraph">
<p>For chunk steps, the batch artifacts for these listeners can be
implementations of the following interfaces: <code>StepListener</code>,
<code>ItemReadListener</code>, <code>ItemProcessListener</code>, <code>ItemWriteListener</code>,
<code>ChunkListener</code>, <code>RetryReadListener</code>, <code>RetryProcessListener</code>,
<code>RetryWriteListener</code>, <code>SkipReadListener</code>, <code>SkipProcessListener</code>, and
<code>SkipWriteListener</code>.</p>
</div>
<div class="paragraph">
<p>For task steps, the batch artifact for these listeners must be an
implementation of the <code>StepListener</code> interface.</p>
</div>
<div class="paragraph">
<p>See <a href="batch-processing008.html#BCGCCFAC">The Listener Batch Artifacts</a>
for an example of an item processor listener implementation.</p>
</div>
</li>
<li>
<p>One <code>partition</code> element (optional).</p>
<div class="paragraph">
<p>This element is used in partitioned steps which execute in more than one
thread.</p>
</div>
</li>
<li>
<p>One <code>end</code> element if this is the last step in a job.</p>
<div class="paragraph">
<p>This element sets the batch status to <code>COMPLETED</code>.</p>
</div>
</li>
<li>
<p>One <code>stop</code> element (optional) to stop a job at this step.</p>
<div class="paragraph">
<p>This element sets the batch status to <code>STOPPED</code>.</p>
</div>
</li>
<li>
<p>One <code>fail</code> element (optional) to terminate a job at this step.</p>
<div class="paragraph">
<p>This element sets the batch status to <code>FAILED</code>.</p>
</div>
</li>
<li>
<p>One or more <code>next</code> elements if the <code>next</code> attribute is not specified.</p>
<div class="paragraph">
<p>This element is associated with an exit status and refers to another
step, a flow, a split, or a decision element.</p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>The following is an example of a chunk step:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepA" next="stepB">
<properties> ... </properties>
<listeners>
<listener ref="MyItemReadListenerImpl"/>
...
</listeners>
<chunk ...> ... </chunk>
<partition> ... </partition>
<end on="COMPLETED" exit-status="MY_COMPLETED_EXIT_STATUS"/>
<stop on="MY_TEMP_ISSUE_EXIST_STATUS" restart="step0"/>
<fail on="MY_ERROR_EXIT_STATUS" exit-status="MY_ERROR_EXIT_STATUS"/>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>The following is an example of a task step:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepB" next="stepC">
<batchlet ...> ... </batchlet>
<properties> ... </properties>
<listener ref="MyStepListenerImpl"/>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p><a id="sthref272"></a><a id="the-chunk-element"></a></p>
</div>
<div class="sect3">
<h4 id="_the_chunk_element">The chunk Element</h4>
<div class="paragraph">
<p>The <code>chunk</code> element is a child of the <code>step</code> element for chunk-oriented
steps. The attributes of this element are listed in <a href="#BCGJCIEI">Table
58-2</a>.</p>
</div>
<div class="paragraph">
<p><a id="sthref273"></a><a id="BCGJCIEI"></a></p>
</div>
<div class="paragraph">
<p><strong>Table 58-2 Attributes of the chunk Element</strong></p>
</div>
<table class="tableblock frame-all grid-all" style="width: 99%;">
<colgroup>
<col style="width: 15%;">
<col style="width: 75%;">
<col style="width: 10%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Attribute Name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Description</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Default Value</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>checkpoint-policy</code></p></td>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
<p>Specifies how to commit the results of processing each chunk:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>"item"</code>: the chunk is committed after processing <code>item-count</code> items</p>
</li>
<li>
<p><code>"custom"</code>: the chunk is committed according to a checkpoint algorithm
specified with the <code>checkpoint-algorithm</code> element</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The checkpoint is updated when the results of a chunk are committed.</p>
</div>
<div class="paragraph">
<p>Every chunk is processed in a global Java EE transaction. If the
processing of one item in the chunk fails, the transaction is rolled
back and no processed items from this chunk are stored.</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>"item"</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>item-count</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Specifies the number of items to process before
committing the chunk and taking a checkpoint.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">10</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>time-limit</code></p></td>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
<p>Specifies the number of seconds before committing the chunk and taking a
checkpoint when <code>checkpoint-policy="item"</code>.</p>
</div>
<div class="paragraph">
<p>If <code>item-count</code> items have not been processed by <code>time-limit</code> seconds,
the chunk is committed and a checkpoint is taken.</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0 (no limit)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>buffer-items</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Specifies if processed items are buffered until it is
time to take a checkpoint. If true, a single call to the item writer is
made with a list of the buffered items before committing the chunk and
taking a checkpoint.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>skip-limit</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Specifies the number of skippable exceptions to skip in
this step during chunk processing. Skippable exception classes are
specified with the <code>skippable-exception-classes</code> element.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No limit</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>retry-limit</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Specifies the number of attempts to execute this step if
retryable exceptions occur. Retryable exception classes are specified
with the <code>retryable-exception-classes</code> element.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No limit</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>The <code>chunk</code> element can contain the following elements.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>One <code>reader</code> element.</p>
<div class="paragraph">
<p>This element specifies a batch artifact that implements the <code>ItemReader</code>
interface.</p>
</div>
</li>
<li>
<p>One <code>processor</code> element.</p>
<div class="paragraph">
<p>This element specifies a batch artifact that implements the
<code>ItemProcessor</code> interface.</p>
</div>
</li>
<li>
<p>One <code>writer</code> element.</p>
<div class="paragraph">
<p>This element specifies a batch artifact that implements the <code>ItemWriter</code>
interface.</p>
</div>
</li>
<li>
<p>One <code>checkpoint-algorithm</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a batch artifact that implements the
<code>CheckpointAlgorithm</code> interface and provides a custom checkpoint policy.</p>
</div>
</li>
<li>
<p>One <code>skippable-exception-classes</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a set of exceptions thrown from the reader,
writer, and processor batch artifacts that chunk processing should skip.
The <code>skip-limit</code> attribute from the <code>chunk</code> element specifies the
maximum number of skipped exceptions.</p>
</div>
</li>
<li>
<p>One <code>retryable-exception-classes</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a set of exceptions thrown from the reader,
writer, and processor batch artifacts that chunk processing will retry.
The <code>retry-limit</code> attribute from the <code>chunk</code> element specifies the
maximum number of attempts.</p>
</div>
</li>
<li>
<p>One <code>no-rollback-exception-classes</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a set of exceptions thrown from the reader,
writer, and processor batch artifacts that should not cause the batch
runtime to roll back the current chunk, but to retry the current
operation without a rollback instead.</p>
</div>
<div class="paragraph">
<p>For exception types not specified in this element, the current chunk is
rolled back by default when an exception occurs.</p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>The following is an example of a chunk-oriented step:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepC" next="stepD">
<chunk checkpoint-policy="item" item-count="5" time-limit="180"
buffer-items="true" skip-limit="10" retry-limit="3">
<reader ref="pkg.MyItemReaderImpl"></reader>
<processor ref="pkg.MyItemProcessorImpl"></processor>
<writer ref="pkg.MyItemWriterImpl"></writer>
<skippable-exception-classes>
<include class="pkg.MyItemException"/>
<exclude class="pkg.MyItemSeriousSubException"/>
</skippable-exception-classes>
<retryable-exception-classes>
<include class="pkg.MyResourceTempUnavailable"/>
</retryable-exception-classes>
</chunk>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example defines a chunk step and specifies its reader, processor,
and writer artifacts. The step updates a checkpoint and commits each
chunk after processing five items. It skips all <code>MyItemException</code>
exceptions and all its subtypes, except for <code>MyItemSeriousSubException</code>,
up to a maximum of ten skipped exceptions. The step retries a chunk when
a <code>MyResourceTempUnavailable</code> exception occurs, up to a maximum of three
attempts.</p>
</div>
<div class="paragraph">
<p><a id="sthref274"></a><a id="the-batchlet-element"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_batchlet_element">The batchlet Element</h4>
<div class="paragraph">
<p>The <code>batchlet</code> element is a child of the <code>step</code> element for
task-oriented steps. This element only has the <code>ref</code> attribute, which
specifies a batch artifact that implements the <code>Batchlet</code> interface. The
<code>batch</code> element can contain a <code>properties</code> element.</p>
</div>
<div class="paragraph">
<p>The following is an example of a task-oriented step:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepD" next="stepE">
<batchlet ref="pkg.MyBatchletImpl">
<properties>
<property name="pname" value="pvalue"/>
</properties>
</batchlet>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example defines a batch step and specifies its batch artifact.</p>
</div>
<div class="paragraph">
<p><a id="sthref275"></a><a id="the-partition-element"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_partition_element">The partition Element</h4>
<div class="paragraph">
<p>The <code>partition</code> element is a child of the <code>step</code> element. It indicates
that a step is partitioned. Most partitioned steps are chunk steps where
the processing of each item does not depend on the results of processing
previous items. You specify the number of partitions in a step and
provide each partition with specific information on which items to
process, such as the following.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A range of items. For example, partition 1 processes items 1 through
500, and partition 2 processes items 501 through 1000.</p>
</li>
<li>
<p>An input source. For example, partition 1 processes the items in
<code>input1.txt</code> and partition 2 processes the items in <code>input2.txt</code>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>When the number of partitions, the number of items, and the input
sources for a partitioned step are known at development or deployment
time, you can use partition properties in the job definition file to
specify partition-specific information and access these properties from
the step batch artifacts. The runtime creates as many instances of the
step batch artifacts (reader, processor, and writer) as partitions, and
each artifact instance receives the properties specific to its
partition.</p>
</div>
<div class="paragraph">
<p>In most cases, the number of partitions, the number of items, or the
input sources for a partitioned step can only be determined at runtime.
Instead of specifying partition-specific properties statically in the
job definition file, you provide a batch artifact that can access your
data sources at runtime and determine how many partitions are needed and
what range of items each partition should process. This batch artifact
is an implementation of the <code>PartitionMapper</code> interface. The batch
runtime invokes this artifact and then uses the information it provides
to instantiate the step batch artifacts (reader, writer, and processor)
for each partition and to pass them partition-specific data as
parameters.</p>
</div>
<div class="paragraph">
<p>The rest of this section describes the <code>partition</code> element in detail and
shows two examples of job definition files: one that uses partition
properties to specify a range of items for each partition, and one that
relies on a <code>PartitionMapper</code> implementation to determine
partition-specific information.</p>
</div>
<div class="paragraph">
<p>See <a href="batch-processing009.html#BCGGGAHB">The Phone Billing Chunk Step</a>
in <a href="batch-processing009.html#BCGFCACD">The phonebilling Example
Application</a> for a complete example of a partitioned chunk step.</p>
</div>
<div class="paragraph">
<p>The <code>partition</code> element can contain the following elements.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>One <code>plan</code> element, if the <code>mapper</code> element is not specified.</p>
<div class="paragraph">
<p>This element defines the number of partitions, the number of threads,
and the properties for each partition in the job definition file. The
<code>plan</code> element is useful when this information is known at development
or deployment time.</p>
</div>
</li>
<li>
<p>One <code>mapper</code> element, if the <code>plan</code> element is not specified.</p>
<div class="paragraph">
<p>This element specifies a batch artifact that provides the number of
partitions, the number of threads, and the properties for each
partition. The batch artifact is an implementation of the
<code>PartitionMapper</code> interface. You use this option when the information
required for each partition is only known at runtime.</p>
</div>
</li>
<li>
<p>One <code>reducer</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a batch artifact that receives control when a
partitioned step begins, ends, or rolls back. The batch artifact enables
you to merge results from different partitions and perform other related
operations. The batch artifact is an implementation of the
<code>PartitionReducer</code> interface.</p>
</div>
</li>
<li>
<p>One <code>collector</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a batch artifact that sends intermediary results
from each partition to a partition analyzer. The batch artifact sends
the intermediary results after each checkpoint for chunk steps and at
the end of the step for task steps. The batch artifact is an
implementation of the <code>PartitionCollector</code> interface.</p>
</div>
</li>
<li>
<p>One <code>analyzer</code> element (optional).</p>
<div class="paragraph">
<p>This element specifies a batch artifact that analyzes the intermediary
results from the partition collector instances. The batch artifact is an
implementation of the <code>PartitionAnalyzer</code> interface.</p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>The following is an example of a partitioned step using the <code>plan</code>
element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepE" next="stepF">
<chunk>
<reader ...></reader>
<processor ...></processor>
<writer ...></writer>
</chunk>
<partition>
<plan partitions="2" threads="2">
<properties partition="0">
<property name="firstItem" value="0"/>
<property name="lastItem" value="500"/>
</properties>
<properties partition="1">
<property name="firstItem" value="501"/>
<property name="lastItem" value="999"/>
</properties>
</plan>
</partition>
<reducer ref="MyPartitionReducerImpl"/>
<collector ref="MyPartitionCollectorImpl"/>
<analyzer ref="MyPartitionAnalyzerImpl"/>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example, the <code>plan</code> element specifies the properties for each
partition in the job definition file.</p>
</div>
<div class="paragraph">
<p>The following example uses a <code>mapper</code> element instead of a <code>plan</code>
element. The <code>PartitionMapper</code> implementation dynamically provides the
same information as the <code>plan</code> element provides in the job definition
file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepE" next="stepF">
<chunk>
<reader ...></reader>
<processor ...></processor>
<writer ...></writer>
</chunk>
<partition>
<mapper ref="MyPartitionMapperImpl"/>
<reducer ref="MyPartitionReducerImpl"/>
<collector ref="MyPartitionCollectorImpl"/>
<analyzer ref="MyPartitionAnalyzerImpl"/>
</partition>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>Refer to <a href="batch-processing009.html#BCGFCACD">The phonebilling Example
Application</a> for an example implementation of the <code>PartitionMapper</code>
interface.</p>
</div>
<div class="paragraph">
<p><a id="sthref276"></a><a id="the-flow-element"></a></p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_the_flow_element">The flow Element</h3>
<div class="paragraph">
<p>The <code>flow</code> element can be a child of the <code>job</code>, <code>flow</code>, and <code>split</code>
elements. Its attributes are <code>id</code> and <code>next</code>. Flows can transition to
flows, steps, splits, and decision elements. The <code>flow</code> element can
contain the following elements:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>One or more <code>step</code> elements</p>
</li>
<li>
<p>One or more <code>flow</code> elements (optional)</p>
</li>
<li>
<p>One or more <code>split</code> elements (optional)</p>
</li>
<li>
<p>One or more <code>decision</code> elements (optional)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The last <code>step</code> in a flow is the one with no <code>next</code> attribute or <code>next</code>
element. Steps and other elements in a flow cannot transition to
elements outside the flow.</p>
</div>
<div class="paragraph">
<p>The following is an example of the <code>flow</code> element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><flow id="flowA" next="stepE">
<step id="flowAstepA" next="flowAstepB">...</step>
<step id="flowAstepB" next="flowAflowC">...</step>
<flow id="flowAflowC" next="flowAsplitD">...</flow>
<split id="flowAsplitD" next="flowAstepE">...</split>
<step id="flowAstepE">...</step>
</flow></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example flow contains three steps, one flow, and one split. The
last step does not have the <code>next</code> attribute. The flow transitions to
<code>stepE</code> when its last step completes.</p>
</div>
<div class="paragraph">
<p><a id="sthref277"></a><a id="the-split-element"></a></p>
</div>
</div>
<div class="sect2">
<h3 id="_the_split_element">The split Element</h3>
<div class="paragraph">
<p>The <code>split</code> element can be a child of the <code>job</code> and <code>flow</code> elements. Its
attributes are <code>id</code> and <code>next</code>. Splits can transition to splits, steps,
flows, and decision elements. The <code>split</code> element can only contain one
or more <code>flow</code> elements that can only transition to other <code>flow</code>
elements in the split.</p>
</div>
<div class="paragraph">
<p>The following is an example of a split with three flows that execute
concurrently:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><split id="splitA" next="stepB">
<flow id="splitAflowA">...</flow>
<flow id="splitAflowB">...</flow>
<flow id="splitAflowC">...</flow>
</split></code></pre>
</div>
</div>
<div class="paragraph">
<p><a id="sthref278"></a><a id="the-decision-element"></a></p>
</div>
</div>
<div class="sect2">
<h3 id="_the_decision_element">The decision Element</h3>
<div class="paragraph">
<p>The <code>decision</code> element can be a child of the <code>job</code> and <code>flow</code> elements.
Its attributes are <code>id</code> and <code>next</code>. Steps, flows, and splits can
transition to a <code>decision</code> element. This element specifies a batch
artifact that decides the next step, flow, or split to execute based on
information from the execution of the previous step, flow, or split. The
batch artifact implements the <code>Decider</code> interface. The <code>decision</code>
element can contain the following elements.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>One or more <code>end</code> elements (optional).</p>
<div class="paragraph">
<p>This element sets the batch status to <code>COMPLETED</code>.</p>
</div>
</li>
<li>
<p>One or more <code>stop</code> elements (optional).</p>
<div class="paragraph">
<p>This element sets the batch status to <code>STOPPED</code>.</p>
</div>
</li>
<li>
<p>One or more <code>fail</code> elements (optional).</p>
<div class="paragraph">
<p>This element sets the batch status to <code>FAILED</code>.</p>
</div>
</li>
<li>
<p>One or more <code>next</code> elements (optional).</p>
</li>
<li>
<p>One <code>properties</code> element (optional).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The following is an example of the <code>decider</code> element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><decision id="decisionA" ref="MyDeciderImpl">
<fail on="FAILED" exit-status="FAILED_AT_DECIDER"/>
<end on="COMPLETED" exit-status="COMPLETED_AT_DECIDER"/>
<stop on="MY_TEMP_ISSUE_EXIST_STATUS" restart="step2"/>
</decision></code></pre>
</div>
</div>
</div>
</div>
</div>
<hr />
<table width="90%" id="bottom-nav" cellspacing="0" cellpadding="0">
<colgroup>
<col width="12%"/>
<col width="12%"/>
<col width="*"/>
</colgroup>
<tr>
<td align="left">
<a href="batch-processing003.html">
<span class=" vector-font"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Previous</span>
</a>
</td>
<td align="left">
<a href="batch-processing005.html">
<span class="vector-font"><i class="fa fa-arrow-circle-right vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Next</span>
</a>
</td>
<td align="right">
<a href="toc.html">
<span class="vector-font"><i class="fa fa-list vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Contents</span>
</a>
</td>
</tr>
</table>
<span id="copyright">
<a href="img/cpyr.adoc">
<img src="img/oracle.gif" height="10px" alt="Oracle Logo" />
<span>Copyright © 2017, Oracle and/or its affiliates. All rights reserved.</span>
</a>
</span>
<!--<p align="center" class="beta">Beta Draft (Pre-General Availability)</p> -->
</body>
</html>