Using state-engine-as-sca-component-final

47
Basel Bern Lausanne Zurich Düsseldorf Frankfurt/M. Freiburg i. Br. Hamburg Munich Stuttgart Vienna Using State-Engine as an SCA Spring component in SOA Suite 11g DOAG Konferenz 2010 Guido Schmutz Technology Manager Oracle ACE Director for FMW & SOA 17.11.2010, Nürnberg

description

Integrate a state engine (Apache Commons SCXML) as a Spring Component in Oracle SOA Suite 11g. It shows some "advanced" use cases for the Spring Component in SOA Suite 11g.

Transcript of Using state-engine-as-sca-component-final

Page 1: Using state-engine-as-sca-component-final

Basel Bern Lausanne Zurich Düsseldorf Frankfurt/M. Freiburg i. Br. Hamburg Munich Stuttgart Vienna

Using State-Engine as an SCA Spring component in SOA Suite 11g

DOAG Konferenz 2010

Guido SchmutzTechnology ManagerOracle ACE Director for FMW & SOA

17.11.2010, Nürnberg

Page 2: Using state-engine-as-sca-component-final

© 2010SOA Suite 11g Spring Component / Apache Commons SCXML

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: [email protected] Blog: http://guidoschmutz.wordpress.com/

Page 3: Using state-engine-as-sca-component-final

© 2010

Trivadis facts & figures

Using State-Engine as an SCA Spring component in SOA Suite 11g 3

IT SOLUTIONS, SERVICES, & PRODUCTS

TECHNOLOGIESOracle, Microsoft, IBM, Open Source

Integration, Application Performance Management, Security

Training Managed Services

InfrastructureEngineering

Application Development

Enterprise Content Management

BUSINESS INTEGRATION SERVICES

ITdepartments

Businessdepartments

CUSTOMER

Business Intelligence

11 Trivadis locations with more than 540 employees

Financially independent and sustainably profitable

Key figures 2009

Revenue CHF 100 / EUR 66 mio.

Services for more than 650 clients in over 1‘600 projects

Over 160 Service Level Agreements

More than 5'000 training participants

Research and development budget: CHF 5.0 / EUR 3.3 mio.

Page 4: Using state-engine-as-sca-component-final

© 2010Using State-Engine as an SCA Spring component in SOA Suite 11g 4

Why we are special

Customer-specific solution competence and

vendor independence

offers substantiated techniques and skills as well as self-developed approaches

guarantees repeatable quality and a safe execution

Technology competence offers more than 15 years of expertise in Oracle, Microsoft, IBM, and open source

has its own Technology Center and strives for technological excellence

Solution and integration expertise

has a wide and cross-sectoral customer basis and more than 1600 projects every year

Combines technological expertise with an understanding of the specific business needs of the client

Support for the entire IT project lifecycle

has a modular portfolio of services for the entire IT project lifecycle

provides the appropriate combination of solutions and services for every „level of maturity“

Page 5: Using state-engine-as-sca-component-final

© 2010

Idea for this session

Test what you can really do 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 ;-)

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 6: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 7: Using state-engine-as-sca-component-final

© 2010

What is State Chart XML (SCXML) ?

Generic and environment agnostic markup language for state machine definition W3C Working Draft (13 May 2010) http://www.w3.org/TR/scxml/

Based on UML 2.0 and Harel State transition tables

Features States and transitions Data Model Executable content External communications module History

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 8: Using state-engine-as-sca-component-final

© 2010

What is Apache Commons SCXML ?

http://commons.apache.org/scxml/

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>.

Using State-Engine as an SCA Spring component in SOA Suite 11g

stm state-action

first

+ entry / log entering+ exit / log exiting

next

Final

Initial

to.next

Page 9: Using state-engine-as-sca-component-final

© 2010

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!

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 10: Using state-engine-as-sca-component-final

© 2010

Summary

There can be issues with the classloader

Make sure that you test what you want to integrate right upfront

So this is it !???

Of course not, just changed my agenda slightly and I will present some interesting use cases with the Spring Component in SOA Suite 11g

