SlideShare uma empresa Scribd logo
1 de 41
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
1
Session: Pattern of the Boundary Layer
Service Facade(s):
Dual View
SOA Facade
Lightweight Asynchronous Facade
Multichannel Facade
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
2
Objectives
Learn about:
✔ … the several types of facades
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
Service Facade
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
7
Service Facade
What is it about:
✔ Easy to use business API, boundary between UI and backend
✔ Exposed methods should
hardly / never change
✔ Coarse grained, remotely
accessible
Image: Bundesarchiv
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
8
Service facade
✔ The principle
Web Container
Invocation
EJB Container
Other Client
SL
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
9
Service facade
Benefits:
✔ Encapsulation: The client does not know too many things about the
components behind
✔ Decoupling: fine-grained services are coordinated by the facade
and remain independent and reusable
✔ Crosscutting: As being the single point of entry, the facade is the
place to implement all cross-cutting concerns like monitoring or
precondition checks
✔ Usability: The methods of a service facade
should make sense to a business expert
(not a bazillian of getter/setter invocations)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
10
Service Facade
How to implement:
✔ Usually a SLSB, in rare cases it might be a SFSB as well
✔ Remotely accessible, local interfaces should be there as well.
✔ Transaction handling might be left to the container
(TransactionAttributeType.REQUIRES_NEW at class level)
✔ Implies a service-oriented way of thinking and promotes
procedural programming.
✔ The methods are actually procedures, which expect parameters
and return the result per value.
✔ The parameters and results can be either Transfer Objects (TOs) or
detached JPA entities.
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
11
Big Picture
App.-Server
JNDI
EJB Container
Bean
Remote
Interface
Service Endpoint
Interface
Local
Interface
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
12
Implementation strategies
There are several strategies to implement a service facade:
✔ CRUD facade
(we will deal with this later using the GenericDAO)
✔ Dual View facade
✔ SOA facade
(We will deal with this
later using some
integration patterns)
✔ Multichannel facade
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
13
CRUD Facade
✔ Nothing else but an exposed, transactional DAO
✔ Revisited later in the field of GenericDAO
(stay tuned)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
14
Dual View Facade
✔ In the vast majority of cases, the Service Facade is accessed from
the same VM.
➢ Calling the remote interface: Call-By-Value semantics
➢ Calling the local interface: Call-By-Reference semantics
✔ Calling the remote/local interfaces has performance impact due to
marshalling/unmarshalling of parameters in case of remote
communication
✔ Remote interface is exposed to external clients, so it has to remain
stable during the lifecycle.
✔ Not all methods need to be exposed remotely; some of them are
only dedicated for internal use such as workfow engines, web
applications, or message-driven beans.
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
15
How it might look like
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
16
Example
✔ The remote interface
✔ The local interface
package de.brockhaus.userMgmt.boundary;
import javax.ejb.Remote;
@Remote
public interface UserManagementService
{
public User findUserByCredentials(String user, String pwd);
}
package de.brockhaus.userMgmt.boundary;
import javax.ejb.Local;
@Local
public interface UserManagementServiceLocal
extends UserManagementService
{
public User createUser(User u);
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
17
Example
✔ The Stateless Session Bean
package de.brockhaus.userMgmt.boundary;
@Stateless(mappedName = "ejb/facade/UserManagementService")
@Local(UserManagementServiceLocal.class)
@Remote(UserManagementService.class)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class UserManagementServiceBean implements
UserManagementService, UserManagementServiceLocal
{
public User findUserByCredentials(String user, String pwd)
{
return new User("peterp", "neverland");
}
public User createUser(User u)
{
return u;
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
18
The client
✔ For local clients it will be the injected local reference
✔ For remote clients, it will be the 'regular' JNDI lookup
public static void init()
{
try
{
ctx = new InitialContext();
facade = (UserManagementService)
ctx.lookup("ejb/facade/UserManagementService");
}
catch (NamingException e)
{
e.printStackTrace();
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
19
Best practices
✔ Facade resides in a component named after the domain-specific
name, like ordermgmt, usermgmt, ...
✔ Implementation of facade to be in a package named „facade“ or
boundary
✔ Business interface named after
the business concept like
OrderService and
OrderServiceBean
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
20
Lab
Implement Dual View
(not more than 15 min.)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
21
SOA Facade
✔ Asynchronous, autonomous, independent of each other and
technology agnostic
✔ Fire and forget style
✔ Usually implemented using a
Message-driven Bean (MDB)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
22
JMS Queue Architecture
✔ Each message has only one consumer.
✔ Receiver can fetch the message at any time.
➢ No timing dependency between senders and receivers.
✔ Receiver acknowledges after processing the message.
Sender
JMS Server
Receiver
sends consumes
acknowledges
Queue
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
23
JMS Topic Architecture
✔ Each message may have multiple consumers.
✔ Subscriber must be active to receive relevant subscription.
➢ Timing dependency between publishers and subscribers.
✔ Possibility of a durable subscription to remove timing
dependency.
➢ Durable subscribers may be inactive.
Publisher
JMS Server
Subscriber1
publishes
delivers
subscribes
Subscriber2
delivers
subscribes
Topic
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
24
Message-Driven Beans
✔ A message-driven bean (MDB) is an EJB that listens to messages
from a JMS server or any other messaging system through JCA.
✔ Features of MDBs
➢ Consumes messages from a destination (queue or topic).
➢ Not visible to clients (asynchronous).
➢ No remote or local business interfaces.
➢ Stateless, no conversational state.
➢ Managed by the container.
Producer
sends/publishes
Server
ContainerContainer
Destination
MDB Pool
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
25
The Message-driven Bean
Annotations, interfaces and CDI
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode",
propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination",
propertyValue="queue/facade/UserMgmt")
})
public class UserManagementQueueListenerBean implements MessageListener
{
@EJB
private UserManagementServiceLocal local;
...
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
26
The Message-driven Bean
onMessage()
public void onMessage(Message msg)
{
log.info("invoked");
if(msg instanceof ObjectMessage)
{
try
{
Serializable s = ((ObjectMessage) msg).getObject();
if(s instanceof User)
{
local.createUser((User) s);
}
else
{ log.error("Wrong object type sent"); }
}
catch (JMSException e)
{ e.printStackTrace(); }
}
else
{ log.error("Wrong message type");}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
27
The client
More needs to be done:
✔ ConnectionFactory and Destination
(Queue/Topic) needs to be configured
beforehand
✔ Get connected:
public static void init()
{
try
{
InitialContext iniCtx = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory)
iniCtx.lookup("ConnectionFactory");
connection = qcf.createQueueConnection();
queue = (Queue) iniCtx.lookup("queue/facade/UserMgmt");
session = connection.
createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
connection.start();
sender = session.createSender(queue);
}
...
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
28
The client
✔ Send the things
✔ Better think twice, what you are sending
(ObjectMessage, TextMessage, ByteMessage)
✔ @see ServiceActivator and PayloadExtractor
(covered later)
try
{
ObjectMessage msg = session.
createObjectMessage(new User("peterp", "neverland"));
sender.send(msg);
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
29
SOA Facade
Further enhancements:
✔ Check message types by interceptor instead of using instanceof
(PayloadExtractor)
✔ Send XML instead of Java objects and
make use of JAXB
✔ Send JSON instead of Java Objects
(and make use of JAXB, google's GSON
or Jackson)
See solutions section
for examples,
we will deal with these later
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
30
Lab
Implement SOA Facade
(not more than 15 min.)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
31
Lightweight asynchronous facade
✔ In contrast to the SOA facade pattern, asynchronous invocation
might also be done 'internally' (pure EJB 3.1, not using JMS)
✔ Request/response communication is much easier to handle (no
Request and Response queue)
✔ No guaranteed delivery,
no storing of messages in
a dedicated message
store
(e.g. a database / journal)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
32
Lightweight asynchronous facade
✔ Methods to be invoked asynchronously needs to be annotated with
@Asynchronous (and will be executed using a background thread)
✔ Result of invocation available through a Future<V> object or
AsyncResult<V> object (which implements the Future interface)
@Asynchronous
public class UserManagementServiceBean implements UserManagementService,
UserManagementServiceLocal
{
...
public Future<User> findUserByCredentials(String user, String pwd)
{
return new AsyncResult<User>(new User("peterp", "neverland"));
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
33
The client
✔ Access the object through the Future object
public void testFindUserByCredentials()
{
Future<User> result = facade.findUserByCredentials("peterp", "neverland");
while(! result.isDone())
{
//do something else ...
}
try
{
// what timeframe is accepted … ('til you'll get an exception)
User u = result.get(5, TimeUnit.SECONDS);
...
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
34
Lab
Implement Lightweight Asynchronous Facade
(not more than 15 min.)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
35
Multichannel facade
✔ There might be the need to integrate non-Java clients
✔ JSR-181: WebService annotations allow customization of
parameters names and methods
✔ A link explaining all annotations in the field of Web Services can be
found below.
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
36
Multichannel facade
✔ Sample code:
@Stateless(mappedName = "ejb/facade/UserManagementService")
@Local(UserManagementServiceLocal.class)
@Remote(UserManagementService.class)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@WebService(serviceName = "UserManagementService")
public class UserManagementServiceBean implements
UserManagementService,
UserManagementServiceLocal
{
private Logger log = Logger.getLogger(this.getClass());
@WebMethod
public User findUserByCredentials(String user, String pwd)
{
return new User("peterp", "neverland");
}
@WebMethod(exclude=true)
public User createUser(User u)
{
log.info("Creating user: " + u.getUser());
return u;
}
}
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
37
The client
✔ Sample code:
public void testFindUserByCredentials()
{
try
{
//<soap:address location=
//"http://localhost:8080/BRO130_3_MultiChannel-solution/
// UserManagementService/UserManagementServiceBean?wsdl"/>
String wsdl = "http://localhost:8080/BRO130_3_4_MultiChannel_WS-solution/“+
“UserManagementService/UserManagementServiceBean?wsdl";
//xmlns:tns="http://control.userMgmt.brockhaus.de/"
String nameSpaceURI = "http://control.userMgmt.brockhaus.de/";
//<wsdl:service name="UserManagementService">
String serviceName = "UserManagementService";
URL wsdlLocation = new URL(wsdl);
QName qName = new QName(nameSpaceURI, serviceName);
Service service = Service.create(wsdlLocation, qName);
UserManagementService mgmtService = service.getPort(UserManagementService.class);
User user = mgmtService.findUserByCredentials("peterp", "neverland");
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
38
Lab
Implement Multichannel Facade
(not more than 15 min.)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
39
Conclusion
All types of facades mapping to one (or even more) SLSB,
several 'inbound' channels like:
✔ RMI or POJI (as used in Dual View Pattern)
✔ JMS plus Java Object or XML / JAXB or
JSON / Jackson
(as used in SOA Facade Pattern)
✔ WebService and RESTful service
(as used in MultiChannel Pattern)
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
40
Review
Session Review:
✔ Can you name the differences between @Local and @Remote?
✔ Why do we need to deal asynchronously?
✔ What if we are leaving the Java world?
✔ How to combine all of it?
Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt
41
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

Mais conteúdo relacionado

Destaque

Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Vladimir Bacvanski, PhD
 
Thailand ePayment infographic 2012 by Paysbuy.com
Thailand ePayment infographic 2012 by Paysbuy.comThailand ePayment infographic 2012 by Paysbuy.com
Thailand ePayment infographic 2012 by Paysbuy.com
PAYSBUY Co.,Ltd.
 
Advanced Fluid Mechanics
Advanced Fluid MechanicsAdvanced Fluid Mechanics
Advanced Fluid Mechanics
guest36d460
 
Effect of boundary layer thickness on secondary structures in a short inlet c...
Effect of boundary layer thickness on secondary structures in a short inlet c...Effect of boundary layer thickness on secondary structures in a short inlet c...
Effect of boundary layer thickness on secondary structures in a short inlet c...
Jeremy Gartner
 
WebSphere 6.1 Admin Course 1
WebSphere 6.1 Admin Course 1WebSphere 6.1 Admin Course 1
WebSphere 6.1 Admin Course 1
odedns
 
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
Stefan Macke
 

Destaque (18)

Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
 
Industrie 40 Symposium an der RFH Köln 7.7.2016
Industrie 40 Symposium an der RFH Köln 7.7.2016 Industrie 40 Symposium an der RFH Köln 7.7.2016
Industrie 40 Symposium an der RFH Köln 7.7.2016
 
Thailand ePayment infographic 2012 by Paysbuy.com
Thailand ePayment infographic 2012 by Paysbuy.comThailand ePayment infographic 2012 by Paysbuy.com
Thailand ePayment infographic 2012 by Paysbuy.com
 
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
Reactive programming met Java 8 en Java EE 7 - Martijn BlankestijnReactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
 
Advanced Fluid Mechanics
Advanced Fluid MechanicsAdvanced Fluid Mechanics
Advanced Fluid Mechanics
 
BRO 110: Reference Architecture
BRO 110: Reference ArchitectureBRO 110: Reference Architecture
BRO 110: Reference Architecture
 
PGDAIT presentation v11
PGDAIT presentation v11PGDAIT presentation v11
PGDAIT presentation v11
 
Effect of boundary layer thickness on secondary structures in a short inlet c...
Effect of boundary layer thickness on secondary structures in a short inlet c...Effect of boundary layer thickness on secondary structures in a short inlet c...
Effect of boundary layer thickness on secondary structures in a short inlet c...
 
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
 
Building impressive layout systems with vaadin
Building impressive layout systems with vaadinBuilding impressive layout systems with vaadin
Building impressive layout systems with vaadin
 
Binding business data to vaadin components
Binding business data to vaadin componentsBinding business data to vaadin components
Binding business data to vaadin components
 
Fluid mechanics - Motion of Fluid Particles and Stream
Fluid mechanics - Motion of Fluid Particles and StreamFluid mechanics - Motion of Fluid Particles and Stream
Fluid mechanics - Motion of Fluid Particles and Stream
 
WebSphere 6.1 Admin Course 1
WebSphere 6.1 Admin Course 1WebSphere 6.1 Admin Course 1
WebSphere 6.1 Admin Course 1
 
Jee course web services
Jee course web servicesJee course web services
Jee course web services
 
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
 
Vaadin 8 with Spring Frameworks AutoConfiguration
Vaadin 8 with Spring Frameworks AutoConfigurationVaadin 8 with Spring Frameworks AutoConfiguration
Vaadin 8 with Spring Frameworks AutoConfiguration
 
Payment Gateway by iPay88
Payment Gateway by iPay88Payment Gateway by iPay88
Payment Gateway by iPay88
 

Semelhante a Java EE Pattern: The Boundary Layer

Rapid deploy™ plugin for websphere message broker
Rapid deploy™ plugin for websphere message brokerRapid deploy™ plugin for websphere message broker
Rapid deploy™ plugin for websphere message broker
MidVision
 

Semelhante a Java EE Pattern: The Boundary Layer (20)

OpenWhisk Introduction
OpenWhisk IntroductionOpenWhisk Introduction
OpenWhisk Introduction
 
IBM Software Licensing: Tips to Safeguard Your Bottom Line
 IBM Software Licensing: Tips to Safeguard Your Bottom Line IBM Software Licensing: Tips to Safeguard Your Bottom Line
IBM Software Licensing: Tips to Safeguard Your Bottom Line
 
“z/OS Multi-Site Business Continuity” September, 2012
“z/OS Multi-Site Business Continuity” September, 2012“z/OS Multi-Site Business Continuity” September, 2012
“z/OS Multi-Site Business Continuity” September, 2012
 
HCLs Digital Asset Management Software to Organize Your Brand's Digital Assets
HCLs Digital Asset Management Software to Organize Your Brand's Digital AssetsHCLs Digital Asset Management Software to Organize Your Brand's Digital Assets
HCLs Digital Asset Management Software to Organize Your Brand's Digital Assets
 
DevOps explained
DevOps explainedDevOps explained
DevOps explained
 
branch_architecture
branch_architecturebranch_architecture
branch_architecture
 
LCA 2014 project-builder.org presentation
LCA 2014 project-builder.org presentationLCA 2014 project-builder.org presentation
LCA 2014 project-builder.org presentation
 
Red Hat JBoss BRMS Primer - JBoss Business Rules and BPM Solutions
Red Hat JBoss BRMS Primer - JBoss Business Rules and BPM SolutionsRed Hat JBoss BRMS Primer - JBoss Business Rules and BPM Solutions
Red Hat JBoss BRMS Primer - JBoss Business Rules and BPM Solutions
 
Making your PostgreSQL Database Highly Available
Making your PostgreSQL Database Highly AvailableMaking your PostgreSQL Database Highly Available
Making your PostgreSQL Database Highly Available
 
A09 - Microservices.pptx
A09 - Microservices.pptxA09 - Microservices.pptx
A09 - Microservices.pptx
 
Creating Effective Mobile Applications with IBM Bluemix
Creating Effective Mobile Applications with IBM BluemixCreating Effective Mobile Applications with IBM Bluemix
Creating Effective Mobile Applications with IBM Bluemix
 
JBoss Architect Meetup - November 2013 - 'Play By The Rules'
JBoss Architect Meetup - November 2013 - 'Play By The Rules'JBoss Architect Meetup - November 2013 - 'Play By The Rules'
JBoss Architect Meetup - November 2013 - 'Play By The Rules'
 
Forrester Research on Globally Distributed Development Using Subversion
Forrester Research on Globally Distributed Development Using SubversionForrester Research on Globally Distributed Development Using Subversion
Forrester Research on Globally Distributed Development Using Subversion
 
Forrester Research on Optimizing Globally Distributed Software Development Us...
Forrester Research on Optimizing Globally Distributed Software Development Us...Forrester Research on Optimizing Globally Distributed Software Development Us...
Forrester Research on Optimizing Globally Distributed Software Development Us...
 
Sprayer: low latency, reliable multichannel messaging
Sprayer: low latency, reliable multichannel messagingSprayer: low latency, reliable multichannel messaging
Sprayer: low latency, reliable multichannel messaging
 
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel MessagingNoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
 
Rapid deploy™ plugin for websphere message broker
Rapid deploy™ plugin for websphere message brokerRapid deploy™ plugin for websphere message broker
Rapid deploy™ plugin for websphere message broker
 
My Seminar
My SeminarMy Seminar
My Seminar
 
Industry 4.0
Industry 4.0Industry 4.0
Industry 4.0
 
AV-Comparatives’ 2017 business software review
AV-Comparatives’ 2017 business software reviewAV-Comparatives’ 2017 business software review
AV-Comparatives’ 2017 business software review
 

Mais de Brockhaus Consulting GmbH

Mais de Brockhaus Consulting GmbH (15)

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

Último

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 

Último (20)

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

Java EE Pattern: The Boundary Layer

  • 1. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 1 Session: Pattern of the Boundary Layer Service Facade(s): Dual View SOA Facade Lightweight Asynchronous Facade Multichannel Facade
  • 2. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 2 Objectives Learn about: ✔ … the several types of facades
  • 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 Service Facade
  • 7. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 7 Service Facade What is it about: ✔ Easy to use business API, boundary between UI and backend ✔ Exposed methods should hardly / never change ✔ Coarse grained, remotely accessible Image: Bundesarchiv
  • 8. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 8 Service facade ✔ The principle Web Container Invocation EJB Container Other Client SL
  • 9. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 9 Service facade Benefits: ✔ Encapsulation: The client does not know too many things about the components behind ✔ Decoupling: fine-grained services are coordinated by the facade and remain independent and reusable ✔ Crosscutting: As being the single point of entry, the facade is the place to implement all cross-cutting concerns like monitoring or precondition checks ✔ Usability: The methods of a service facade should make sense to a business expert (not a bazillian of getter/setter invocations)
  • 10. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 10 Service Facade How to implement: ✔ Usually a SLSB, in rare cases it might be a SFSB as well ✔ Remotely accessible, local interfaces should be there as well. ✔ Transaction handling might be left to the container (TransactionAttributeType.REQUIRES_NEW at class level) ✔ Implies a service-oriented way of thinking and promotes procedural programming. ✔ The methods are actually procedures, which expect parameters and return the result per value. ✔ The parameters and results can be either Transfer Objects (TOs) or detached JPA entities.
  • 11. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 11 Big Picture App.-Server JNDI EJB Container Bean Remote Interface Service Endpoint Interface Local Interface
  • 12. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 12 Implementation strategies There are several strategies to implement a service facade: ✔ CRUD facade (we will deal with this later using the GenericDAO) ✔ Dual View facade ✔ SOA facade (We will deal with this later using some integration patterns) ✔ Multichannel facade
  • 13. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 13 CRUD Facade ✔ Nothing else but an exposed, transactional DAO ✔ Revisited later in the field of GenericDAO (stay tuned)
  • 14. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 14 Dual View Facade ✔ In the vast majority of cases, the Service Facade is accessed from the same VM. ➢ Calling the remote interface: Call-By-Value semantics ➢ Calling the local interface: Call-By-Reference semantics ✔ Calling the remote/local interfaces has performance impact due to marshalling/unmarshalling of parameters in case of remote communication ✔ Remote interface is exposed to external clients, so it has to remain stable during the lifecycle. ✔ Not all methods need to be exposed remotely; some of them are only dedicated for internal use such as workfow engines, web applications, or message-driven beans.
  • 15. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 15 How it might look like
  • 16. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 16 Example ✔ The remote interface ✔ The local interface package de.brockhaus.userMgmt.boundary; import javax.ejb.Remote; @Remote public interface UserManagementService { public User findUserByCredentials(String user, String pwd); } package de.brockhaus.userMgmt.boundary; import javax.ejb.Local; @Local public interface UserManagementServiceLocal extends UserManagementService { public User createUser(User u); }
  • 17. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 17 Example ✔ The Stateless Session Bean package de.brockhaus.userMgmt.boundary; @Stateless(mappedName = "ejb/facade/UserManagementService") @Local(UserManagementServiceLocal.class) @Remote(UserManagementService.class) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public class UserManagementServiceBean implements UserManagementService, UserManagementServiceLocal { public User findUserByCredentials(String user, String pwd) { return new User("peterp", "neverland"); } public User createUser(User u) { return u; } }
  • 18. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 18 The client ✔ For local clients it will be the injected local reference ✔ For remote clients, it will be the 'regular' JNDI lookup public static void init() { try { ctx = new InitialContext(); facade = (UserManagementService) ctx.lookup("ejb/facade/UserManagementService"); } catch (NamingException e) { e.printStackTrace(); } }
  • 19. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 19 Best practices ✔ Facade resides in a component named after the domain-specific name, like ordermgmt, usermgmt, ... ✔ Implementation of facade to be in a package named „facade“ or boundary ✔ Business interface named after the business concept like OrderService and OrderServiceBean
  • 20. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 20 Lab Implement Dual View (not more than 15 min.)
  • 21. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 21 SOA Facade ✔ Asynchronous, autonomous, independent of each other and technology agnostic ✔ Fire and forget style ✔ Usually implemented using a Message-driven Bean (MDB)
  • 22. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 22 JMS Queue Architecture ✔ Each message has only one consumer. ✔ Receiver can fetch the message at any time. ➢ No timing dependency between senders and receivers. ✔ Receiver acknowledges after processing the message. Sender JMS Server Receiver sends consumes acknowledges Queue
  • 23. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 23 JMS Topic Architecture ✔ Each message may have multiple consumers. ✔ Subscriber must be active to receive relevant subscription. ➢ Timing dependency between publishers and subscribers. ✔ Possibility of a durable subscription to remove timing dependency. ➢ Durable subscribers may be inactive. Publisher JMS Server Subscriber1 publishes delivers subscribes Subscriber2 delivers subscribes Topic
  • 24. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 24 Message-Driven Beans ✔ A message-driven bean (MDB) is an EJB that listens to messages from a JMS server or any other messaging system through JCA. ✔ Features of MDBs ➢ Consumes messages from a destination (queue or topic). ➢ Not visible to clients (asynchronous). ➢ No remote or local business interfaces. ➢ Stateless, no conversational state. ➢ Managed by the container. Producer sends/publishes Server ContainerContainer Destination MDB Pool
  • 25. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 25 The Message-driven Bean Annotations, interfaces and CDI @MessageDriven( activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination", propertyValue="queue/facade/UserMgmt") }) public class UserManagementQueueListenerBean implements MessageListener { @EJB private UserManagementServiceLocal local; ...
  • 26. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 26 The Message-driven Bean onMessage() public void onMessage(Message msg) { log.info("invoked"); if(msg instanceof ObjectMessage) { try { Serializable s = ((ObjectMessage) msg).getObject(); if(s instanceof User) { local.createUser((User) s); } else { log.error("Wrong object type sent"); } } catch (JMSException e) { e.printStackTrace(); } } else { log.error("Wrong message type");} }
  • 27. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 27 The client More needs to be done: ✔ ConnectionFactory and Destination (Queue/Topic) needs to be configured beforehand ✔ Get connected: public static void init() { try { InitialContext iniCtx = new InitialContext(); QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup("ConnectionFactory"); connection = qcf.createQueueConnection(); queue = (Queue) iniCtx.lookup("queue/facade/UserMgmt"); session = connection. createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); connection.start(); sender = session.createSender(queue); } ...
  • 28. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 28 The client ✔ Send the things ✔ Better think twice, what you are sending (ObjectMessage, TextMessage, ByteMessage) ✔ @see ServiceActivator and PayloadExtractor (covered later) try { ObjectMessage msg = session. createObjectMessage(new User("peterp", "neverland")); sender.send(msg);
  • 29. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 29 SOA Facade Further enhancements: ✔ Check message types by interceptor instead of using instanceof (PayloadExtractor) ✔ Send XML instead of Java objects and make use of JAXB ✔ Send JSON instead of Java Objects (and make use of JAXB, google's GSON or Jackson) See solutions section for examples, we will deal with these later
  • 30. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 30 Lab Implement SOA Facade (not more than 15 min.)
  • 31. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 31 Lightweight asynchronous facade ✔ In contrast to the SOA facade pattern, asynchronous invocation might also be done 'internally' (pure EJB 3.1, not using JMS) ✔ Request/response communication is much easier to handle (no Request and Response queue) ✔ No guaranteed delivery, no storing of messages in a dedicated message store (e.g. a database / journal)
  • 32. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 32 Lightweight asynchronous facade ✔ Methods to be invoked asynchronously needs to be annotated with @Asynchronous (and will be executed using a background thread) ✔ Result of invocation available through a Future<V> object or AsyncResult<V> object (which implements the Future interface) @Asynchronous public class UserManagementServiceBean implements UserManagementService, UserManagementServiceLocal { ... public Future<User> findUserByCredentials(String user, String pwd) { return new AsyncResult<User>(new User("peterp", "neverland"));
  • 33. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 33 The client ✔ Access the object through the Future object public void testFindUserByCredentials() { Future<User> result = facade.findUserByCredentials("peterp", "neverland"); while(! result.isDone()) { //do something else ... } try { // what timeframe is accepted … ('til you'll get an exception) User u = result.get(5, TimeUnit.SECONDS); ...
  • 34. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 34 Lab Implement Lightweight Asynchronous Facade (not more than 15 min.)
  • 35. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 35 Multichannel facade ✔ There might be the need to integrate non-Java clients ✔ JSR-181: WebService annotations allow customization of parameters names and methods ✔ A link explaining all annotations in the field of Web Services can be found below.
  • 36. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 36 Multichannel facade ✔ Sample code: @Stateless(mappedName = "ejb/facade/UserManagementService") @Local(UserManagementServiceLocal.class) @Remote(UserManagementService.class) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @WebService(serviceName = "UserManagementService") public class UserManagementServiceBean implements UserManagementService, UserManagementServiceLocal { private Logger log = Logger.getLogger(this.getClass()); @WebMethod public User findUserByCredentials(String user, String pwd) { return new User("peterp", "neverland"); } @WebMethod(exclude=true) public User createUser(User u) { log.info("Creating user: " + u.getUser()); return u; } }
  • 37. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 37 The client ✔ Sample code: public void testFindUserByCredentials() { try { //<soap:address location= //"http://localhost:8080/BRO130_3_MultiChannel-solution/ // UserManagementService/UserManagementServiceBean?wsdl"/> String wsdl = "http://localhost:8080/BRO130_3_4_MultiChannel_WS-solution/“+ “UserManagementService/UserManagementServiceBean?wsdl"; //xmlns:tns="http://control.userMgmt.brockhaus.de/" String nameSpaceURI = "http://control.userMgmt.brockhaus.de/"; //<wsdl:service name="UserManagementService"> String serviceName = "UserManagementService"; URL wsdlLocation = new URL(wsdl); QName qName = new QName(nameSpaceURI, serviceName); Service service = Service.create(wsdlLocation, qName); UserManagementService mgmtService = service.getPort(UserManagementService.class); User user = mgmtService.findUserByCredentials("peterp", "neverland");
  • 38. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 38 Lab Implement Multichannel Facade (not more than 15 min.)
  • 39. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 39 Conclusion All types of facades mapping to one (or even more) SLSB, several 'inbound' channels like: ✔ RMI or POJI (as used in Dual View Pattern) ✔ JMS plus Java Object or XML / JAXB or JSON / Jackson (as used in SOA Facade Pattern) ✔ WebService and RESTful service (as used in MultiChannel Pattern)
  • 40. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 40 Review Session Review: ✔ Can you name the differences between @Local and @Remote? ✔ Why do we need to deal asynchronously? ✔ What if we are leaving the Java world? ✔ How to combine all of it?
  • 41. Copyright by Brockhaus GmbH, alle Rechte reserviert, unautorisierte Vervielfältigung untersagt 41 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

Notas do Editor

  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. The message Queue provides a Point-to-Point messaging system. Messages, which are sent to a Queue are picked up by only one message consumer. When more than one message consumer is registered to this queue, its undefined which consumer will process the message. When a message is send to a queue, while no consumers are available, the message will reside on the JMS server, until it times-out, or is picked up by a consumer.
  3. One or more JMS destinations are configured in the server’s namespace. The message-driven beans register as clients to those destinations via configuration information in annotations or in the deployment descriptor. A client cannot locate message-driven beans in the server’s namespace. Instead, the destination is usually injected by using the @Resource annotation. Once the JMS queue or topic has been located by the client, the client uses the JMS API to send messages to that remote destination. Upon receiving the message on the destination, the server will deliver the message to the message-driven bean that has been configured as a client to that destination. If the destination is a queue, the server delivers a single copy of the message to a single message-driven bean that is registered as a message consumer for the queue. If the destination is a topic, the server delivers a single copy of the message to all message-driven beans registered as a subscriber to the topic. Since messages are sent to destinations in the server’s namespace, the message-driven beans do not have remote or local interfaces. In fact, the application client does not know to which message-driven beans the messages are being delivered, since the client is only sending a message to a destination queue or topic. Message-driven beans are similar to stateless session beans in that they cannot carry client state. Since any client can perform a look-up on a destination, and then send messages to that destination, a message-driven bean must be prepared to receive messages from multiple clients.
  4. Nice overview: http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.wsfep.multiplatform.doc%2Finfo%2Fae%2Fae%2Frwbs_jaxwsannotations.html