0 Replies Latest reply on Jun 6, 2016 4:10 PM by cfang

    JBeret and Other Programming and Scripting Languages

    cfang

      JBeret implements JSR 352, which defines batch processing for Java applications.  However, it doesn't mean you can't use other programming or scripting languages in your batch applications. In fact, with JBeret as the target batch runtime, a batch application can use multiple languages to satisfy different use cases:

      • other languages (scripting languages) inside JBeret runtime:  we currently support writing certain batch components with some common scripting languages, and they are invoked using JSR 223 (Scripting for the JavaTM Platform).  See JBERET-61
        • test-apps/scripting contains many sample batch jobs written with various scripting languages (Groovy, JavaScript, PHP, Jython, JRuby, Scala, etc)
      • JBeret inside other language runtime: as a java library, JBeret modules can work with and inside other language runtime (especailly JVM languages) just as any other java lib.  For instance, Groovy/JRuby app can easily embed and invoke JBeret to start, stop jobs and get job data, etc.
      • Interop with REST: any html or rest-capable client can interop with remote JBeret batch runtime that includes jberet-rest-api. See REST API docs for details.
      • Write batch components in other languages and compile into java classes. For instance, several common JVM scripting languages (Groovy, Scala, Kotlin, etc)support compiling scripts into java class files.

       

      A common use case is in testing and  app prototyping, where you can quickly put together a functioning batch job with your favorite scripting language.  For example, the following job xml file is all you need to both define and implement a batchlet batch job:

      <job id="timer-scheduler-job1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
          <step id="timer-scheduler-job1.step1">
              <batchlet>
                  <properties>
                      <property name="testName" value="#{jobParameters['testName']}"/>
                  </properties>
                  <script type="javascript">
                      function process() {
                          var testName = batchProperties.get('testName');
                          var stepName = stepContext.getStepName();
                          var d = new Date();
                          var msg = d + ', testName: ' + testName + ', stepName: ' + stepName;
                          print(msg);
                          jobContext.setExitStatus(msg);
                          return msg;
                      }
                  </script>
              </batchlet>
          </step>
      </job>