Using State-Engine as an SCA Spring component in SOA Suite 11g

Lessons learnt: Do not create sexy and fancy abstracts just to get accepted to a conference ;-) Or make sure before that it‘s somehow achievable....

Page 11: Using state-engine-as-sca-component-final

© 2010

Agenda

Data are always part of the game.

Spring Component of SOA Suite 11g Introduction Hello World “Advanced” Use Cases

State Machine and Apache Commons SCXML What are State Machines What is Apache Commons SCXML

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 12: Using state-engine-as-sca-component-final

© 2010

SOA Suite 11gR1 PS2 Architecture

12

Oracle Restricted and Confidential

Unified Runtime

BPMN

Policy ManagerOptimized

binding

Human Workflow

(+AMX, AG, Orgn)

Business Rules

Oracle Service Bus

Common JCA-based connectivity infrastructure

Repository

EM console+BPMN Screens

BAM

B2B

Mediator

Workspace Process Portal(WC spaces)

MS Office

Create and Submit Order

ProcessPayment

NotifyUser

DownloadVideo

Wait3 days

Call Customer

Customer

Customer

Sales Rep

Copy toS3

Create and Submit Order

ProcessPayment

NotifyUser

DownloadVideo

Wait3 days

Call Customer

Customer

Customer

Sales Rep

Copy toS3

BPM Studio(with Business and IT views)

Shared BPMN Model

Business View

BPA

BPMN 2.0, BPEL

Rich End User InteractionWeb based customization

Process Composer

BPEL

ProcessAnalytics

Proc Cubes

Spring

Page 13: Using state-engine-as-sca-component-final

© 2010

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 implemented in

Java and 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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 14: Using state-engine-as-sca-component-final

© 2010

Agenda

Data are always part of the game.

Spring Component of SOA Suite 11g Introduction Hello World “Advanced” Use Cases

State Machine and Apache Commons SCXML What are State Machines What is Apache Commons SCXML

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 15: Using state-engine-as-sca-component-final

© 2010

The HelloWorldImpl POJO used inside a Spring component

Hello World – Step 1

Using State-Engine as an SCA Spring component in SOA Suite 11g

Lessons learnt: Make sure to compile classes before wiring!

Page 16: Using state-engine-as-sca-component-final

© 2010

Hello World – Step 2

Add the GreetingProvider strategy interface to provide an extended greeting message

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 17: Using state-engine-as-sca-component-final

© 2010

Hello World – Step 3

Implement the GreetingProvider as a separate Spring component and wire it to the HelloWorld component

Same type

Page 18: Using state-engine-as-sca-component-final

© 2010

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

Page 19: Using state-engine-as-sca-component-final

© 2010

<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)

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 20: Using state-engine-as-sca-component-final

© 2010

<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)

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 21: Using state-engine-as-sca-component-final

© 2010

Different granularities of componentization

Single SCA-level component / one spring bean

Single SCA-level component /multiple spring beans

Multiple SCA-level Spring components

SCA Spring Component and Meditor component

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 22: Using state-engine-as-sca-component-final

© 2010

Agenda

Data are always part of the game.

Spring Component of SOA Suite 11g Introduction Hello World “Advanced” Use Cases

State Machine and Apache Commons SCXML What are State Machines What is Apache Commons SCXML

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 23: Using state-engine-as-sca-component-final

© 2010

Use Case 1: Accessing the Spring Context

Use Case: Want to access/lookup another bean from the spring context

Idea: Implement the Lifecycle Interface

Using State-Engine as an SCA Spring component in SOA Suite 11g

Lessons learnt: Only a BeanFactory and not an ApplicationContext is created!

Page 24: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Lessons learnt: Classloader is not my friend!

Page 25: Using state-engine-as-sca-component-final

© 2010

Use Case 3: Executing Task asynchronously

Use Case: Want to execute a possible long running Java method asynchronously

Idea: use the Spring TaskExecutor abstraction

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 26: Using state-engine-as-sca-component-final

© 2010

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“

Using State-Engine as an SCA Spring component in SOA Suite 11g

