SlideShare a Scribd company logo
1 of 28
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
1
Session: Pattern of the Control Layer
Singleton
Service Starter
Simple Workflows
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
2
Objectives
Learn about:
✔ How to start a service at deploy time
✔ Dealing with timers
✔ The Singleton pattern in Java EE
✔ The State Pattern in conjunction with simple workflows
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
3
Some orientation
Consumer
Consumer
Layer
Integration
Layer
Business Process
Layer
Services
Layer
Component
Layer
OS
Layer
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
4
ECB Pattern
Entity Control Boundary
✔ Based upon Robustness Diagrams
(http://www.agilemodeling.com/artifacts/robustnessDiagram.htm)
➢ Boundary: user interface
➢ Control: actual process or activity
➢ Entity: a concept from an enterprise context.
✔ Elements are generic enough to be mapped either to service-
oriented or object-oriented architectures.
Boundary Control Entity
Adam Bien
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
5
Services, components and patterns
Boundary Control Entity
DAO &
Domain
Store
Generic
DAO
Singleton
Service
Starter
Dual View
SOA Facade
Lightweight
asynchronous
Facade
Multichannel
Facade
TO
&
DTO
Paginator
Bean
Locator
Multichannel
Facade
Resource
Binder
Payload
Extractor
Aynchronous
Resource
Integrator
Infrastructure
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
6
Module
Singleton
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
7
Singleton
✔ Access to limited resources needs to be shared across user
requests.
✔ Amount of active SLSB is dependent on:
➢ Parallel user requests
➢ Pool settings (min/max)
➢ Both isn't covered by spec.
✔ The solution should be portable
between app.-servers.
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
8
Singleton
✔ Most effective in terms of caches,
application-wide configuration
parameters or cyclic actions.
✔ Often combined with Service Starter
(therefore we'll combine both labs)
@Singleton(mappedName = "ejb/facade/ServiceStarter")
@Remote(ServiceStarter.class)
public class ServiceStarterBean implements ServiceStarter
{
...
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
9
Module
Service Starter
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
10
Service Starter
✔ Some logic needs to be initialized prior to the business logic
✔ Some services might depend on each other
✔ Since EJB 3.1 these initializations are specified, in EJB 3.0 they
were not.
➢ In EJB 3.1: @Startup combined with @PostConstruct
➢ In EJB 3.0: Servlet and <load-on-startup> plus CDI
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
11
Example
Think of the following:
✔ Some production data needs to be retrieved for further processing
✔ You have to integrate a 3rd
party system by means of cyclic,
synchronous calls.
✔ Maybe you want to make use of
timers, be aware, you can create
timers from MDBs or Singletons
only.
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
12
Example
✔ ServiceStarterBean
@Singleton(mappedName = "ejb/facade/ServiceStarter")
@Startup
@Remote(ServiceStarter.class)
public class ServiceStarterBean implements ServiceStarter
{
private Logger log = Logger.getLogger(ServiceStarterBean.class);
@EJB
private PollingServiceBean pollingService;
/** the timer service */
@Resource
private javax.ejb.TimerService timerService;
@PostConstruct
public void init(){
log.info("initializing");
}
...
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
13
Example
✔ ServiceStarterBean (cont.)
@Schedule(second = "*/5", minute="*", hour="*", persistent = false, info="Timer:
external polling")
public void notifyPollingService(){
this.pollingService.doPoll();
}
public void stopTimer(String timerName){
Collection<Timer> timers = this.timerService.getTimers();
for (Timer timer : timers){
if(timer.getInfo().toString().equals(timerName)){
timer.cancel();
log.info("Timer: " + timerName + " has been cancelled");
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
14
Example
✔ External configuration: ejb-jar.xml (overwrites the annotation)
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-
jar_3_1.xsd"
version="3.1">
<display-name>Pattern Training</display-name>
<enterprise-beans>
<session>
<ejb-name>ServiceStarterBean</ejb-name>
<ejb-class>de.brockhaus.userMgmt.control.ServiceStarterBean</ejb-class>
<timer>
<description>none</description>
<schedule>
<second>0/5</second>
<minute>*</minute>
<hour>*</hour>
</schedule>
<timeout-method>
<method-name>notifyPollingService</method-name>
</timeout-method>
<persistent>false</persistent>
<info>Timer: external polling</info>
</timer>
</session>
</enterprise-beans>
</ejb-jar>
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
15
Lab
Implement Service Activator
(not more than 15 min.)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
16
Module
Simple Workflows
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
17
Simple Workflow
✔ Within the control layer, it might happen, you have to perform
several (identical) steps within different services / methods:
➢ Checking for existence of x, maybe in system y
➢ Calculating amounts of a, b, c (e.g. in a production plan for a certain
period)
➢ ...
✔ You might end up in the idea of decomposition into processes and
activities
➢ Has only little to do with Java EE
➢ Inspired by State Machines and
Workflow Engines
➢ No maintenance of state of a current
workflow instance
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
18
The abstract process
An abstract superclass providing methods to:
✔ Proceed (starting the process)
✔ Initialize the process
✔ Finalize the process
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
19
The abstract process
public abstract class Process{
private Logger log = Logger.getLogger(Process.class);
public static final int PROCESS_START = 1;
public static final int PROCESS_END = 999;
private int runstate = 1;
private boolean hasFinished = false;
public synchronized void proceed() throws ProcessException{
try{
this.beforeProcess();
while (runstate != Process.PROCESS_END){
runSteps();
}
this.afterProcess();
this.end();
}
catch (ProcessException e) {
...
}
catch (Exception e){
...
}
}
...
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
20
The activity
✔ Common interface to all process related activities:
public interface ProcessActivity
{
public <T> T proceedActivity<T>();
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
21
The activity
✔ Concrete activity (example)
➢ Make use of the constructor to pass parameters
➢ Return whatever you want from processActivity
public class StepOne implements ProcessActivity
{
private Logger log = Logger.getLogger(this.getClass());
private int value;
public StepOne(int value){
this.value = value;
}
public <T> T proceedActivity(){
log.info(this.getClass().getSimpleName() + " invoked");
if(this.value > 99){
return (T) new Boolean(true);
}
else {
return (T) new Boolean(false);
}
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
22
A concrete process
✔ Extend Process and overwrite runSteps() according to the activities
public class SomeProcess extends de.brockhaus.userMgmt.util.Process
{
private int amount;
public SomeProcess(int amount)
{
this.amount = amount;
}
@Override
public void runSteps() throws ProcessException
{
switch(super.getRunstate())
{
case(1): this.triggerStepOne(); break;
case(2): this.triggerStepTwo(); break;
case(3): this.triggerStepThree(); break;
default: super.setRunstate(PROCESS_END);
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
23
A concrete process
✔ Decide upon the activities outcome what needs to be done next
private void triggerStepOne(){
StepOne one = new StepOne(amount);
boolean ret = one.proceedActivity();
if(ret){
super.setRunstate(2);
}
else{
super.setRunstate(3);
}
}
private void triggerStepTwo() {
StepTwo two = new StepTwo();
two.proceedActivity();
super.setRunstate(PROCESS_END);
}
private void triggerStepThree() {
StepThree three = new StepThree();
three.proceedActivity();
super.setRunstate(PROCESS_END);
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
24
Relation to the control layer
✔ Obviously the process has to be connected to the SLSBs of the
control layer
@Stateless
@Remote(SomeService.class)
public class SomeServiceBean implements SomeService
{
// inject SomeProcess
@Inject
private SomeProcess p;
public void someBusinessMethod(int amount) throws ProcessException
{
// set amount at process
p.setAmount(amount);
// proceed process
p.proceed();
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
25
Some conclusion
Pros
✔ It's pretty simple and effective
✔ Well designed it might help a lot to stay with DRY paradigm
✔ Provides flexibility, just exchange an activity within a process and
the process will behave different.
Cons
✔ Don't think of too many activities, don't
think of fully fledged workflows spanning
several components / modules
✔ No graphical support, no modelling
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
26
Lab
Implement Simple Workflows
(State Machine)
(not more than 15 min.)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
27
Review
Session Review:
✔ @PostConstruct, what is this good for?
✔ Can you provide some examples of using Singletons in Java EE?
✔ Why do we have processes and services in the example and what
makes the difference to workflow engines?
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
28
Recommeded reading
✔ http://java.sun.com/blueprints/corej2eepatterns/
✔ http://www.corej2eepatterns.com/Patterns2ndEd/
✔ Adam Bien, J2EE Patterns,
Addison Wesley 2002,
ISBN: 3-8273-1903-X
✔ Floyd Marinescu, Ed Roman:
Ejb Design Patterns: Advanced Patterns,
Processes, and Idioms; Wiley & Sons,
ISBN-10: 0471208310
✔ And other ...
Photo: Bundesarchiv

More Related Content

Viewers also liked

Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7
Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7
Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7Stefan Macke
 
Effiziente datenpersistierung mit JPA 2.1 und Hibernate
Effiziente datenpersistierung mit JPA 2.1 und HibernateEffiziente datenpersistierung mit JPA 2.1 und Hibernate
Effiziente datenpersistierung mit JPA 2.1 und HibernateThorben Janssen
 
Zehn Jahre JPA – Architekturkonzepte und Best Practices revisited
Zehn Jahre JPA – Architekturkonzepte und Best Practices revisitedZehn Jahre JPA – Architekturkonzepte und Best Practices revisited
Zehn Jahre JPA – Architekturkonzepte und Best Practices revisitedOPEN KNOWLEDGE GmbH
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Ryan Cuprak
 
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
50 EJB 3 Best Practices in 50 Minutes - JavaOne 201450 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014Ryan Cuprak
 
20091020 JPA2
20091020 JPA220091020 JPA2
20091020 JPA2lyonjug
 

Viewers also liked (12)

PGDAIT presentation v11
PGDAIT presentation v11PGDAIT presentation v11
PGDAIT presentation v11
 
Brockhaus Group 2014
Brockhaus Group 2014Brockhaus Group 2014
Brockhaus Group 2014
 
Bro110 5 1_software_architecture
Bro110 5 1_software_architectureBro110 5 1_software_architecture
Bro110 5 1_software_architecture
 
Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7
Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7
Von wegen schwergewichtig - Moderne Webentwicklung mit Java EE 7
 
Effiziente datenpersistierung mit JPA 2.1 und Hibernate
Effiziente datenpersistierung mit JPA 2.1 und HibernateEffiziente datenpersistierung mit JPA 2.1 und Hibernate
Effiziente datenpersistierung mit JPA 2.1 und Hibernate
 
Zehn Jahre JPA – Architekturkonzepte und Best Practices revisited
Zehn Jahre JPA – Architekturkonzepte und Best Practices revisitedZehn Jahre JPA – Architekturkonzepte und Best Practices revisited
Zehn Jahre JPA – Architekturkonzepte und Best Practices revisited
 
Industry 4.0
Industry 4.0Industry 4.0
Industry 4.0
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
 
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
50 EJB 3 Best Practices in 50 Minutes - JavaOne 201450 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
 
Industrie 4.0: Symposium an der RFH Köln
Industrie 4.0: Symposium an der RFH KölnIndustrie 4.0: Symposium an der RFH Köln
Industrie 4.0: Symposium an der RFH Köln
 
20091020 JPA2
20091020 JPA220091020 JPA2
20091020 JPA2
 
Jpa(1)
Jpa(1)Jpa(1)
Jpa(1)
 

Similar to Java EE Pattern: The Control Layer

Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a TutorialGetting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a TutorialSam Garforth
 
Guidelines and Best Practices for Sencha Projects
Guidelines and Best Practices for Sencha ProjectsGuidelines and Best Practices for Sencha Projects
Guidelines and Best Practices for Sencha ProjectsAmitaSuri
 
PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...
PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...
PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...Puppet
 
Tips for Developing and Testing IBM HATS Applications
Tips for Developing and Testing IBM HATS ApplicationsTips for Developing and Testing IBM HATS Applications
Tips for Developing and Testing IBM HATS ApplicationsStrongback Consulting
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Ra'Fat Al-Msie'deen
 
A new kind of BPM with Activiti
A new kind of BPM with ActivitiA new kind of BPM with Activiti
A new kind of BPM with ActivitiAlfresco Software
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)Nagarajan
 
Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Samuel De Rycke
 
JBPM5 Community Training Course - Module #1 Introduction
JBPM5 Community Training Course - Module #1 IntroductionJBPM5 Community Training Course - Module #1 Introduction
JBPM5 Community Training Course - Module #1 IntroductionMauricio (Salaboy) Salatino
 
Simulation-Language.pptx
Simulation-Language.pptxSimulation-Language.pptx
Simulation-Language.pptxskknowledge
 
GT-Mconf - Transfer of Technology Course
GT-Mconf - Transfer of Technology CourseGT-Mconf - Transfer of Technology Course
GT-Mconf - Transfer of Technology Coursemconf
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3Dwight Sabio
 
Prometheus (Microsoft, 2016)
Prometheus (Microsoft, 2016)Prometheus (Microsoft, 2016)
Prometheus (Microsoft, 2016)Brian Brazil
 
performancetestingjmeter-121109061704-phpapp02
performancetestingjmeter-121109061704-phpapp02performancetestingjmeter-121109061704-phpapp02
performancetestingjmeter-121109061704-phpapp02Gopi Raghavendra
 
performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)QA Programmer
 
Performance eng prakash.sahu
Performance eng prakash.sahuPerformance eng prakash.sahu
Performance eng prakash.sahuDr. Prakash Sahu
 
Building Automation System (BAS) competitive buying strategies
Building Automation System (BAS) competitive buying strategiesBuilding Automation System (BAS) competitive buying strategies
Building Automation System (BAS) competitive buying strategiesRich Purtell
 

Similar to Java EE Pattern: The Control Layer (20)

Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a TutorialGetting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
 
Guidelines and Best Practices for Sencha Projects
Guidelines and Best Practices for Sencha ProjectsGuidelines and Best Practices for Sencha Projects
Guidelines and Best Practices for Sencha Projects
 
PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...
PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...
PuppetConf 2017: Puppet & Google Cloud: From Nothing to Production in 10 minu...
 
Tips for Developing and Testing IBM HATS Applications
Tips for Developing and Testing IBM HATS ApplicationsTips for Developing and Testing IBM HATS Applications
Tips for Developing and Testing IBM HATS Applications
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
A new kind of BPM with Activiti
A new kind of BPM with ActivitiA new kind of BPM with Activiti
A new kind of BPM with Activiti
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)
 
Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015
 
JBPM5 Community Training Course - Module #1 Introduction
JBPM5 Community Training Course - Module #1 IntroductionJBPM5 Community Training Course - Module #1 Introduction
JBPM5 Community Training Course - Module #1 Introduction
 
Simulation-Language.pptx
Simulation-Language.pptxSimulation-Language.pptx
Simulation-Language.pptx
 
GT-Mconf - Transfer of Technology Course
GT-Mconf - Transfer of Technology CourseGT-Mconf - Transfer of Technology Course
GT-Mconf - Transfer of Technology Course
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
Prometheus (Microsoft, 2016)
Prometheus (Microsoft, 2016)Prometheus (Microsoft, 2016)
Prometheus (Microsoft, 2016)
 
DevOps explained
DevOps explainedDevOps explained
DevOps explained
 
performancetestingjmeter-121109061704-phpapp02
performancetestingjmeter-121109061704-phpapp02performancetestingjmeter-121109061704-phpapp02
performancetestingjmeter-121109061704-phpapp02
 
performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)
 
ch3-lect7.pptx
ch3-lect7.pptxch3-lect7.pptx
ch3-lect7.pptx
 
Performance eng prakash.sahu
Performance eng prakash.sahuPerformance eng prakash.sahu
Performance eng prakash.sahu
 
Building Automation System (BAS) competitive buying strategies
Building Automation System (BAS) competitive buying strategiesBuilding Automation System (BAS) competitive buying strategies
Building Automation System (BAS) competitive buying strategies
 

More from Brockhaus Consulting GmbH (14)

Zeitreihen in Apache Cassandra
Zeitreihen in Apache CassandraZeitreihen in Apache Cassandra
Zeitreihen in Apache Cassandra
 
M2M infrastructure using Docker
M2M infrastructure using DockerM2M infrastructure using Docker
M2M infrastructure using Docker
 
Arquillian in a nutshell
Arquillian in a nutshellArquillian in a nutshell
Arquillian in a nutshell
 
Big Data and Business Intelligence
Big Data and Business IntelligenceBig Data and Business Intelligence
Big Data and Business Intelligence
 
Microservices und das Entity Control Boundary Pattern
Microservices und das Entity Control Boundary PatternMicroservices und das Entity Control Boundary Pattern
Microservices und das Entity Control Boundary Pattern
 
OPC -Connectivity using Java
OPC -Connectivity using JavaOPC -Connectivity using Java
OPC -Connectivity using Java
 
Mobile Endgeräte in der Produktion
Mobile Endgeräte in der ProduktionMobile Endgeräte in der Produktion
Mobile Endgeräte in der Produktion
 
Intro 2 Machine Learning
Intro 2 Machine LearningIntro 2 Machine Learning
Intro 2 Machine Learning
 
Messaging im Internet of Things: MQTT
Messaging im Internet of Things: MQTTMessaging im Internet of Things: MQTT
Messaging im Internet of Things: MQTT
 
Architekturbewertung
ArchitekturbewertungArchitekturbewertung
Architekturbewertung
 
Work shop worldbank
Work shop worldbankWork shop worldbank
Work shop worldbank
 
Certification isec 2012 program committee (bohnen, matthias) 2
Certification isec 2012 program committee (bohnen, matthias) 2Certification isec 2012 program committee (bohnen, matthias) 2
Certification isec 2012 program committee (bohnen, matthias) 2
 
Java flyer final_2014
Java flyer final_2014Java flyer final_2014
Java flyer final_2014
 
Cartel java ee 2nd ed
Cartel java ee 2nd edCartel java ee 2nd ed
Cartel java ee 2nd ed
 

Recently uploaded

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 

Recently uploaded (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 

Java EE Pattern: The Control Layer

  • 1. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 1 Session: Pattern of the Control Layer Singleton Service Starter Simple Workflows
  • 2. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 2 Objectives Learn about: ✔ How to start a service at deploy time ✔ Dealing with timers ✔ The Singleton pattern in Java EE ✔ The State Pattern in conjunction with simple workflows
  • 3. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 3 Some orientation Consumer Consumer Layer Integration Layer Business Process Layer Services Layer Component Layer OS Layer
  • 4. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 4 ECB Pattern Entity Control Boundary ✔ Based upon Robustness Diagrams (http://www.agilemodeling.com/artifacts/robustnessDiagram.htm) ➢ Boundary: user interface ➢ Control: actual process or activity ➢ Entity: a concept from an enterprise context. ✔ Elements are generic enough to be mapped either to service- oriented or object-oriented architectures. Boundary Control Entity Adam Bien
  • 5. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 5 Services, components and patterns Boundary Control Entity DAO & Domain Store Generic DAO Singleton Service Starter Dual View SOA Facade Lightweight asynchronous Facade Multichannel Facade TO & DTO Paginator Bean Locator Multichannel Facade Resource Binder Payload Extractor Aynchronous Resource Integrator Infrastructure
  • 6. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 6 Module Singleton
  • 7. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 7 Singleton ✔ Access to limited resources needs to be shared across user requests. ✔ Amount of active SLSB is dependent on: ➢ Parallel user requests ➢ Pool settings (min/max) ➢ Both isn't covered by spec. ✔ The solution should be portable between app.-servers.
  • 8. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 8 Singleton ✔ Most effective in terms of caches, application-wide configuration parameters or cyclic actions. ✔ Often combined with Service Starter (therefore we'll combine both labs) @Singleton(mappedName = "ejb/facade/ServiceStarter") @Remote(ServiceStarter.class) public class ServiceStarterBean implements ServiceStarter { ...
  • 9. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 9 Module Service Starter
  • 10. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 10 Service Starter ✔ Some logic needs to be initialized prior to the business logic ✔ Some services might depend on each other ✔ Since EJB 3.1 these initializations are specified, in EJB 3.0 they were not. ➢ In EJB 3.1: @Startup combined with @PostConstruct ➢ In EJB 3.0: Servlet and <load-on-startup> plus CDI
  • 11. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 11 Example Think of the following: ✔ Some production data needs to be retrieved for further processing ✔ You have to integrate a 3rd party system by means of cyclic, synchronous calls. ✔ Maybe you want to make use of timers, be aware, you can create timers from MDBs or Singletons only.
  • 12. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 12 Example ✔ ServiceStarterBean @Singleton(mappedName = "ejb/facade/ServiceStarter") @Startup @Remote(ServiceStarter.class) public class ServiceStarterBean implements ServiceStarter { private Logger log = Logger.getLogger(ServiceStarterBean.class); @EJB private PollingServiceBean pollingService; /** the timer service */ @Resource private javax.ejb.TimerService timerService; @PostConstruct public void init(){ log.info("initializing"); } ...
  • 13. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 13 Example ✔ ServiceStarterBean (cont.) @Schedule(second = "*/5", minute="*", hour="*", persistent = false, info="Timer: external polling") public void notifyPollingService(){ this.pollingService.doPoll(); } public void stopTimer(String timerName){ Collection<Timer> timers = this.timerService.getTimers(); for (Timer timer : timers){ if(timer.getInfo().toString().equals(timerName)){ timer.cancel(); log.info("Timer: " + timerName + " has been cancelled"); } }
  • 14. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 14 Example ✔ External configuration: ejb-jar.xml (overwrites the annotation) <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb- jar_3_1.xsd" version="3.1"> <display-name>Pattern Training</display-name> <enterprise-beans> <session> <ejb-name>ServiceStarterBean</ejb-name> <ejb-class>de.brockhaus.userMgmt.control.ServiceStarterBean</ejb-class> <timer> <description>none</description> <schedule> <second>0/5</second> <minute>*</minute> <hour>*</hour> </schedule> <timeout-method> <method-name>notifyPollingService</method-name> </timeout-method> <persistent>false</persistent> <info>Timer: external polling</info> </timer> </session> </enterprise-beans> </ejb-jar>
  • 15. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 15 Lab Implement Service Activator (not more than 15 min.)
  • 16. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 16 Module Simple Workflows
  • 17. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 17 Simple Workflow ✔ Within the control layer, it might happen, you have to perform several (identical) steps within different services / methods: ➢ Checking for existence of x, maybe in system y ➢ Calculating amounts of a, b, c (e.g. in a production plan for a certain period) ➢ ... ✔ You might end up in the idea of decomposition into processes and activities ➢ Has only little to do with Java EE ➢ Inspired by State Machines and Workflow Engines ➢ No maintenance of state of a current workflow instance
  • 18. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 18 The abstract process An abstract superclass providing methods to: ✔ Proceed (starting the process) ✔ Initialize the process ✔ Finalize the process
  • 19. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 19 The abstract process public abstract class Process{ private Logger log = Logger.getLogger(Process.class); public static final int PROCESS_START = 1; public static final int PROCESS_END = 999; private int runstate = 1; private boolean hasFinished = false; public synchronized void proceed() throws ProcessException{ try{ this.beforeProcess(); while (runstate != Process.PROCESS_END){ runSteps(); } this.afterProcess(); this.end(); } catch (ProcessException e) { ... } catch (Exception e){ ... } } ...
  • 20. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 20 The activity ✔ Common interface to all process related activities: public interface ProcessActivity { public <T> T proceedActivity<T>(); }
  • 21. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 21 The activity ✔ Concrete activity (example) ➢ Make use of the constructor to pass parameters ➢ Return whatever you want from processActivity public class StepOne implements ProcessActivity { private Logger log = Logger.getLogger(this.getClass()); private int value; public StepOne(int value){ this.value = value; } public <T> T proceedActivity(){ log.info(this.getClass().getSimpleName() + " invoked"); if(this.value > 99){ return (T) new Boolean(true); } else { return (T) new Boolean(false); } } }
  • 22. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 22 A concrete process ✔ Extend Process and overwrite runSteps() according to the activities public class SomeProcess extends de.brockhaus.userMgmt.util.Process { private int amount; public SomeProcess(int amount) { this.amount = amount; } @Override public void runSteps() throws ProcessException { switch(super.getRunstate()) { case(1): this.triggerStepOne(); break; case(2): this.triggerStepTwo(); break; case(3): this.triggerStepThree(); break; default: super.setRunstate(PROCESS_END); } }
  • 23. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 23 A concrete process ✔ Decide upon the activities outcome what needs to be done next private void triggerStepOne(){ StepOne one = new StepOne(amount); boolean ret = one.proceedActivity(); if(ret){ super.setRunstate(2); } else{ super.setRunstate(3); } } private void triggerStepTwo() { StepTwo two = new StepTwo(); two.proceedActivity(); super.setRunstate(PROCESS_END); } private void triggerStepThree() { StepThree three = new StepThree(); three.proceedActivity(); super.setRunstate(PROCESS_END); }
  • 24. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 24 Relation to the control layer ✔ Obviously the process has to be connected to the SLSBs of the control layer @Stateless @Remote(SomeService.class) public class SomeServiceBean implements SomeService { // inject SomeProcess @Inject private SomeProcess p; public void someBusinessMethod(int amount) throws ProcessException { // set amount at process p.setAmount(amount); // proceed process p.proceed(); } }
  • 25. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 25 Some conclusion Pros ✔ It's pretty simple and effective ✔ Well designed it might help a lot to stay with DRY paradigm ✔ Provides flexibility, just exchange an activity within a process and the process will behave different. Cons ✔ Don't think of too many activities, don't think of fully fledged workflows spanning several components / modules ✔ No graphical support, no modelling
  • 26. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 26 Lab Implement Simple Workflows (State Machine) (not more than 15 min.)
  • 27. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 27 Review Session Review: ✔ @PostConstruct, what is this good for? ✔ Can you provide some examples of using Singletons in Java EE? ✔ Why do we have processes and services in the example and what makes the difference to workflow engines?
  • 28. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 28 Recommeded reading ✔ http://java.sun.com/blueprints/corej2eepatterns/ ✔ http://www.corej2eepatterns.com/Patterns2ndEd/ ✔ Adam Bien, J2EE Patterns, Addison Wesley 2002, ISBN: 3-8273-1903-X ✔ Floyd Marinescu, Ed Roman: Ejb Design Patterns: Advanced Patterns, Processes, and Idioms; Wiley & Sons, ISBN-10: 0471208310 ✔ And other ... Photo: Bundesarchiv

Editor's Notes

  1. You can see that there is no tight coupling between the classes. Both can be changed independently without affecting each other. Of course, if there is any change in the public methods of Class Callee, Class Caller needs to change as well. But how Object &amp;quot;c&amp;quot; is created and managed is not decided in the implementation of Object &amp;quot;a&amp;quot;. Instead, the IoC framework uses the setB() method in Object &amp;quot;a&amp;quot; to inject Object &amp;quot;c&amp;quot;.
  2. Workflows can be described as : Sequential Workflow State Machine Workflow A Sequential Work Flow is a top-Down process, also known as a Human Flow Process, where the activities emerge from a beginning situation and end after a predefined sequence of steps. The State Machine Workflow does not have a defined path but signifies a set of states and transitions between these states. Sequential Workflows are self-driven. Once they are initiated, they have an absolutely predictable behavior throughout the execution of the activities. State Machine Workflows are event-driven. Activation of each state depends on predefined action / event. The engine executes the activities needed and stops after completion of the next state. State Machine Workflows are the solution for complex modeling processes where there is no deterministic execution path between the steps. Each human activity can be described as a function of a Sequential Workflow. For example – Order processing, Expenses approval or Purchase requests process. Best example for State Machine Workflow would be an order supply process where an order can have different states: received, approved, and shipped. Most workflows are having states and run for a relatively long time. Workflow which has many unplanned steps to track and where it may not be possible to represent all the possible paths to follow, a State Machine Workflow can be easier and more orderly to program.