{"id":406,"date":"2014-06-02T00:08:04","date_gmt":"2014-06-01T15:08:04","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2014\/06\/02\/java_ee_7_12_jbatch_arquillian\/"},"modified":"2014-06-02T00:08:04","modified_gmt":"2014-06-01T15:08:04","slug":"java_ee_7_12_jbatch_arquillian","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/02\/java_ee_7_12_jbatch_arquillian\/","title":{"rendered":"Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(12) jBatch \u7c21\u6613\u30b5\u30f3\u30d7\u30eb\u4f5c\u6210\u3068 Arquillian \u3067\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8"},"content":{"rendered":"<ol>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/28\/java_ee_7_1_wildfly_jboss_tools_ear_arquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(1) WildFly + JBoss Tools \u3067 EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057 Arquillian \u3067 \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u30b0\u30ea\u30fc\u30f3\u306b\u3059\u308b\u3068\u3053\u308d\u307e\u3067<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/28\/java_ee_7_2_wildfly_datasource\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(2) WildFly \u306b DataSource\u3092\u4f5c\u6210<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/29\/java_ee_7_3_jpamysqlarquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(3) JPA\u304b\u3089MySQL\u306b\u63a5\u7d9a\u3059\u308b\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092Arquillian\u3067\u5b9f\u884c<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/05\/java_ee_4_java_ee_didependency_injection_cdicontexts_and_dependency_injection\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(4) Java EE \u3067\u306e DI(Dependency Injection) \u304a\u3088\u3073 CDI(Contexts and Dependency Injection)\u3092\u306a\u304c\u3081\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/08\/java_ee_7_5_jboss_toolscdi\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(5) JBoss Tools\u304c\u751f\u6210\u3057\u305f\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u306eCDI\u3092\u78ba\u8a8d\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/10\/java_ee_7_6_jpa\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(6) JPA \u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u4f5c\u6210\u3068\u633f\u5165<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/12\/java_ee_7_7_jpa_1\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(7) JPA \u554f\u3044\u5408\u308f\u305b(1) \u540d\u524d\u4ed8\u304d\u30af\u30a8\u30ea\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u30c6\u30b9\u30c8\u3067\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3082\u610f\u8b58\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/17\/java_ee_7_8_jpa_2_criteria_api\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(8) JPA \u554f\u3044\u5408\u308f\u305b(2) \u52d5\u7684\u30af\u30a8\u30ea\u3068Criteria API \u3092\u8a66\u3059<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/25\/java_ee_7_9_jbatch\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(9) jBatch \u6982\u8981\u3092\u304a\u3055\u3048\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/25\/java_ee_7_10_jboss_tools_earjava_ee_6_7\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(10) JBoss Tools \u3067\u4f5c\u6210\u3057\u305f EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092Java EE 6 \u304b\u3089 7 \u306b\u5909\u66f4\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/30\/java_ee_7_11_jbatch\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(11) jBatch\u7528 \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u3092\u884c\u3046<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/02\/java_ee_7_12_jbatch_arquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(12) jBatch \u7c21\u6613\u30b5\u30f3\u30d7\u30eb\u4f5c\u6210\u3068 Arquillian \u3067\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/10\/java_ee_7_13_jbatch_rest\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(13) jBatch REST \u30b5\u30fc\u30d3\u30b9\u7d4c\u7531\u3067\u5b9f\u884c\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/15\/java_ee_7_14_wildfly_gui\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(14) WildFly \u306e\u7ba1\u7406\u3092GUI\u3067\u884c\u3046<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/15\/java_ee_7_15_wildfly_windowslinux\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(15) WildFly \u3092 \u30b5\u30fc\u30d3\u30b9\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b(Windows\/Linux)<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/26\/java_ee_7_16_wildfly_apache_mod_jk_widows\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(16) WildFly \u3068 Apache \u3092 mod_jk \u3067\u9023\u643a\u3055\u305b\u308b(Widows)<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/25\/java_ee_7_9_jbatch\">jBatch\u306e\u6982\u8981\u3092\u62bc\u3055\u3048\u3066<\/a>\u3001jBatch\u7528\u306e\u74b0\u5883(<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/25\/java_ee_7_10_jboss_tools_earjava_ee_6_7\">Java EE7\u5bfe\u5fdc<\/a>\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/30\/java_ee_7_11_jbatch\">EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u751f\u6210<\/a>)\u3092\u884c\u3063\u305f\u306e\u3067\u3001<a href=\"http:\/\/docs.oracle.com\/javaee\/7\/tutorial\/doc\/batch-processing003.htm#BCGHBJIG\">Java EE 7 \u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u304b\u3089\u3001\u30d0\u30c3\u30c1\u306e\u7c21\u5358\u306a\u4f8b<\/a> \u3092\u8a66\u3057\u3066\u307f\u308b\u3002(<a href=\"http:\/\/kagamihoge.hatenablog.com\/entry\/2014\/04\/10\/205918\">\u65e5\u672c\u8a9e\u8a33\u30b5\u30a4\u30c8\u306f\u3053\u3061\u3089<\/a>)<\/p>\n<h2>1.\u7c21\u5358\u306a\u4f7f\u7528\u4f8b<\/h2>\n<p>\u30b8\u30e7\u30d6\u5b9a\u7fa9\u8a00\u8a9e(JSL)\u3092XML\u3067\u4f5c\u6210\u3059\u308b\u3002XML\u30d5\u30a1\u30a4\u30eb\u306f\u3001META-INF\/batch-jobs \u914d\u4e0b\u306b\u683c\u7d0d\u3059\u308b\u3002<\/p>\n<p>\u4eca\u56de\u306e\u6d41\u308c\u3067\u306f\u3001batch-ejb \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u3001META-INF\/batch-jobs \u914d\u4e0b\u306b\u3001simplejob.xml \u3068\u3044\u3046\u540d\u524d\u3067\u4f5c\u6210\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_job_xml.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"batch_job_xml\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" border=\"0\" alt=\"batch_job_xml\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_job_xml_thumb.jpg\" width=\"219\" height=\"337\" \/><\/a><\/p>\n<p>\u30c1\u30e3\u30f3\u30af\u30b9\u30c6\u30c3\u30d7\u3068\u30bf\u30b9\u30af\u30b9\u30c6\u30c3\u30d7\u306e\u30b8\u30e7\u30d6\u5b9a\u7fa9\u3002input_file\u3001output_file \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5177\u4f53\u7684\u306a\u30d5\u30a1\u30a4\u30eb\u306b\u8a2d\u5b9a\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;!-- http:\/\/docs.oracle.com\/javaee\/7\/tutorial\/doc\/batch-processing003.htm --&gt;\r\n&lt;job id=\"simplejob\" xmlns=\"http:\/\/xmlns.jcp.org\/xml\/ns\/javaee\" \r\n                    version=\"1.0\"&gt;\r\n  &lt;properties&gt;\r\n    &lt;property name=\"input_file\" value=\"c:\\work\\test.txt\"\/&gt;\r\n    &lt;property name=\"output_file\" value=\"c:\\work\\test_out.txt\"\/&gt;\r\n  &lt;\/properties&gt;\r\n  &lt;step id=\"mychunk\" next=\"mytask\"&gt;\r\n    &lt;chunk&gt;\r\n      &lt;reader ref=\"MyReader\"&gt;&lt;\/reader&gt;\r\n      &lt;processor ref=\"MyProcessor\"&gt;&lt;\/processor&gt;\r\n      &lt;writer ref=\"MyWriter\"&gt;&lt;\/writer&gt;\r\n    &lt;\/chunk&gt;\r\n  &lt;\/step&gt;\r\n  &lt;step id=\"mytask\"&gt;\r\n    &lt;batchlet ref=\"MyBatchlet\"&gt;&lt;\/batchlet&gt;\r\n    &lt;end on=\"COMPLETED\"\/&gt;\r\n  &lt;\/step&gt;\r\n&lt;\/job&gt;<\/pre>\n<h2>2.\u4f5c\u6210\u3059\u308b\u30af\u30e9\u30b9<\/h2>\n<p>\u30b8\u30e7\u30d6\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u3067\u53c2\u7167\u3059\u308b\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_structure.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"batch_structure\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" border=\"0\" alt=\"batch_structure\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_structure_thumb.jpg\" width=\"258\" height=\"149\" \/><\/a><\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"400\" border=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"200\">\u30af\u30e9\u30b9<\/td>\n<td valign=\"top\" width=\"200\">\u5f79\u5272<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\">MyCheckpoint<\/td>\n<td valign=\"top\" width=\"200\">\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u3002\u51e6\u7406\u6e08\u307f\u306e\u4f4d\u7f6e\u3092\u4fdd\u6301\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\">MyReader<\/td>\n<td valign=\"top\" width=\"200\">\u30a2\u30a4\u30c6\u30e0\u3092\u8aad\u307f\u8fbc\u3080\u3002\u30b8\u30e7\u30d6\u304c\u518d\u958b\u3055\u308c\u305f\u5834\u5408\u306f\u3001\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u304b\u3089\u8aad\u307f\u8fbc\u307f\u4f4d\u7f6e\u3092\u53d6\u5f97\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\">MyProcesser<\/td>\n<td valign=\"top\" width=\"200\">\u8aad\u307f\u8fbc\u3093\u3060\u30a2\u30a4\u30c6\u30e0\u3092\u51e6\u7406\u3002<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\">MyWriter<\/td>\n<td valign=\"top\" width=\"200\">\u51e6\u7406\u6e08\u307f\u30a2\u30a4\u30c6\u30e0\u3092\u51fa\u529b\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\"> <\/td>\n<td valign=\"top\" width=\"200\"> <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.1 \u30c1\u30e3\u30f3\u30af\u30b9\u30c6\u30c3\u30d7<\/h3>\n<h4>2.1.1 Checkpoint \u30af\u30e9\u30b9<\/h4>\n<ul>\n<li>\u591a\u304f\u306e\u5834\u5408\u3001\u30c1\u30e3\u30f3\u30af\u6307\u5411\u30b9\u30c6\u30c3\u30d7\u306e\u305f\u3081\u306b\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u3092\u5b9f\u88c5\u3059\u3079\u304d<\/li>\n<li>\u4ee5\u4e0b\u306e\u30af\u30e9\u30b9\u306f\u3001\u51e6\u7406\u3055\u308c\u305f\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u884c\u3092\u4fdd\u6301\u3059\u308b<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\">@SuppressWarnings(\"serial\")\r\npublic class MyCheckpoint implements Serializable {\r\n    \r\n    private long lineNum = 0;\r\n    \r\n    public void increase() { \r\n        lineNum++; \r\n    }\r\n    public long getLineNum() { \r\n        return lineNum; \r\n    }\r\n}<\/pre>\n<h4>2.1.2 ItemReader \u30af\u30e9\u30b9<\/h4>\n<ul>\n<li>ItemReader\u5b9f\u88c5\u30af\u30e9\u30b9\u306f\u3001\u30b8\u30e7\u30d6\u304c\u518d\u958b\u3055\u308c\u305f\u5834\u5408\u306b\u306f\u4e0e\u3048\u3089\u308c\u305f\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u304b\u3089\u5165\u529b\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u7d9a\u884c\u3059\u308b<\/li>\n<li>\u30a2\u30a4\u30c6\u30e0\u306f\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u5404\u884c\u306b\u5bfe\u5fdc<\/li>\n<li>\u3088\u308a\u8907\u96d1\u306a\u30b7\u30ca\u30ea\u30aa\u3067\u306f\u3001\u30a2\u30a4\u30c6\u30e0\u306f\u72ec\u81ea\u306eJava\u30af\u30e9\u30b9\u3067\u5165\u529b\u5143\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u7b49\u306b\u306a\u308b<\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/05\/java_ee_4_java_ee_didependency_injection_cdicontexts_and_dependency_injection\">@Named \u3067\u3001MyReader \u3068\u3044\u3046\u540d\u524d\u3092\u3064\u3051\u3001\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u540d\u524d\u3067\u53c2\u7167<\/a><\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\">@Dependent\r\n@Named(\"MyReader\")\r\npublic class MyReader implements javax.batch.api.chunk.ItemReader {\r\n    private MyCheckpoint checkpoint;\r\n    private BufferedReader breader;\r\n    \r\n    @Inject\r\n    JobContext jobCtx;\r\n    \r\n    public MyReader() {}\r\n\r\n    \/*\r\n     * Item\u3092\u8aad\u3080\u305f\u3081\u306eReader\u3092\u6e96\u5099\u3059\u308b\r\n     * \u4eee\u5f15\u6570\u306f\u3001\u30b8\u30e7\u30d6\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u6700\u7d42\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\r\n     *\/\r\n    @Override\r\n    public void open(Serializable ckpt) throws Exception {\r\n        if (ckpt == null) {\r\n            checkpoint = new MyCheckpoint();\r\n        } else {\r\n            checkpoint = (MyCheckpoint) ckpt;\r\n        }\r\n        String fileName = jobCtx.getProperties()\r\n                                .getProperty(\"input_file\");\r\n        breader = new BufferedReader(new FileReader(fileName));\r\n        for (long i = 0; i &lt; checkpoint.getLineNum(); i++) {\r\n            breader.readLine();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void close() throws Exception {\r\n        breader.close();\r\n    }\r\n\r\n    @Override\r\n    public Object readItem() throws Exception {\r\n        String line = breader.readLine();\r\n        return line;\r\n    }\r\n\r\n    \/* \r\n     * Reader\u306b\u5bfe\u3057\u3066\u3001\u3001\u73fe\u5728\u306e\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u3092\u8fd4\u3059\r\n     *\/\r\n    @Override\r\n    public Serializable checkpointInfo() throws Exception {\r\n        return checkpoint;\r\n    }\r\n}<\/pre>\n<h4>2.1.3 ItemProcessor \u30af\u30e9\u30b9<\/h4>\n<ul>\n<li>\u8aad\u307f\u8fbc\u3093\u3060\u30a2\u30a4\u30c6\u30e0\u3092\u51e6\u7406\u3059\u308b<\/li>\n<li>\u3053\u306e\u30b1\u30fc\u30b9\u3067\u306f\u3001\u5927\u6587\u5b57\u306b\u5909\u63db\u3059\u308b\u3060\u3051<\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/05\/java_ee_4_java_ee_didependency_injection_cdicontexts_and_dependency_injection\">@Named \u3067\u3001MyProcessor \u3068\u3044\u3046\u540d\u524d\u3092\u3064\u3051\u3001\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u540d\u524d\u3067\u53c2\u7167<\/a><\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\">@Dependent\r\n@Named(\"MyProcessor\")\r\npublic class MyProcessor implements javax.batch.api.chunk.ItemProcessor {\r\n    public MyProcessor() {}\r\n\r\n    @Override\r\n    public Object processItem(Object obj) throws Exception {\r\n        String line = (String) obj;\r\n        return line.toUpperCase();\r\n    }\r\n}<\/pre>\n<h4>2.1.4 ItemWriter \u30af\u30e9\u30b9<\/h4>\n<ul>\n<li>ItemWriter\u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u306fItemProcessor\u3092\u901a\u904e\u3057\u305f\u30c7\u30fc\u30bf\u3092\u30d5\u30a1\u30a4\u30eb\u3078\u51fa\u529b<\/li>\n<li>\u3082\u3057\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u304c\u7121\u3051\u308c\u3070\u51fa\u529b\u30d5\u30a1\u30a4\u30eb\u3092\u4e0a\u66f8\u304d\u3057\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u30d5\u30a1\u30a4\u30eb\u306eEOF\u3078\u306e\u66f8\u304d\u8fbc\u307f\u3092\u518d\u958b<\/li>\n<li>\u30a2\u30a4\u30c6\u30e0\u306f\u30c1\u30e3\u30f3\u30af\u3054\u3068\u306b\u66f8\u304d\u8fbc\u307e\u308c\u308b<\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/05\/java_ee_4_java_ee_didependency_injection_cdicontexts_and_dependency_injection\">@Named \u3067\u3001MyWriter \u3068\u3044\u3046\u540d\u524d\u3092\u3064\u3051\u3001\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u540d\u524d\u3067\u53c2\u7167<\/a><\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\">@Dependent\r\n@Named(\"MyWriter\")\r\npublic class MyWriter implements javax.batch.api.chunk.ItemWriter {\r\n    private BufferedWriter bwriter;\r\n    \r\n    @Inject\r\n    private JobContext jobCtx;\r\n\r\n    @Override\r\n    public void open(Serializable ckpt) throws Exception {\r\n        String fileName = jobCtx.getProperties()\r\n                                .getProperty(\"output_file\");\r\n        bwriter = new BufferedWriter(new FileWriter(fileName, \r\n                                                    (ckpt != null)));\r\n    }\r\n\r\n    @Override\r\n    public void writeItems(List&lt;Object&gt; items) throws Exception {\r\n        for (int i = 0; i &lt; items.size(); i++) {\r\n            String line = (String) items.get(i);\r\n            bwriter.write(line);\r\n            bwriter.newLine();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public Serializable checkpointInfo() throws Exception {\r\n        return new MyCheckpoint();\r\n    }\r\n\r\n    @Override\r\n    public void close() throws Exception {\r\n        bwriter.close();\r\n    }\r\n}<\/pre>\n<h3>2.2 \u30bf\u30b9\u30af\u30b9\u30c6\u30c3\u30d7<\/h3>\n<h4>2.2.1 Batchlet<\/h4>\n<ul>\n<li><a href=\"http:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/batch\/api\/Batchlet.html\">\u30c1\u30e3\u30f3\u30af\u6307\u5411\u3067\u3046\u307e\u304f\u6271\u3048\u306a\u3044\u3088\u3046\u306a\u51e6\u7406\u3092\u6271\u3046\u3053\u3068\u304c\u51fa\u6765\u308b<\/a><\/li>\n<li>\u3053\u306e\u4f8b\u3067\u306f\u3001\u30bf\u30b9\u30af\u30b9\u30c6\u30c3\u30d7\u306f\u51fa\u529b\u30d5\u30a1\u30a4\u30eb\u306e\u30b5\u30a4\u30ba\u3092\u8868\u793a<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\">@Dependent\r\n@Named(\"MyBatchlet\")\r\npublic class MyBatchlet implements javax.batch.api.Batchlet {\r\n    \r\n    @Inject\r\n    private JobContext jobCtx;\r\n    \r\n    @Override\r\n    public String process() throws Exception {\r\n        String fileName = jobCtx.getProperties()\r\n                                .getProperty(\"output_file\");\r\n        System.out.println(\"\"+(new File(fileName)).length());\r\n        return \"COMPLETED\";\r\n    }\r\n\r\n    @Override\r\n    public void stop() throws Exception {\r\n        \/\/ TODO Auto-generated method stub\r\n    }\r\n}<\/pre>\n<h2>2. Arquillian \u3067\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u884c\u3046<\/h2>\n<p>\u3055\u3066\u3001\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u5f93\u3044\u3001\u5b9f\u88c5\u3057\u305f\u306e\u3067\u3001Arquillian \u306b\u3088\u308b\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u884c\u304a\u3046\u3002\u3002\u3002\u3068\u601d\u3046\u3002<\/p>\n<p><a title=\"https:\/\/github.com\/javaee-samples\/javaee7-samples\" href=\"https:\/\/github.com\/javaee-samples\/javaee7-samples\">https:\/\/github.com\/javaee-samples\/javaee7-samples<\/a><\/p>\n<p>Github \u306b Java EE 7 \u306e\u30b5\u30f3\u30d7\u30eb\u304c\u4e0a\u304c\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u53c2\u8003\u306bArquillian \u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3092\u4f5c\u6210\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_test_structure.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"batch_test_structure\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" border=\"0\" alt=\"batch_test_structure\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_test_structure_thumb.jpg\" width=\"227\" height=\"164\" \/><\/a><\/p>\n<p>\u6700\u7d42\u7684\u306b\u306f\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306a\u69cb\u6210\u306b\u306a\u308b\u3002\u30b5\u30f3\u30d7\u30eb\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3092\u5229\u7528\u3059\u308b\u306b\u306f\u3001BatchTestHelper \u30af\u30e9\u30b9\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001<\/p>\n<p><a title=\"https:\/\/github.com\/javaee-samples\/javaee7-samples\/blob\/master\/util\/src\/main\/java\/org\/javaee7\/util\/BatchTestHelper.java\" href=\"https:\/\/github.com\/javaee-samples\/javaee7-samples\/blob\/master\/util\/src\/main\/java\/org\/javaee7\/util\/BatchTestHelper.java\">https:\/\/github.com\/javaee-samples\/javaee7-samples\/blob\/master\/util\/src\/main\/java\/org\/javaee7\/util\/BatchTestHelper.java<\/a><\/p>\n<p>\u3092\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u7d44\u307f\u8fbc\u3080\u3002<\/p>\n<h3>2.1 BatchTestHelper<\/h3>\n<pre class=\"prettyprint linenums\">\/**\r\n * @author Roberto Cortez\r\n * @see https:\/\/github.com\/javaee-samples\/javaee7-samples\/blob\/master\/util\/src\/main\/java\/org\/javaee7\/util\/BatchTestHelper.java\r\n *\/\r\npublic final class BatchTestHelper {\r\n    private static final int MAX_TRIES = 10;\r\n    private static final int THREAD_SLEEP = 100;\r\n\r\n    private BatchTestHelper() {\r\n        throw new UnsupportedOperationException();\r\n    }\r\n\r\n    \/**\r\n     * We need to keep the test running because JobOperator runs the batch job in an asynchronous way, so the\r\n     * JobExecution can be properly updated with the running job status.\r\n     *\r\n     * @param jobExecution\r\n     *         the JobExecution of the job that is being runned on JobOperator.\r\n     *\r\n     * @throws InterruptedException thrown by Thread.sleep.\r\n     *\/\r\n    public static void keepTestAlive(JobExecution jobExecution) throws InterruptedException {\r\n        int maxTries = 0;\r\n        while (!jobExecution.getBatchStatus().equals(BatchStatus.COMPLETED)) {\r\n            if (maxTries &lt; MAX_TRIES) {\r\n                maxTries++;\r\n                Thread.sleep(THREAD_SLEEP);\r\n            } else {\r\n                break;\r\n            }\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * Convert the Metric array contained in StepExecution to a key-value map for easy access to Metric parameters.\r\n     *\r\n     * @param metrics\r\n     *         a Metric array contained in StepExecution.\r\n     *\r\n     * @return a map view of the metrics array.\r\n     *\/\r\n    public static Map&lt;metric.metrictype   , long&gt; getMetricsMap(Metric[] metrics) {\r\n        Map&lt;metric.metrictype   , long&gt; metricsMap = new HashMap&lt;&gt;();\r\n        for (Metric metric : metrics) {\r\n            metricsMap.put(metric.getType(), metric.getValue());\r\n        }\r\n        return metricsMap;\r\n    }\r\n}<\/pre>\n<h3>2.2 \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9<\/h3>\n<p>\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3068\u306f\u8a00\u3046\u304c\u3001\u307e\u305a\u306f\u3001Arquillian \u4e0a\u3067\u30d0\u30c3\u30c1\u304c\u8d77\u52d5\u51fa\u6765\u308c\u3070\u3088\u3044\u3002<\/p>\n<p>@Deployment \u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u3051\u305f\u30c7\u30d7\u30ed\u30a4\u30e1\u30bd\u30c3\u30c9\u3067\u3001Web\u30a2\u30fc\u30ab\u30a4\u30d6\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<ul>\n<li>addPackage \u306b\u4eca\u56de\u306e\u30d0\u30c3\u30c1\u95a2\u9023\u30af\u30e9\u30b9\u304c\u5165\u3063\u305f\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u6307\u5b9a\u3057\u3066\u3001\u30a2\u30fc\u30ab\u30a4\u30d6\u306b\u542b\u3081\u3066\u3044\u308b<\/li>\n<li>addAsWebInfResource \u306e\u884c\u3067\u306f\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/05\/java_ee_4_java_ee_didependency_injection_cdicontexts_and_dependency_injection\">CDI\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306b\u3001\u7a7a\u306ebean.xml \u3092\u30a2\u30fc\u30ab\u30a4\u30d6\u306b\u542b\u3081\u3066\u3044\u308b<\/a><\/li>\n<li>addAsResource\u306e\u884c\u3067\u306f\u3001\u30b8\u30e7\u30d6\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30fc\u30ab\u30a4\u30d6\u306b\u542b\u3081\u3066\u3044\u308b\u3002<\/li>\n<li>addClass \u306e\u884c\u3067\u306f\u3001CDI\u306b\u30ed\u30ac\u30fc\u306a\u3069\u3092\u767b\u9332\u3059\u308b\u30af\u30e9\u30b9\u3092\u767b\u9332\n<ul>\n<li><a title=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/08\/java_ee_7_5_jboss_toolscdi\" href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/08\/java_ee_7_5_jboss_toolscdi\">https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/08\/java_ee_7_5_jboss_toolscdi<\/a><\/li>\n<\/ul>\n<\/li>\n<li>System.out.print \u3067 war.toString \u3092\u547c\u3076\u3053\u3068\u3067\u3001\u30a2\u30fc\u30ab\u30a4\u30d6\u306e\u69cb\u6210\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3055\u308c\u308b\u306e\u3067\u3001\u601d\u3063\u305f\u3088\u3046\u306a\u69cb\u6210\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<\/li>\n<\/ul>\n<p>@Test \u3092\u4ed8\u4e0e\u3057\u305f\u3001\u30c6\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u3001JobOperator \u304b\u3089\u3001\u30b8\u30e7\u30d6\u5b9a\u7fa9XML\u3067\u5b9a\u7fa9\u3057\u305f\u3001&#8221;simplejob&#8221;\u3092\u547c\u3073\u51fa\u3057\u30d0\u30c3\u30c1\u3092\u51e6\u7406\u3057\u3066\u3044\u308b\u3002<\/p>\n<\/p>\n<pre class=\"prettyprint linenums\">@RunWith(Arquillian.class)\r\npublic class SimpleJobTest {\r\n\r\n    @Deployment\r\n    public static WebArchive createDeployment() {\r\n        WebArchive war = ShrinkWrap.create(WebArchive.class, \"test.war\")\r\n                .addClass(BatchTestHelper.class)\r\n                .addPackage(\"info.typea.tallarico.job.simplejob\")\r\n                .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create(\"beans.xml\"))\r\n                .addAsResource(\"META-INF\/batch-jobs\/simpleJob.xml\")\r\n                .addClass(Resources.class)\r\n                ;\r\n        System.out.println(war.toString(true));\r\n        return war;\r\n    }\r\n    \r\n    @Inject\r\n    Logger logger;\r\n    \r\n    @Test\r\n    public void simpleJobTest() throws Exception {\r\n        JobOperator jobOperator = BatchRuntime.getJobOperator();\r\n        Long executionId = jobOperator.start(\"simplejob\", new Properties());\r\n        JobExecution jobExecution = jobOperator.getJobExecution(executionId);\r\n        \r\n        BatchTestHelper.keepTestAlive(jobExecution);\r\n        \r\n        List<stepexecution> stepExecutions = jobOperator.getStepExecutions(executionId);\r\n        for (StepExecution stepExecution : stepExecutions) {\r\n            String stepName = stepExecution.getStepName();\r\n            \r\n            switch(stepName) {\r\n            case \"mychunk\":\r\n            case \"mytask\":\r\n                Map&lt;metric.metrictype   , Long&gt; metricsMap \r\n                    = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());\r\n                \r\n                logger.info(\"===== STEP NAME:\" + stepName + \"=====\");\r\n                logger.info(\"READ COUNT:\" + metricsMap.get(Metric.MetricType.READ_COUNT).longValue());\r\n                logger.info(\"WRITE COUNT:\" + metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());\r\n                logger.info(\"COMMIT COUNT:\" + metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());\r\n                break;\r\n            }\r\n        }\r\n    }\r\n}<\/stepexecution><\/pre>\n<\/p>\n<p>\u305d\u306e\u4ed6\u306e\u8a2d\u5b9a\u306f\u3001<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/28\/java_ee_7_1_wildfly_jboss_tools_ear_arquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(1) WildFly + JBoss Tools \u3067 EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057 Arquillian \u3067 \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u30b0\u30ea\u30fc\u30f3\u306b\u3059\u308b\u3068\u3053\u308d\u307e\u3067<\/a><\/p>\n<p>\u3092\u53c2\u8003\u306b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_test_green.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"batch_test_green\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" border=\"0\" alt=\"batch_test_green\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/Java-EE-7-12_13D54\/batch_test_green_thumb.jpg\" width=\"386\" height=\"246\" \/><\/a><\/p>\n<p>\u30c6\u30b9\u30c8\u6210\u529f\uff01\u51fa\u529b\u30d5\u30a1\u30a4\u30eb\u3082\u671f\u5f85\u901a\u308a\u751f\u6210\u3055\u308c\u305f\u3002<\/p>\n<p>\n<iframe loading=\"lazy\" width=\"320\" height=\"240\" style=\"height: 240px; width: 120px;\" marginheight=\"0\" src=\"http:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?lt1=_blank&amp;bc1=FFFFFF&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=typea09-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=1449370179\" frameborder=\"0\" marginwidth=\"0\" scrolling=\"no\"><\/iframe><br \/>\n<iframe loading=\"lazy\" width=\"320\" height=\"240\" style=\"height: 240px; width: 120px;\" marginheight=\"0\" src=\"http:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?lt1=_blank&amp;bc1=FFFFFF&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=typea09-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=4873114675\" frameborder=\"0\" marginwidth=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(1) WildFly + JBoss Tools \u3067 EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057 Arquillian \u3067 \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u30b0\u30ea\u30fc\u30f3\u306b\u3059\u308b\u3068\u3053\u308d\u307e\u3067 Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[69,46,74],"tags":[],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-arquillian","category-java-ee","category-jbatch"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=406"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}