Using State-Engine as an SCA Spring
component in SOA Suite 11g
OOW 2010
Guido Schmutz,
Technology Manager / Partner
Trivadis AG
23.09.2010, San Francisco
Basel · Baden · Bern · Lausanne · Zürich · Düsseldorf · Frankfurt/M. · Freiburg i. Br. · Hamburg · München · Stuttgart · Wien
Introduction
Guido Schmutz
Working for Trivadis for more than 13 years
leading and independent IT service company operating in
Germany, Austria and Switzerland
Oracle ACE Director for Fusion Middleware and SOA
Co-Author of different books
Consultant, Trainer Software Architect for Java,
Oracle, SOA and EDA
More than 20 years of software development
experience
Contact: [Link]@[Link]
Blog: [Link]
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
About Trivadis
Swiss IT consulting company
13 locations in Switzerland,
Germany and Austria
~ 540 employees
Key figures 2008
Services for more than 650 clients
in over 1‘600 projects
Over 150 service level agreements
More than 5‘000 training
participants
Research and development budget:
CHF 6.0 Mio. / EUR 3.6 Mio.
3 © 2009
Idea for this session
Test what you can really to with the Spring Component
A bit more than just another HelloWorld sample
Test Drive it with a more complex use case
Integrate an existing implemementation (Apache Commons
SCXML library) into SOA Suite as an Spring Component
By that show that a state engine offers another (sometimes better?)
approach for documenting (business) processes
Just a Proof of Concept for myself !!
Have a „sexy“ presentation topic for OOW 2010 ;-)
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Result
Not successfull !
Issues with the classloader when trying to initiate the Commons
SCXML (ClassNotFoundException)!
I‘m talking to the Oracle Development to see how to solve that!
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Summary
There can be issues with the classloader
Make sure that you test what you want to integrate right upfront
Lessons learnt: Do not create sexy and fancy abstracts just to
get accepted to OOW ;-) Or make sure before that it‘s somehow
achievable....
So this is it !???
Of course not, just changed my topic slightly and I will present
some interesting use cases with the Spring Component in SOA
Suite 11g and in a 2nd part the Apache Commons SCXML
library!
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
SOA Suite 11g Spring Component /
Apache Commons SCXML
OOW 2010
Guido Schmutz,
Technology Manager / Oracle
ACE Director
Partner Trivadis AG
23.09.2010, San Francisco
Basel · Baden · Bern · Lausanne · Zürich · Düsseldorf · Frankfurt/M. · Freiburg i. Br. · Hamburg · München · Stuttgart · Wien
Agenda
Spring Component of SOA Suite 11g
Introduction
Hello World
“Advanced” Use Cases
State Machine and Apache Commons
SCXML
Data are always What are State Machines
part of the game. What is Apache Commons SCXML
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
SOA Suite 11gR1 PS2 Architecture
BPMN 2.0,
Shared BPMN
BPEL
BPA
Model Web based customization
Rich End User Interaction
Customer
Notify Download
Customer User Video Sales Rep
Create and Process Wait Call
Submit Order Payment 3 days Customer
Copy to
S3
Business View
Workspace Process Portal MS Office
(WC spaces)
BPM Studio Process Composer
(with Business and IT views)
Human
Workflow Business
BPEL BPMN (+AMX, AG,
Mediator Spring
Rules
Orgn)
B2B
Unified Runtime
Process Common JCA-based connectivity infrastructure Policy Manager
Analytics Optimized
binding
BAM
Proc Cubes Oracle Service Bus
EM console
+BPMN Screens
Repository
Repository
© 2009
9
The Spring component
„Officially“ introduced with SOA Suite 11g PS2
Allows to publish Java Interfaces implemented by Spring beans as a
service that can be used inside a composite application
By that
part of the logic required in a SOA composite can be easily implemented
in Java an used like any other service component
a Spring Ban can be reused within the composite and even outside the
composite either as an EJB or as a Web Service
Additionally the Java beans in the Spring Context component can
call services exposed by other Service components and Adapter
bindings
Java bean can retrieve records from a database table using the DB
adapter
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Agenda
Spring Component of SOA Suite 11g
Introduction
Hello World
“Advanced” Use Cases
State Machine and Apache Commons
SCXML
Data are always What are State Machines
part of the game. What is Apache Commons SCXML
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Hello World – Step 1
The HelloWorldImpl POJO used inside a Spring component
Lessons learnt: Make sure to compile classes before wiring!
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Hello World – Step 2
Add the GreetingProvider strategy interface to provide an
extended greeting message
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Hello World – Step 3
Implement the GreetingProvider as a
separate Spring component and wire it to
the HelloWorld component
© 2009
Hello World – Step 4
Implement the GreetingProvider as a Mediator component
and wire it to the HelloWorld component
Lessons learnt: if you delete a wire, the <sca:reference> element
is also removed
© 2009
<sca:service> Element
Declares a Spring bean that SCA exposes as a service
Takes the following attributes
Name
the name of the service (required)
Type
The fully qualified Java type of the Java class to be exposed as an SCA
service (required)
Target
The bean to be exposed as a service (required)
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
<sca:reference> Element
Declares a Spring bean representing an SCA service external to
the Spring application context
Takes the follwing attributes
Name
The name of the reference (required)
Type
The fully-qualified Java type of the interface or class representing the
remote service (required)
Default
The target bean for the reference if none is specified (optional)
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Callback
the concept of callbacks does not exist in the spring framework
For Oracle SOA Suite a callback is specified as a 2nd port type for
[Link] or a 2nd Java name for [Link]
The spring metadata has only sca:services and sca:references and no
way to specify a callback
To design a callback with spring, you must provide sca:services and
sca:references with a specific name
create a sca:service and sca:reference using naming conventions of
someService and someServiceCallback
Oracle SOA Suite recognizes this convention and creates a callback
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Agenda
Spring Component of SOA Suite 11g
Introduction
Hello World
“Advanced” Use Cases
State Machine and Apache Commons
SCXML
Data are always What are State Machines
part of the game. What is Apache Commons SCXML
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Use Case 1: Accessing the Spring Context
Use Case: Want to access/lookup another bean from the spring
context
Idea: Implement the Lifecycle Interface
Lessons learnt: Only a BeanFactory and not an ApplicationContext
is created!
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Use Case 2: Groovy Script
Use Case: Want to use the Spring Dynamic Language Support to
execute a Groovy Script
Idea: use the <lang:groovy> tag and reference the script and
put the external libraries in SCA-INF/lib of the SOA project
Lessons learnt: Classloader is not my friend!
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Use Case 3: Executing Task asynchronously
Use Case: Want to execute a possible long running Java method
asynchronously
Idea: use the Spring TaskExecutor abstraction
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Use Case 4: Schedule a Job
Use Case: Want to Schedule a job/task/service to run repeatedly
Idea: use a Timer to schedule the call of a „service references“
Lessons learnt: „free-floating“ Spring bean (timerFactory) is not initialized!
it need to referenced from a bean which is externalized as a service!
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Use Case 5: Schedule Job to
run delayed
Use Case: Want to schedule a method/service to run delayed
Idea: use a Timer and schedule the call of a „service references“
through a service call
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Use Case 6: Caching
Use Case: Want to cache some information and access it in a
next request
Idea: use a Map and store the information in there
Could be further extended by using Oracle Coherence to get
access to the Grid !
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Summary
Spring Component is a very nice and long awaited feature!
Uses cases for it are endless….. Just presented some use cases
to whet your appetite!
Only use the Spring Component if there is no out-of-the-box
feature offered by SOA Suite itself
Make sure that your external library works before you invest too
much time!
Actual books where you’ll
find more information
about SOA Suite:
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Agenda
Spring Component of SOA Suite 11g
Introduction
Hello World
“Advanced” Use Cases
State Machine and Apache Commons
SCXML
Data are always What is a State Machine
part of the game. What is Apache Commons SCXML
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Indroduction
A state describes the condition of an object at a given point in its
lifetime
"A state is a condition or situation during the life of an object
during which it satisfies some condition, performs some
activity, or waits for some event"
[Booch et al. (1999) UML Language User
Guide, p291]
A state diagram describes all possible states of an object & the
paths to get from one state to another when an external event is
received
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
What is a state machine ?
A state machine diagram models the behaviour of a single
object/system
specifies the sequence of events that an object/system goes
through during its lifetime in response to events
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Building Blocks
Start and End States Transitions
State Actions Self Transitions
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Building Blocks
Compound States History State
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Building Blocks
Concurrent Blocks
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Agenda
Spring Component of SOA Suite 11g
Introduction
Hello World
“Advanced” Use Cases
State Machine and Apache Commons
SCXML
Data are always What is a State Machine
part of the game. What is Apache Commons SCXML
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
What is State Chart XML (SCXML)
Generic and environment agnostic markup language for state
machine definition
W3C Working Draft (13 May 2010)
[Link]
Based on UML 2.0 and Harel State transition tables
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
SCXML features
States and transitions
Composite, Orthogonal and Final
Events, guards and targets
Data Model
Pluggable data representation and expression language
Executable content
On entry, exit or transition
Extensible
External communications module
Send, cancel
Invoke, Finalize
History
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Apache Commons SCXML
[Link]
Implements State Chart XML (SCXML)
The only Java engine which implements SCXML (as far as I know)
The "standard actions" defined by the SCXML specification are
<var>, <assign>, <log>, <send>, <cancel>, <if>, <elseif>,
<else>.
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
State Actions
stm state-action
Initial
first
+ entry / log entering
+ exit / log exiting
[Link]
next
Final
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
stm transitions
Transitions (simple, condition, self) Initial
[Link]
[counter < 4]
main
[Link]
[counter >= 4]
processing
Final
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
stm parallel
parallel
Parallel States
[para-1]
para11 para12
to.para12
Initial [para-2]
para21 para22
to.para22
Synch
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
stm timeout
Timeout with Custom Action Initial
timeout
start-state [after expired
2sec]
SCXML can be extended with
custom action [Link] [Link]
Used for timeout transitions
next
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Send action
<send> can used to send events and data to external systems,
including external SCXML Interpreters, or to raise events in the
current SCXML session
stm send-internal
Initial
main
+ entry / signal event "[Link]"
[Link] [Link]
processing Error
Final
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Using SCXML in a SOA
Implemented a Spring Wrapper around Commons SCXML
Exposed a Web Service interface through Spring-WS
Created Publisher compontents to publish/signal events via Event
Delivery Network (EDN) or Web Services
cmp SOA-State-Engine
EDNPublisher
signal
createInstance StateEngine listener
send
triggerEvent
WebServ icePublisher
signal
SOA Suite 11g Spring Component / Apache Commons SCXML © 2009
Thank you!
ODTUG 2010
Guido Schmutz,
Technology Manager / Partner
Trivadis AG
29.6.2010, Washington
Basel · Baden · Bern · Lausanne · Zürich · Düsseldorf · Frankfurt/M. · Freiburg i. Br. · Hamburg · München · Stuttgart · Wien