Java Reference
In-Depth Information
return target.request().get(String.class);
}
}
Our reader extends the AbstractItemReader class so that we don't have to imple-
ment all methods of the javax.batch.api.chunk.ItemReader interface. The
only two methods we are interested in are open and readItem . The first one initializes
the REST client, which will get the data from the server. The implementation is optional
because not every reader needs initialization logic. Note that a checkpoint parameter is
passed to the method. It can be used to restart the batch job from a specific point. We will,
however, leave out this feature.
The readItem method requests the data from an external service and returns a single
item to the batch framework. A null value is an indicator that there is no more data. Addi-
tional methods of the ItemReader interface are responsible for checkpoint handling and
closing of the reader.
When we define the XML specification for the batch job, we must use the names of man-
aged beans to refer to the reader, processor, or writer we want (just like in JSF). Therefore,
we need the @Named annotation in order to provide a string-based qualifier; by default, it
will be a lowercase name of the class on which the annotation is placed. For the Ex-
ternalSystemReader bean, we will use the externalSystemReader name.
After an item is read, we may process it. Our SeatProcessor class goes as the follow-
ing code snippet:
package com.packtpub.wflydevelopment.chapter12.batching;
import javax.batch.api.chunk.ItemProcessor;
import javax.inject.Inject;
import javax.inject.Named;
import
com.packtpub.wflydevelopment.chapter12.control.SeatDao;
import com.packtpub.wflydevelopment.chapter12.entity.Seat;
@Named
public class SeatProcessor implements ItemProcessor {
@Inject
Search WWH ::




Custom Search