Lessons learnt: „free-floating“ Spring bean (timerFactory) is not initialized! need to be referenced from a bean which is externalized as a service!

Page 27: Using state-engine-as-sca-component-final

© 2010

Use Case 5: Schedule Job torun 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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 28: Using state-engine-as-sca-component-final

© 2010

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 !

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 29: Using state-engine-as-sca-component-final

© 2010

Use Case 7: JMX managed beans

Use Case: Want to change the properties of a Spring bean at runtime

Idea: use the Spring JMX abstraction to externalize a Spring bean as an MBean

Using State-Engine as an SCA Spring component in SOA Suite 11g

Lessons learnt: Only a BeanFactory and not an ApplicationContext is created!

Page 30: Using state-engine-as-sca-component-final

© 2010

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’llfind more informationabout SOA Suite:

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 31: Using state-engine-as-sca-component-final

© 2010

Agenda

Data are always part of the game.

Spring Component of SOA Suite 11g Introduction Hello World “Advanced” Use Cases

State Machine and Apache Commons SCXML What is a State Machine What is Apache Commons SCXML

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 32: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 33: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 34: Using state-engine-as-sca-component-final

© 2010

Building Blocks

Start and End States

State Actions

Transitions

Self Transitions

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 35: Using state-engine-as-sca-component-final

© 2010

Building Blocks

Compound States History State

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 36: Using state-engine-as-sca-component-final

© 2010

Building Blocks

Concurrent Blocks

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 37: Using state-engine-as-sca-component-final

© 2010

Agenda

Data are always part of the game.

Spring Component of SOA Suite 11g Introduction Hello World “Advanced” Use Cases

State Machine and Apache Commons SCXML What is a State Machine What is Apache Commons SCXML

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 38: Using state-engine-as-sca-component-final

© 2010

What is State Chart XML (SCXML)

Generic and environment agnostic markup language for state machine definition W3C Working Draft (13 May 2010) http://www.w3.org/TR/scxml/

Based on UML 2.0 and Harel State transition tables

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 39: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 40: Using state-engine-as-sca-component-final

© 2010

Apache Commons SCXML

http://commons.apache.org/scxml/

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>.

Using State-Engine as an SCA Spring component in SOA Suite 11g

Page 41: Using state-engine-as-sca-component-final

© 2010

State Actions

Using State-Engine as an SCA Spring component in SOA Suite 11g

stm state-action

first

+ entry / log entering+ exit / log exiting

next

Final

Initial

to.next

Page 42: Using state-engine-as-sca-component-final

© 2010

Transitions (simple, condition, self)

Using State-Engine as an SCA Spring component in SOA Suite 11g

stm transitions

main

processing

Initial

Final

to.processing[counter >= 4]

fi le.received[counter < 4]

Page 43: Using state-engine-as-sca-component-final

© 2010

Parallel States

Using State-Engine as an SCA Spring component in SOA Suite 11g

stm parallel

parallel

[para-1]

[para-2]

para11

Initial

para12

para21 para22

Synch

to.para12

to.para22

Page 44: Using state-engine-as-sca-component-final

© 2010

Timeout with Custom Action

SCXML can be extended with custom action Used for timeout transitions

Using State-Engine as an SCA Spring component in SOA Suite 11g

stm timeout

start-state expired

next

Initial

to.next

timeout[after2sec]

to.start

Page 45: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

stm send-internal

main

+ entry / signal event "to.processing"

processing Error

Initial

Final

to.processing error.send.targetunavailable

Page 46: Using state-engine-as-sca-component-final

© 2010

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

Using State-Engine as an SCA Spring component in SOA Suite 11g

cmp SOA-State-Engine

l istenerStateEnginecreateInstance

triggerEvent

listener

send

EDNPublisher

signal

WebServ icePublisher

signal

Page 47: Using state-engine-as-sca-component-final

Basel · Baden · Bern · Lausanne · Zürich · Düsseldorf · Frankfurt/M. · Freiburg i. Br. · Hamburg · München · Stuttgart · Wien

Thank you!

ODTUG 2010

Guido Schmutz,Technology Manager / Partner Trivadis AG

29.6.2010, Washington