Contents
Design Patterns
This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.
Learning Objectives
- Understand what design patterns are
- Learn about the myriad of design patterns that you can use in your projects
Intended Audience
This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.
Prerequisites
Basic knowledge of Java programming.
Hello dear friends. In this video, we will examine the service activator pattern. Let's begin. Before we begin, I'd like to make it clear that we cannot provide examples for all of these patterns. For instance, the service activator pattern requires a large structure which will be difficult to demonstrate in this course. As a result, I will only provide examples of patterns that can be implemented with small projects. Let's get going. In enterprise applications, a majority of the processing is done in a synchronous manner. A client invokes a business service and waits until the business service returns from processing. However, the business processing in some use cases takes considerable time and resources. The business processing might even span applications possibly integrating with applications inside and outside the enterprise. For these long lived processes, it's not feasible for application clients to wait until the business processing completes. So, in this case, we want to invoke services asynchronously.
Some long running use cases take a long time. Instead of blocking the users, we can run these asynchronously. JMS is a good example of service activator pattern. JMS as a Java message service is an API that provides the facility to create, send, and read messages. It provides loosely coupled, reliable, and asynchronous communication. Let's examine the UML of service activator. The client is any client in the application that needs to invoke a business service in an asynchronous manner. The client can be any type of application components such as POJO or an EJB component that can create and send JMS messages. The request is the message object created by the client and sent to the service activator using the message-oriented middleware. According to the JMS specification, the request object must implement the java.jms.message interface. The JMS API provides several message types such as text message, object message and so on that can be used as request objects depending on what type of message you want to send. The service activator is the main class of the pattern. It implements the javax.jms.MessageListener interface which is defined by the JMS specification.
The service activator implements an on-message method that is invoked when a new message arrives. The service activator parses the message to determine what needs to be done. The service activator might use a service locator to lookup or create business service components. The business service is the target object that the client asks to do asynchronous processing. The response is a message object created and sent either by the service activator or a business service. The response can be an acknowledgement to let the client know that the request was received. The response can also be the result of asynchronous processing. Now, I believe that covers the service activator pattern in JMS. In the next video, we will look into the DAO pattern. See you in the next video.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.