%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;
...
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
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 &quot;c&quot; is created and managed is not decided in the implementation of Object &quot;a&quot;. Instead, the IoC framework uses the setB() method in Object &quot;a&quot; to inject Object &quot;c&quot;.
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.
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.