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-processing009.html
More file actions
759 lines (731 loc) · 27.7 KB
/
batch-processing009.html
File metadata and controls
759 lines (731 loc) · 27.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>The phonebilling Example Application</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-processing008.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-processing010.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="BCGFCACD"></a><a id="the-phonebilling-example-application"></a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_the_phonebilling_example_application">The phonebilling Example Application</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <code>phonebilling</code> example application, located in the
tut-install`/examples/batch/phonebilling/` directory, demonstrates how
to use the batch framework in Java EE to implement a phone billing
system. This example application processes a log file of phone calls and
creates a bill for each customer.</p>
</div>
<div class="paragraph">
<p>The following topics are addressed here:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#BABDEIFG">Architecture of the phonebilling Example Application</a></p>
</li>
<li>
<p><a href="#BABBGDAA">Running the phonebilling Example Application</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p><a id="BABDEIFG"></a><a id="architecture-of-the-phonebilling-example-application"></a></p>
</div>
<div class="sect2">
<h3 id="_architecture_of_the_phonebilling_example_application">Architecture of the phonebilling Example Application</h3>
<div class="paragraph">
<p>The <code>phonebilling</code> example application consists of the following
elements.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A job definition file (<code>phonebilling.xml</code>) that uses the Job
Specification Language (JSL) to define a batch job with two chunk steps.
The first step reads call records from a log file and associates them
with a bill. The second step computes the amount due and writes each
bill to a text file.</p>
</li>
<li>
<p>A Java class (<code>CallRecordLogCreator</code>) that creates the log file for
the batch job. This is an auxiliary component that does not demonstrate
any key functionality in this example.</p>
</li>
<li>
<p>Two Java Persistence API (JPA) entities (<code>CallRecord</code> and <code>PhoneBill</code>)
that represent call records and customer bills. The application uses a
JPA entity manager to store instances of these entities in a database.</p>
</li>
<li>
<p>Three batch artifacts (<code>CallRecordReader</code>, <code>CallRecordProcessor</code>, and
<code>CallRecordWriter</code>) that implement the first step of the application.
This step reads call records from the log file, associates them with a
bill, and stores them in a database.</p>
</li>
<li>
<p>Four batch artifacts (<code>BillReader</code>, <code>BillProcessor</code>, <code>BillWriter</code>, and
<code>BillPartitionMapper</code>) that implement the second step of the
application. This step is a partitioned step that gets each bill from
the database, calculates the amount due, and writes it to a text file.</p>
</li>
<li>
<p>Two Facelets pages (<code>index.xhtml</code> and <code>jobstarted.xhtml</code>) that provide
the front end of the batch application. The first page shows the log
file that will be processed by the batch job, and the second page
enables the user to check on the status of the job and shows the
resulting bill for each customer.</p>
</li>
<li>
<p>A managed bean (<code>JsfBean</code>) that is accessed from the Facelets pages.
The bean submits the job to the batch runtime, checks on the status of
the job, and reads the text files for each bill.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p><a id="sthref288"></a><a id="the-job-definition-file"></a></p>
</div>
<div class="sect3">
<h4 id="_the_job_definition_file">The Job Definition File</h4>
<div class="paragraph">
<p>The <code>phonebilling.xml</code> job definition file is located in the
<code>WEB-INF/classes/META-INF/batch-jobs/</code> directory. The file specifies
three job-level properties and two steps:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><?xml version="1.0" encoding="UTF-8"?>
<job id="phonebilling" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
version="1.0">
<properties>
<property name="log_file_name" value="log1.txt"/>
<property name="airtime_price" value="0.08"/>
<property name="tax_rate" value="0.07"/>
</properties>
<step id="callrecords" next="bills"> ... </step>
<step id="bills"> ... </step>
</job></code></pre>
</div>
</div>
<div class="paragraph">
<p>The first step is defined as follows:</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="callrecords" next="bills">
<chunk checkpoint-policy="item" item-count="10">
<reader ref="CallRecordReader"></reader>
<processor ref="CallRecordProcessor"></processor>
<writer ref="CallRecordWriter"></writer>
</chunk>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>This step is a normal chunk step that specifies the batch artifacts that
implement each phase of the step. The batch artifact names are not fully
qualified class names, so the batch artifacts are CDI beans annotated
with <code>@Named</code>.</p>
</div>
<div class="paragraph">
<p>The second step is defined as follows:</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="bills">
<chunk checkpoint-policy="item" item-count="2">
<reader ref="BillReader">
<properties> <property name="firstItem" value="#{partitionPlan['firstItem']}"/> <property name="numItems" value="#{partitionPlan['numItems']}"/> </properties> </reader>
<processor ref="BillProcessor"></processor>
<writer ref="BillWriter"></writer>
</chunk>
<partition>
<mapper ref="BillPartitionMapper"/>
</partition>
<end on="COMPLETED"/>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>This step is a partitioned chunk step. The partition plan is specified
through the <code>BillPartitionMapper</code> artifact instead of using the <code>plan</code>
element.</p>
</div>
<div class="paragraph">
<p><a id="sthref289"></a><a id="the-callrecord-and-phonebill-entities"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_callrecord_and_phonebill_entities">The CallRecord and PhoneBill Entities</h4>
<div class="paragraph">
<p>The <code>CallRecord</code> entity is defined as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Entity
public class CallRecord implements Serializable {
@Id @GeneratedValue
private Long id;
@Temporal(TemporalType.DATE)
private Date datetime;
private String fromNumber;
private String toNumber;
private int minutes;
private int seconds;
private BigDecimal price;
public CallRecord() { }
public CallRecord(String datetime, String from,
String to, int min, int sec) throws ParseException { ... }
public CallRecord(String jsonData) throws ParseException { ... }
/* ... Getters and setters ... */
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>id</code> field is generated automatically by the JPA implementation to
store and retrieve <code>CallRecord</code> objects to and from a database.</p>
</div>
<div class="paragraph">
<p>The second constructor creates a <code>CallRecord</code> object from an entry of
JSON data in the log file using the JSON Processing API. Log entries
look as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">{"datetime":"03/01/2013 04:03","from":"555-0101",
"to":"555-0114","length":"03:39"}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>PhoneBill</code> entity is defined as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Entity
public class PhoneBill implements Serializable {
@Id
private String phoneNumber;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
@OrderBy("datetime ASC")
private List<CallRecord> calls;
private BigDecimal amountBase;
private BigDecimal taxRate;
private BigDecimal tax;
private BigDecimal amountTotal;
public PhoneBill() { }
public PhoneBill(String number) {
this.phoneNumber = number;
calls = new ArrayList<>();
}
public void addCall(CallRecord call) {
calls.add(call);
}
public void calculate(BigDecimal taxRate) { ... }
/* ... Getters and setters ... *
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>OneToMany</code> annotation defines the relationship between a bill and
its call records. The <code>FetchType.EAGER</code> attribute specifies that the
collection should be retrieved eagerly. The <code>CascadeType.PERSIST</code>
attribute indicates that the elements in the call list should be
automatically persisted when the phone bill is persisted. The <code>OrderBy</code>
annotation defines an order for retrieving the elements of the call list
from the database.</p>
</div>
<div class="paragraph">
<p>The batch artifacts use instances of these two entities as items to
read, process, and write.</p>
</div>
<div class="paragraph">
<p>For more information on the Java Persistence API, see
<a href="persistence-intro.html#BNBPZ">Chapter 40, "Introduction to the Java
Persistence API"</a>. For more information on the JSON Processing API, see
<a href="jsonp.html#GLRBB">Chapter 20, "JSON Processing"</a>.</p>
</div>
<div class="paragraph">
<p><a id="sthref290"></a><a id="the-call-records-chunk-step"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_call_records_chunk_step">The Call Records Chunk Step</h4>
<div class="paragraph">
<p>The first step is composed of the <code>CallRecordReader</code>,
<code>CallRecordProcessor</code>, and <code>CallRecordWriter</code> batch artifacts.</p>
</div>
<div class="paragraph">
<p>The <code>CallRecordReader</code> artifact reads call records from the log file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Dependent
@Named("CallRecordReader")
public class CallRecordReader implements ItemReader {
private ItemNumberCheckpoint checkpoint;
private String fileName;
private BufferedReader breader;
@Inject
JobContext jobCtx;
/* ... Override the open, close, readItem,
* and checkpointInfo methods ... */
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>open</code> method reads the <code>log_filename</code> property and opens the log
file with a buffered reader:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">fileName = jobCtx.getProperties().getProperty("log_file_name");
breader = new BufferedReader(new FileReader(fileName));</code></pre>
</div>
</div>
<div class="paragraph">
<p>If a checkpoint object is provided, the <code>open</code> method advances the
reader up to the last checkpoint. Otherwise, this method creates a new
checkpoint object. The checkpoint object keeps track of the line number
from the last committed chunk.</p>
</div>
<div class="paragraph">
<p>The <code>readItem</code> method returns a new <code>CallRecord</code> object or null at the
end of the log file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Override
public Object readItem() throws Exception {
/* Read a line from the log file and
* create a CallRecord from JSON */
String callEntryJson = breader.readLine();
if (callEntryJson != null) {
checkpoint.nextItem();
return new CallRecord(callEntryJson);
} else
return null;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>CallRecordProcessor</code> artifact obtains the airtime price from the
job properties, calculates the price of each call, and returns the call
object. This artifact overrides only the <code>processItem</code> method.</p>
</div>
<div class="paragraph">
<p>The <code>CallRecordWriter</code> artifact associates each call record with a bill
and stores the bill in the database. This artifact overrides the <code>open</code>,
<code>close</code>, <code>writeItems</code>, and <code>checkpointInfo</code> methods. The <code>writeItems</code>
method looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Override
public void writeItems(List<Object> callList) throws Exception {
for (Object callObject : callList) {
CallRecord call = (CallRecord) callObject;
PhoneBill bill = em.find(PhoneBill.class, call.getFromNumber());
if (bill == null) {
/* No bill for this customer yet, create one */
bill = new PhoneBill(call.getFromNumber());
bill.addCall(call);
em.persist(bill);
} else {
/* Add call to existing bill */
bill.addCall(call);
}
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p><a id="BCGGGAHB"></a><a id="the-phone-billing-chunk-step"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_phone_billing_chunk_step">The Phone Billing Chunk Step</h4>
<div class="paragraph">
<p>The second step is composed of the <code>BillReader</code>, <code>BillProcessor</code>,
<code>BillWriter</code>, and <code>BillPartitionMapper</code> batch artifacts. This step gets
the phone bills from the database, computes the tax and total amount
due, and writes each bill to a text file. Since the processing of each
bill is independent of the others, this step can be partitioned and run
in more than one thread.</p>
</div>
<div class="paragraph">
<p>The <code>BillPartitionMapper</code> artifact specifies the number of partitions
and the parameters for each partition. In this example, the parameters
represent the range of items each partition should process. The artifact
obtains the number of bills in the database to calculate these ranges.
It provides a partition plan object that overrides the <code>getPartitions</code>
and <code>getPartitionProperties</code> methods of the <code>PartitionPlan</code> interface.
The <code>getPartitions</code> method looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Override
public Properties[] getPartitionProperties() {
/* Assign an (approximately) equal number of elements
* to each partition. */
long totalItems = getBillCount();
long partItems = (long) totalItems / getPartitions();
long remItems = totalItems % getPartitions();
/* Populate a Properties array. Each Properties element
* in the array corresponds to a partition. */
Properties[] props = new Properties[getPartitions()];
for (int i = 0; i < getPartitions(); i++) {
props[i] = new Properties();
props[i].setProperty("firstItem",
String.valueOf(i * partItems));
/* Last partition gets the remainder elements */
if (i == getPartitions() - 1) {
props[i].setProperty("numItems",
String.valueOf(partItems + remItems));
} else {
props[i].setProperty("numItems",
String.valueOf(partItems));
}
return props;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>BillReader</code> artifact obtains the partition parameters as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Dependent
@Named("BillReader")
public class BillReader implements ItemReader {
@Inject @BatchProperty(name = "firstItem") private String firstItemValue; @Inject @BatchProperty(name = "numItems") private String numItemsValue;
private ItemNumberCheckpoint checkpoint; @PersistenceContext private EntityManager em; private Iterator iterator;
@Override
public void open(Serializable ckpt) throws Exception {
/* Get the range of items to work on in this partition */
long firstItem0 = Long.parseLong(firstItemValue);
long numItems0 = Long.parseLong(numItemsValue);
if (ckpt == null) {
/* Create a checkpoint object for this partition */
checkpoint = new ItemNumberCheckpoint();
checkpoint.setItemNumber(firstItem0);
checkpoint.setNumItems(numItems0);
} else {
checkpoint = (ItemNumberCheckpoint) ckpt;
}
/* Adjust range for this partition from the checkpoint */
long firstItem = checkpoint.getItemNumber();
long numItems = numItems0 - (firstItem - firstItem0);
...
}
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This artifact also obtains an iterator to read items from the JPA entity
manager:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">/* Obtain an iterator for the bills in this partition */
String query = "SELECT b FROM PhoneBill b ORDER BY b.phoneNumber";
Query q = em.createQuery(query).setFirstResult((int) firstItem)
.setMaxResults((int) numItems);
iterator = q.getResultList().iterator();</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>BillProcessor</code> artifact iterates over the list of call records in a
bill and calculates the tax and total amount due for each bill.</p>
</div>
<div class="paragraph">
<p>The <code>BillWriter</code> artifact writes each bill to a plain text file.</p>
</div>
<div class="paragraph">
<p><a id="sthref291"></a><a id="the-javaserver-faces-pages"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_javaserver_faces_pages">The JavaServer Faces Pages</h4>
<div class="paragraph">
<p>The <code>index.xhtml</code> page contains a text area that shows the log file of
call records. The page provides a button for the user to submit the
batch job and navigate to the next page:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><body>
<h1>The Phone Billing Example Application</h1>
<h2>Log file</h2>
<p>The batch job analyzes the following log file:</p>
<textarea cols="90" rows="25"
readonly="true">#{jsfBean.createAndShowLog()}</textarea>
<p> </p>
<h:form>
<h:commandButton value="Start Batch Job"
action="#{jsfBean.startBatchJob()}" />
</h:form>
</body></code></pre>
</div>
</div>
<div class="paragraph">
<p>This page calls the methods of the managed bean to show the log file and
submit the batch job.</p>
</div>
<div class="paragraph">
<p>The <code>jobstarted.xhtml</code> page provides a button to check the current
status of the batch job and displays the bills when the job finishes:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><p>Current Status of the Job: <b>#{jsfBean.jobStatus}</b></p>
<h:dataTable var="_row" value="#{jsfBean.rowList}"
border="1" rendered="#{jsfBean.completed}">
<!-- ... show results from jsfBean.rowList ... -->
</h:dataTable>
<!-- Render the check status button if the job has not finished -->
<h:form>
<h:commandButton value="Check Status"
rendered="#{jsfBean.completed==false}"
action="jobstarted" />
</h:form></code></pre>
</div>
</div>
<div class="paragraph">
<p><a id="sthref292"></a><a id="the-managed-bean"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_the_managed_bean">The Managed Bean</h4>
<div class="paragraph">
<p>The <code>JsfBean</code> managed bean submits the job to the batch runtime, checks
on the status of the job, and reads the text files for each bill.</p>
</div>
<div class="paragraph">
<p>The <code>startBatchJob</code> method of the bean submits the job to the batch
runtime:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">/* Submit the batch job to the batch runtime.
* JSF Navigation method (return the name of the next page) */
public String startBatchJob() {
jobOperator = BatchRuntime.getJobOperator();
execID = jobOperator.start("phonebilling", null);
return "jobstarted";
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>getJobStatus</code> method of the bean checks the status of the job:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">/* Get the status of the job from the batch runtime */
public String getJobStatus() {
return jobOperator.getJobExecution(execID).getBatchStatus().toString();
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>getRowList</code> method of the bean creates a list of bills to be
displayed on the <code>jobstarted.xhtml</code> JSF page using a table.</p>
</div>
<div class="paragraph">
<p><a id="BABBGDAA"></a><a id="running-the-phonebilling-example-application"></a></p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_running_the_phonebilling_example_application">Running the phonebilling Example Application</h3>
<div class="paragraph">
<p>You can use either NetBeans IDE or Maven to build, package, deploy, and
run the <code>phonebilling</code> example application.</p>
</div>
<div class="paragraph">
<p>The following topics are addressed here:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#BABIBBBG">To Run the phonebilling Example Application Using
NetBeans IDE</a></p>
</li>
<li>
<p><a href="#BABFHIIB">To Run the phonebilling Example Application Using
Maven</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p><a id="BABIBBBG"></a><a id="to-run-the-phonebilling-example-application-using-netbeans-ide"></a></p>
</div>
<div class="sect3">
<h4 id="_to_run_the_phonebilling_example_application_using_netbeans_ide">To Run the phonebilling Example Application Using NetBeans IDE</h4>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Make sure that GlassFish Server has been started (see
<a href="usingexamples002.html#BNADI">Starting and Stopping GlassFish
Server</a>).</p>
</li>
<li>
<p>From the File menu, choose Open Project.</p>
</li>
<li>
<p>In the Open Project dialog box, navigate to:</p>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">tut-install/examples/batch</code></pre>
</div>
</div>
</li>
<li>
<p>Select the <code>phonebilling</code> folder.</p>
</li>
<li>
<p>Click Open Project.</p>
</li>
<li>
<p>In the Projects tab, right-click the <code>phonebilling</code> project and
select Run.</p>
<div class="paragraph">
<p>This command builds and packages the application into a WAR file,
<code>phonebilling.war</code>, located in the <code>target/</code> directory; deploys it to
the server; and launches a web browser window at the following URL:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">http://localhost:8080/phonebilling/</code></pre>
</div>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p><a id="BABFHIIB"></a><a id="to-run-the-phonebilling-example-application-using-maven"></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_to_run_the_phonebilling_example_application_using_maven">To Run the phonebilling Example Application Using Maven</h4>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Make sure that GlassFish Server has been started (see
<a href="usingexamples002.html#BNADI">Starting and Stopping GlassFish
Server</a>).</p>
</li>
<li>
<p>In a terminal window, go to:</p>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">tut-install/examples/batch/phonebilling/</code></pre>
</div>
</div>
</li>
<li>
<p>Enter the following command to deploy the application:</p>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">mvn install</code></pre>
</div>
</div>
</li>
<li>
<p>Open a web browser window at the following URL:</p>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">http://localhost:8080/phonebilling/</code></pre>
</div>
</div>
</li>
</ol>
</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-processing008.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-processing010.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>