Java Batch Job Framework

utopianthreeSoftware and s/w Development

Jul 14, 2012 (5 years and 1 month ago)

496 views

Java Batch Job Framework
Plugins Tutorial
Author: Adym Lincoln, Java Batch Job Framework
Copyright © 2006-2010, Java Batch Job Framework Software, All Rights Reserved
ACKNOWLEDGMENTS



............................................................................................................

3

PREAMBLE



..................................................................................................................................

4

G
LOSSARY



...........................................................................................................................................

4

R
EFERENCES



........................................................................................................................................

4

WHAT ARE JBJF PLUGINS?



....................................................................................................

5

JBJF PLUGIN CATEGORIES AND INTERFACES



................................................................

7

PLUGIN DEFINITIONS



.............................................................................................................

8

CREATING A JBJF PLUGIN



...................................................................................................

10

SYNOPSIS



...................................................................................................................................

28

OTHER RESOURCES



...............................................................................................................

29

Acknowledgments
Apache Software Foundation - This product includes software developed by the Apache

Software Foundation (
http://www.apache.org/
). We would like to acknowledge the

terrific work the Apache Software Foundation has provided.
Sun Microsystems - This product includes and/or utilizes software developed by the Sun

Microsystems (
http://www.sun.com/ )
. We would like to acknowledge Sun

Microsystems' contributions to the Open Source initiative.
JDom - The JBJF utilizes the JDom library for XML processing and we would like to

acknowledge them and their work.
Bouncy Castle - The JBJF utilizes the Bouncy Castle encryption library and we would like

to acknowledge their great work.
OpenOffice.org – The very document you're reading was created with OpenOffice

products. We would like to acknowledge the great work they have done and the

excellent products this organization puts out.
Java Batch Job Framework
Preamble
This tutorial assumes that you've read through the Plugins User Guide. The Plugins

User Guide provides essential background on the how and why for JBJF Plugins.
In this tutorial we will focus on the following concepts:

JBJF Plugin Categories and Interfaces

JBJF Plugin Definitions

Creating a JBJF Plugin
Glossary
Name
Description/Comments
JBJF
A document acronym for Java Batch Job Framework.
XML
Industry standard for Extensible Markup Language. A

simple language for adding structure to data and

documents.
XML Definition
A coding paradigm that combines Java's programming

language with XML configuration files.
JBJF Batch Definition File
A specialized XML file that contains data and elements

specific to a JBJF batch job.
References

Title:
jbjf-user-guide.pdf
Location:
http://jbjf.sourceforge.net/pdfs/jbjf-user-guide.pdf

Author: Adym S. Lincoln
Referenced Revision: 1.3.0

Title:
jbjf-basics-tutorial.pdf
Location:
http://jbjf.sourceforge.net/pdfs/jbjf-basics-tutorial.pdf

Author: Adym S. Lincoln
Referenced Revision: 1.3.0
Plugins Tutorials - Version 1.3.0
Page
4
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
What are JBJF Plugins?
JBJF Plugins are a new architecture being introduced into JBJF. Plugins provide

developers and batch process designers a way to enhance and extend JBJF without

having to know intimate details and specific code within JBJF. Prior to Plugins the

original JBJF could be enhanced, but it required intimate knowledge of the code and it

also required you to download the source code and directly replace specific Java

classes.
The JBJF Plugins architecture allows you to enhance and extend JBJF with only a

compiled JBJF runtime binary and some simple knowledge of the specific plugin

category you are developing. Because the plugins are done outside the source code

and “dropped” in as a runtime binary, enhancements can be done at any time and

anyplace. All that is required is the JRE/JDK 6 and JBJF 1.3.0(+). See the JBJF Plugins

Tutorial for complete details...
The initial release of JBJF Plugins will support the follow Plugin Categories:
Cipher
Encryption and Decryption. You write a simple Plugin class that

implements the IJBJFPluginCipher or extends the

IAbstractJBJFPluginCipher. Ciphers are now allocated at both the

Batch and the “Task” level. A nagging issue with JBJF has been the

ability to use custom encryption keys and other encryption

algorithms. A simple switch from the default DES/CBC encryption to

something like AES involved large amounts of custom code, class

replacement and rebuilding of JBJF.
Now the Cipher Plugin API allows us to write a custom

implementation against whatever encryption library we want. Our

Plugin gets compiled and packaged into a common jarfile. The jarfile

then gets “dropped” into a “plugins” directory. Tasks can then just

reference the Cipher Plugin API to have text encrypted/decrypted

with whatever cipher plugin you wish.
Database
JDBC Database types. Another hefty flaw in JBJF was total lack of

any DAO layer. Database tasks were typically written to a specific

database platform, MS SQL Server only, Oracle only or MySQL only.

So, while the tasks could be reused for other like platform SQL work,

they were limited to that one database platform only.
Using the new Database Plugin API, you write a simple Plugin class

that implements the IJBJFPluginDatabase or extends the

IAbstractJBJFPluginDatabase. The plugin then got compiled into a

common jarfile and dropped into the plugins directory.
Unlike a traditional DAO which usually targets a specific Data Model,

Plugins Tutorials - Version 1.3.0
Page
5
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
the Database Plugin is designed to accept an XML <connection>

element from a JBJF Batch Definition file and return a generic

java.sql.Connection. Tasks can now be written to the

IJBJFPluginDatabase interface and are insulated from the specific

JDBC database type (MS SQL Server, Oracle, MySQL).
The JBJF Team has plans to expand the Plugins to the following:
Email
A simple API that provides an email service for your batch process

and/or individual tasks. A batch process and/or task will have the

ability to dispatch email along with various file attachments.
Utility
A simple API that allows you to attached lists, collections, reporting

or other free form objects to a given task during processing.

Working with JBJF I noticed a need to have values that get created in

one task available for use in another task. While the Job Stack can

provide this functionality, the job stack keys need to be hard coded

into the <task> elements as <resource> elements.
Plugins Tutorials - Version 1.3.0
Page
6
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
JBJF Plugin Categories and Interfaces
In the Plugins User Guide we discussed the various categories of Plugins and their

supporting Interfaces and Abstracts. As a repeat, those concepts are presented here.

The following table outlines the Plugin Categories and the Interfaces/Abstracts that

support them:
Plugin Category
Interface
Asbtract
Cipher
IJBJFPluginCipher
IAbstractJBJFPluginCipher
Database
IJBJFPluginDatabase
IAbstractJBJFPluginDatabase
Both Interfaces extend the base Interface IJBJFPlugin. The IJBJFPlugin provides a set of

“core” attributes listed below. No matter what category of Plugin you create, they will

all have the following core properties:

Id

Name

Type

Active
We’ll see in the next section just how these properties play a role in identifying, locating

and managing our plugins. As a refresher from the User Guide, you generally wouldn’t

extend or implement the IJBJFPlugin Interface directly unless you had need of intimate

control and/or you were introducing a new “category” of Plugin. The IJBJFPlugin serves

as the connector between JBJF and Java.
During the start up cycle in JBJF, a Service Loader API is created and utilized to search

and load all the classes that implement or extend (in some fashion) the IJBJFPlugin

interface. Once loaded, your batch process is free to cast the Plugins into their usable

forms with the IJBJFPluginCipher and IJBJFPluginDatabase.
Plugins Tutorials - Version 1.3.0
Page
7
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Plugin Definitions
So the IJBJFPlugin provides the connector between JBJF and Java. And your tasks then

cast those generic classes into the specific “category” of Plugin using the Cipher and

Database Interfaces. The second piece of the Plugin puzzle is how JBJF associates the

Plugin to the Tasks. How do we tell JBJF I want to use this Plugin with that Task?
Like most JBJF flexible constructs, we indicate the plugin association in the JBJF Batch

Definition file using a new XML element called plugin-definition. The Plugin Definition

provides a simple indicator of what plugins are needed for the batch process. Then we

use the <resource> cache in the individual Tasks to associate the Plugin to the Task.
The following is a sample snippet of plugin-definitions:

<!--
PLUGIN DEFINITIONS: Optional
Use these to define various plugins for the batch process. Then
list any plugins you need per task.
-->

<
jbjf-plugins
>

<
plugin-definition


id
=
"default-cipher"


name
=
"jbjf-cipher"


type
=
"org.jbjf.plugin.IJBJFPluginCipher"


active
=
"true"
>

<
class
>
org.jbjf.services.impl.DefaultCipher
</
class
>

</
plugin-definition
>

<
plugin-definition


id
=
"sql-server-persistent"


name
=
"sql-server-database"


type
=
"org.jbjf.plugin.IJBJFPluginDatabase"


active
=
"true"
>

<
class
>
org.jbjf.services.db.MSSQLServerJBJFService
</
class
>

</
plugin-definition
>

<
plugin-definition


id
=
"sql-server-not-persistent"


name
=
"sql-server-database"


type
=
"org.jbjf.plugin.IJBJFPluginDatabase"


active
=
"true"
>

<
class
>
org.jbjf.services.db.MSSQLLocalJBJFService
</
class
>

</
plugin-definition
>

<
plugin-definition


id
=
"oracle-database"


name
=
"oracle-database"


type
=
"org.jbjf.plugin.IJBJFPluginDatabase"


active
=
"true"
>

<
class
>
org.jbjf.services.db.OracleJBJFService
</
class
>

</
plugin-definition
>

</
jbjf-plugins
>
You’ll notice that each plugin-definition comes with a core set of attributes, id, name,

type and active. These in fact map directly to the core properties for the

Plugins Tutorials - Version 1.3.0
Page
8
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
IJBJFPlugin/IAbstractJBJFPlugin classes. The additional <class> element is the actual

name of your Plugin class, eventually used for casting the plugin to it’s true form in a

JBJF task.
Plugins Tutorials - Version 1.3.0
Page
9
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Creating a JBJF Plugin
Now that we’ve revisited the Plugin fundamentals, let create a simple Cipher plugin.
Start by opening up your Eclipse Workspace and Creating a new Java project called my-
cipher-plugin. Accept all the defaults for the moment and get the project created.

Then add a new package in your source folder called org.jbjf.cipher.plugins. Your

project should be similar to the following:
Next, open up the CVS perspective and check out the JBJF source from SourceForge,

anonymous CVS connection information is available from SourceForge.net. For

stability, it’s best to Check out a Tagged Version of the source, not the HEAD. Any

Tagged version 1.3.0(+) or better is probably sufficient. The other option is to

download a pre-built JBJF bundle in a compiled/runtime state. But you’ll need to

include this runtime in the Build Path of your plugin project.
Plugins Tutorials - Version 1.3.0
Page
10
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Create a new Java class, MyCipherPlugin (or similar name) in your source package and

extend the IAbstractJBJFPluginCipher. You are free to implement the IJBJFPluginCipher

Interface, but you’ll need to do extra work on the getters/setters for the class

properties.
Plugins Tutorials - Version 1.3.0
Page
11
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Plugins Tutorials - Version 1.3.0
Page
12
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Make sure the Inherited abstract methods option is checkmarked. I generally

checkmark the Constructors from superclass and Generate comments options as well.

The public static void main() option should NOT be checked.
Eclipse will generate a skeleton class with the abstract methods decryptString(),

encryptString() and initPlugin() ready to go:

/* (non-Javadoc
)
* @see

org.jbjf.plugin.IAbstractJBJFPluginCipher#decryptString(java.lang.Strin
g)
*/

@Override

public
String decryptString( String cipherText ) {
Plugins Tutorials - Version 1.3.0
Page
13
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework

//
TODO
Auto-generated method stub

return

null
;
}

/* (non-Javadoc
)
* @see

org.jbjf.plugin.IAbstractJBJFPluginCipher#encryptString(java.lang.Strin
g)
*/

@Override

public
String encryptString( String clearText ) {

//
TODO
Auto-generated method stub

return

null
;
}

/* (non-Javadoc
)
* @see org.jbjf.plugin.IAbstractJBJFPlugin#initPlugin(org.jbjf.xm
­
l.JBJFPluginDefinition, org.jbjf.util.APILog4j)
*/

@Override

public

void
initPlugin( JBJFPluginDefinition jobPlugin ,APILog4j

logFile )

throws
Exception {

//
TODO
Auto-generated method stub
}
For simplicity, we won’t implement a complex encryption/decryption, but instead just

have logging debug statements that echo the text parameters passed in to the Log4j.

For the initPlugin(), put in the following code snippet to implement a very simple

initialization:

public

void
initPlugin (
JBJFPluginDefinition jobPlugin
,APILog4j logFile
)
throws
Exception {
setPluginId ( jobPlugin.getPluginId() );
setPluginName ( jobPlugin.getPluginName() );
setPluginType ( jobPlugin.getPluginType() );
setPluginActive ( jobPlugin.isPluginActive() );
setLog ( logFile );
}
The initPlugin takes two parameters, a JBJFPluginDefinition which is a Java Object

representation of a <plugin-definition> XML element from the JBJF Batch Definition file.

The second is the current JBJF Log4j object (APILog4j), which provides a way to have the

Plugin output log statements and information should it need to.
For the decryptString() and encryptString() we just want to put some log4j statements

that output the text parameter passed in. Like most JBJF objects, you can use the

getLog() to return the current log4j object:

/* (non-Javadoc
)
* @see

org.jbjf.plugin.IAbstractJBJFPluginCipher#decryptString(java.lang.Strin
g)
*/
Plugins Tutorials - Version 1.3.0
Page
14
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework

@Override

public
String decryptString( String cipherText ) {
getLog().debug(
"MyCipherPlugin.decryptString("
+ cipherText +

"]"
);

return
cipherText;
}

/* (non-Javadoc
)
* @see

org.jbjf.plugin.IAbstractJBJFPluginCipher#encryptString(java.lang.Strin
g)
*/

@Override

public
String encryptString( String clearText ) {
getLog().debug(
"MyCipherPlugin.encryptString("
+ clearText +

"]"
);

return
clearText;
}
The last piece for the plugin is to create a new Folder in the source folder of the plugin

project called META-INF/services. In this new folder create a simple text file call

org.jbjf.plugin.IJBJFPlugin, no file extension. Edit the file and put the fully qualified

name of your Plugin class, org.jbjf.cipher.plugins.MyCipherPlugin.
With our Plugin coded, we’re ready to try it out. Before we can do that, we need a JBJF

Batch Process written for version 1.3.0(+) or better. Again, create a new Java project in

your Eclipse workspace called my-cipher-test (or similar). Accept all the default and

then create a package in there called org.jbjf.tasks.test. Don’t link this project to your

plugin project. Your project should be similar to the following:
Plugins Tutorials - Version 1.3.0
Page
15
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Now create a series of folders in my-cipher-test project:

etc

logs

plugins
Create a new JBJF Batch Definition file in the ./etc folder called my-cipher-test.xml. In

here, just put in the bare essentials for elements. I usually copy an existing Batch

Definition file and just change it. For ease, I’ve put the Batch Definition file in the

Appendix of this tutorial and you can also get the source code from the JBJF Website for

this tutorial as well.
The key component in this Batch Definition file is the <jbjf-plugins> element, specifically

the <plugin-definition> element for your Plugin:

<!--
PLUGIN DEFINITIONS: Optional
Use these to define various plugins for the batch process. Then
list any plugins you need per task.
-->

<jbjf-plugins>

<plugin-definition


id
=
"default-cipher"


name
=
"my-cipher-test"


type
=
"org.jbjf.plugin.IJBJFPluginCipher"

Plugins Tutorials - Version 1.3.0
Page
16
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework

active
=
"true"
>

<class>
org.jbjf.cipher.plugins.MyCipherPlugin
</class>

</plugin-definition>

</jbjf-plugins>
Note the <class> element contains the fully qualified class name for your Plugin class.

The type attribute contains the “Interface” of the class, NOT the Abstract

extension...very important!
In our <jbjf-tasks> element we have both our Task classes along with a <resource>

element that points to the plugin:

<jbjf-tasks>

<task

name
=
"t001"

order
=
"1"

active
=
"true"
>

<class>
org.jbjf.tasks.test.MyCipherTask001
</class>

<resource

type
=
"plugin-cipher"
>
default-cipher
</resource>

</task>

<task

name
=
"t002"

order
=
"2"

active
=
"true"
>

<class>
org.jbjf.tasks.test.MyCipherTask002
</class>

<resource

type
=
"plugin-whatever"
>
default-cipher
</resource>

</task>

</jbjf-tasks>
The <resource> type attribute should be named “plugin-<something>”, where

<something> can really be anything within reason, but it must be UNIQUE!. By default,

the AbstractTask will now pre-process <resource> elements with a type attribute prefix

of “plugin”. HOWEVER, it should be noted that the following will NOT work:

<jbjf-tasks>

<task

name
=
"t001"

order
=
"1"

active
=
"true"
>

<class>
org.jbjf.tasks.test.MyCipherTask001
</class>

<resource

type
=
"plugin-cipher"
>
default-cipher
</resource>

<resource

type
=
"plugin-string"
>
my text value
</resource>

</task>

</jbjf-tasks>
The type=”plugin-string”, while intended to be a simple text string resource, will be

interpreted by AbstractTask as a <plugin-definition> called “my text value”. Basically,

the plugin prefix is now a reserved type attribute for JBJF resources.
Now open up both Task classes in the Java Editor. The <resource> element has linked

the Plugin to our tasks and now we need to write the Java code on how we want to use

that Plugin. For this tutorial we’re keeping it simple, we’ll pass the Plugin a text string

and it will get echoed out to the logfile and/or console.
By the time runTask() is called a number of events have occurred within JBJF. During

the JBJF startup cycle, the Plugins get loaded by the Java class loader. JBJF has rendered

the Plugins into a runtime state and they are cast into the generic IJBJFPlugin. The

Plugins Tutorials - Version 1.3.0
Page
17
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Batch Definition file has been parsed and the “link” between the Plugin and the Tasks

has been made using the <plugin-definition> elements and the <resource> elements. In

short, much of the mundane Plugin management has been taken care of by JBJF.
So, you may remember from the Plugins User Guide there are two getter methods, one

at the batch level, one at the task level, that provide access to the rendered (runtime)

Plugins:
Batch – getBatchPlugins() – reached through the JBJFBatchDefinition object.
Task – getTaskPlugins()
Both return a special collection object, JBJFPluginsCache, which operates like a

HashMap using a key to lookup a Plugin. While both cache objects contain Plugins

rendered to the IJBFPlugin interface, the content of each cache is slightly different. The

Batch level cache contains “all” the Plugins for the entire batch process while the Task

cache only contains plugins for the Task...essentially plugins associated to the task using

<resource> elements. No matter which cache you use, a lookup is done using the id

attribute of the <plugin-definition>.
Now that you understand the data architecture of the Plugins we can code our

runTask() methods. Use the getTaskPlugins() to lookup our plugin and make the call to

encryptString() and decryptString(). The following code snippet from the

MyCipherTask001 illustrates the calls:
// Grab the <plugin-definition>, has the id...
JBJFPluginDefinition lpluginCipher = (JBJFPluginDefinition)getRe
­
sources().get(

"plugin-cipher"
);
// RUNTIME PLUGINS :
// Grab the runtime plugins from the task cache...
IJBJFPluginCipher theCipher = getTaskPlugins().getCipherPlugin(lplu
­
ginCipher.getPluginId());
getLog().debug(
"Plugin ID.........["
+ theCipher.getPluginId() +
"]"
);
getLog().debug(
"Plugin Cipher Key.["
+ theCipher.getCipherKey() +
"]"
);
getLog().debug(
"Plugin Name.......["
+ theCipher.getPluginName() +

"]"
);
getLog().debug(
"Plugin Type.......["
+ theCipher.getPluginType() +

"]"
);
getLog().debug(
"Plugin Active.....["
+ theCipher.getPluginActive() +
"]"

);
getLog().debug(
"Decrypt Call......["
+ theCipher.de
­
cryptString(
"MyTaskCipher001 decrypt call"
) +
"]"
);
getLog().debug(
"Encrypt Call......["
+ theCipher.en
­
cryptString(
"MyTaskCipher001 encrypt call"
) +
"]"
);
The only meaningful code in here occurs in the first two lines. The first line will lookup

the <plugin-definition> from the <resource> cache, receiving a JBJFPluginDefinition

object. We then use the id from that Plugin Definition object to go lookup the runtime

Plugins Tutorials - Version 1.3.0
Page
18
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Plugin stored in the Task Plugins cache and cast it into the correct Plugin Category

interface. Once cast, we are free to use it to perform work within the task, specifically

the encryption and decryption of text.
A similar code snippet in MyCipherTask002 will implement the Plugin there...make sure

and change the lookup name and id though to match the ones in your JBJF Batch

Definition file.
Almost done. Now create a log4j properties file, again you can use the one included in

the tutorial source and I’ve put a working one in the Appendix of the tutorial.

Whatever category you place in the log4j properties file should also be placed in the

<log-definition> of the JBJF Batch Definition file:
<jbjf-logs>

<log-definition

name
=
"org.adym.batch"
>

<log4j

category
=
"org.adym.batch"
>
./etc/log4j.properties
</log4j>

</log-definition>
</jbjf-logs>
At this point you should have two Java projects in your workspace similar in structure

and content like the following:
Plugins Tutorials - Version 1.3.0
Page
19
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Now Export (not Build) the Plugin project as a JAR file using the Eclipse built-in Export

function, File > Export. Your destination for the jarfile will be my-cipher-test/plugins.
Plugins Tutorials - Version 1.3.0
Page
20
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Plugins Tutorials - Version 1.3.0
Page
21
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Refresh the my-cipher-test project to ensure that the jarfile appears as expected:
Plugins Tutorials - Version 1.3.0
Page
22
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Select the my-cipher-test project and the Run > Run Configurations... from the Eclipse

menus. Under the Java Application entry create a new Run Configuration and name it

my-cipher-test. In the Main Tab, for the Main class: choose the

org.jbjf.core.DefaultBatch class...this is a pre-built batch process class included with

JBJF. Then verify/check the Project: and make sure it’s my-cipher-test.
Plugins Tutorials - Version 1.3.0
Page
23
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
In the Arguments Tab, set the Program arguments: to ./etc/my-cipher-test.xml. We are

passing our new JBJF Batch Definition file into the batch process.
Plugins Tutorials - Version 1.3.0
Page
24
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Apply all the changes to Save the configuration. Then click Run. If all goes well, your

calls within the Task classes to the Cipher Plugin will appear in the logfile as well as the

console. The following log snippet is from my run.
2010-01-20 15:57:22,951 [main] DEBUG org.adym.batch - Found Plugin null

class [org.jbjf.cipher.plugins.MyCipherPlugin]
2010-01-20 15:57:22,952 [main] DEBUG org.adym.batch - Found Plugin de
­
fault-cipher class [org.jbjf.cipher.plugins.MyCipherPlugin]
2010-01-20 15:57:22,968 [main] INFO org.adym.batch - Starting jbjf-
generic-batch...
2010-01-20 15:57:22,968 [main] INFO org.adym.batch - Work Unit ...

Starting ...class org.jbjf.tasks.test.MyCipherTask001
2010-01-20 15:57:22,968 [main] DEBUG org.adym.batch - Initialize Work

Unit...Start...
Plugins Tutorials - Version 1.3.0
Page
25
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
2010-01-20 15:57:22,969 [main] DEBUG org.adym.batch - Gathering re
­
sources...
2010-01-20 15:57:22,969 [main] DEBUG org.adym.batch - Gathering plugin-
cipher [ default-cipher ]
2010-01-20 15:57:22,969 [main] DEBUG org.adym.batch - Initialize Work

Unit...Complete...
2010-01-20 15:57:22,970 [main] DEBUG org.adym.batch - MyCipherTask001()

... Start ...
2010-01-20 15:57:22,970 [main] DEBUG org.adym.batch - Plugin

ID.........[default-cipher]
2010-01-20 15:57:22,970 [main] DEBUG org.adym.batch - Plugin Cipher

Key.[null]
2010-01-20 15:57:22,970 [main] DEBUG org.adym.batch - Plugin

Name.......[my-cipher-test]
2010-01-20 15:57:22,970 [main] DEBUG org.adym.batch - Plugin

Type.......[org.jbjf.plugin.IJBJFPluginCipher]
2010-01-20 15:57:22,970 [main] DEBUG org.adym.batch - Plugin

Active.....[true]
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - MyCipherPlugin.
­
decryptString(MyTaskCipher001 decrypt call]
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - Decrypt

Call......[MyTaskCipher001 decrypt call]
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - MyCipherPlu
­
gin.encryptString(MyTaskCipher001 encrypt call]
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - Encrypt

Call......[MyTaskCipher001 encrypt call]
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - MyCipherTask001()

... Complete ...
2010-01-20 15:57:22,971 [main] INFO org.adym.batch - Work Unit ...

Complete ...
2010-01-20 15:57:22,971 [main] INFO org.adym.batch - Work Unit ...

Starting ...class org.jbjf.tasks.test.MyCipherTask002
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - Initialize Work

Unit...Start...
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - Gathering re
­
sources...
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - Gathering plugin-
whatever [ default-cipher ]
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - Initialize Work

Unit...Complete...
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - MyCipherTask002()

... Start ...
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - Plugin

ID.........[default-cipher]
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - Plugin Cipher

Key.[null]
2010-01-20 15:57:22,972 [main] DEBUG org.adym.batch - Plugin

Name.......[my-cipher-test]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - Plugin

Type.......[org.jbjf.plugin.IJBJFPluginCipher]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - Plugin

Active.....[true]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - MyCipherPlugin.
­
decryptString(MyTaskCipher002 decrypt call]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - Decrypt

Call......[MyTaskCipher002 decrypt call]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - MyCipherPlu
­
gin.encryptString(MyTaskCipher002 encrypt call]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - Encrypt

Call......[MyTaskCipher002 encrypt call]
2010-01-20 15:57:22,973 [main] DEBUG org.adym.batch - MyCipherTask002()

... Complete ...
Plugins Tutorials - Version 1.3.0
Page
26
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
2010-01-20 15:57:22,973 [main] INFO org.adym.batch - Work Unit ...

Complete ...
2010-01-20 15:57:22,974 [main] INFO org.adym.batch - Finishing jbjf-
generic-batch...
About half way through the log snippet you can see the first call to Task

MyCipherTask001. In here you can see the calls to the Plugin and it’s echo of the text

string passed in:
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - Decrypt

Call......[MyTaskCipher001 decrypt call]
2010-01-20 15:57:22,971 [main] DEBUG org.adym.batch - MyCipherPlu
­
gin.encryptString(MyTaskCipher001 encrypt call]
This completes the JBJF Plugins Tutorial. I hope you have questions and

suggestions...feel free to email or post on the JBJF board.
Plugins Tutorials - Version 1.3.0
Page
27
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Synopsis
JBJF Plugins provide an excellent way to extend your JBJF installation. The initial Plugins

release, version 1.3.0, focuses on two critical areas for JBJF, encryption/decryption and

databases. JBJF utilizes the built-in services API that comes with Java 6, so a move to

JBJF 1.3.0 also necessitates a move to Java 6. The services API searches for JBJF Plugins

and loads them for use with your batch process. Like all JBJF constructs, the Plugins get

defined as an XML element in the JBJF Batch Definition file. Plugins can then be

associated with Tasks using the standard task <resource> elements and accessed at two

Plugin Caches, one at the Task level, one at the Batch level.
Plugins Tutorials - Version 1.3.0
Page
28
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010
Java Batch Job Framework
Other Resources
JBJF Website –
http://jbjf.sourceforge.net/

JBJF Tutorials/Documentation -
http://jbjf.sourceforge.net/documentation.html

Plugins Tutorials - Version 1.3.0
Page
29
of
29
Author: Adym S. Lincoln
Copyright 2006-2010 JBJF. ALL RIGHTS RESERVED
Last Update
1/21/2010