This tutorial describes an easy and efficient caching mechanism based on DynaCachefor IBM® Business Process Manager V8.0. DynaCacheenhances application performance and provides the flexibility to load or flush cache contents at runtime. For ease of understanding and simplicity, the tutorial depicts how to load data that is accessed frequently by the application into DynaCache via a properties file. For any subsequent read cycle, the data is fetched from DynaCache, thereby improving application performance.
Introduction:
When developing business process management solutions, you frequently require data that is expensive to fetch or compute. To obtain this data, you can connect to a database, invoke a Web service, and so on. If this data does not change over time, you can often achieve significant performance gains with the appropriate use of caching.
IBM BPM product new feature Called DynaCache. DynaCache stores objects and later retrieves and serves them from its cache based on data-matching rules. It creates a unique user-defined "key" to store and retrieve cache items. Think of DynaCacheas a sophisticated Java Hashtable. The code used to provide the in-memory cache services extends the Java Dictionary class, which is the abstract parent of the Hashtable.
The object cache instance is used to store, distribute, and share Java objects. TheDistributedObjectCacheand DistributedMap APIs are provided so that application scan interacts with the object cache instances. Caches are stored in the JVM heap memory. If enabled, DynaCache supports overflow to disk when needed.
Introduction:
When developing business process management solutions, you frequently require data that is expensive to fetch or compute. To obtain this data, you can connect to a database, invoke a Web service, and so on. If this data does not change over time, you can often achieve significant performance gains with the appropriate use of caching.
IBM BPM product new feature Called DynaCache. DynaCache stores objects and later retrieves and serves them from its cache based on data-matching rules. It creates a unique user-defined "key" to store and retrieve cache items. Think of DynaCacheas a sophisticated Java Hashtable. The code used to provide the in-memory cache services extends the Java Dictionary class, which is the abstract parent of the Hashtable.
The object cache instance is used to store, distribute, and share Java objects. TheDistributedObjectCacheand DistributedMap APIs are provided so that application scan interacts with the object cache instances. Caches are stored in the JVM heap memory. If enabled, DynaCache supports overflow to disk when needed.
The default DynaCache instance is created if the DynaCache service is enabled in the Administrative Console. This default instance is bound to the global Java Naming and Directory Interface (JNDI) namespace using the name services, cache, and distributed map.
This tutorial covers the following topics:
- Creating the properties File.
- Creating the business object and service interface.
- Building the caching component.
- Testing the caching component
- IBM Integration Designer V7.5 or above
- IBM Process Server V7.5 or above
This tutorial is based on a fictional service that retrieves States details, such as Capital City, Population and Official Language. You can implement this retrieval in different ways:
- Straightforward approaches retrieve the values from a database based on the States name, or invoke a Web service that returns the details.
- An alternative approach is to use DynaCaching. Since States details rarely change, this particular service is a strong candidate for caching. With this approach, States Details are stored in a properties file. A Java class reads the properties file and loads the values into the cache. This prevents the frequent read calls made for the properties file, and the application can effectively read the values from the cache. This approach improves application performance and also optimizes resource utilization.
In this section, you create a Since States properties file with the States Name mapping to Capital City, Population and Official Language.
Create a new text file and name it StateDetails.properties. Populate the properties file as shown in below.
Creating the business object and the service interface
In this section, you create the business object and the service interface in the library.
Create Library
Creating the business object and the service interface
In this section, you create the business object and the service interface in the library.
Create Library
Open Integration Designer with a new workspace, and open the Business Integration perspective.
Right click on Business Integration view select new Library give name as EAI_Library. Select File > New > Library as shown in below.
Name the library EAI_Library and click Finish as shown in Figure below.
Add the fields to the business object as shown in below Figure
Create the service interface named StateInformationInterface.
Create a business object named StateInfoBO.
Add the fields to the business object as shown in below Figure
Right-click the Interface in the Business Integration Explorer of EAI_Library and create a new interface. Name the interface StateInformationInterface.
Create a request-response operation named getStateInfo with an input parameter called StateName of type String and an output parameter called StateInfo of type StateInfoBO, as shown in below Figure. Save the changes.
Select File > New > Module as shown in below Figure to create a new module named EAI_DynaCacheModule and click Next
Select EAI_Library from the Selected Required Libraries and click Finish as shown in Figure.
Right click on EAI_DynaCacheModule and select Properties. Add com.ibm.ws.runtime.jar as an external JAR file in the Java Build Path as shown in below Figure. This JAR file is located at <AppServer root>/plugins
Expand the EAI_DynaCacheModule under the Business Integration Explorer, and double-click the Assembly Diagram to open it.
Once the Assembly Diagram is open, click Java under the Components category from the Palette, and then click the blank area of the Assembly Diagram.
Rename the Java Component to StateInfoService. Use its pop-up toolbar to add an interface to the component. Use the StateInformationInterface interface for the interface. Save the assembly diagram, and then save all changes.
Double-click the StateInfoService component to generate its implementation. Give the package name as com.bpm.dynacache. A stub method is generated for the getStateInfo operation.
Enter the code snippet shown in Listing 1 for the getStateInfo operation of the StateInfoServiceImplJava class.
Enter the code snippet shown in Listing 2 after the StateInfoServiceImpl constructor to initialize the default DynaCache.
Listing 2. Java code to initialize cache
Save all changes.
In this section, you deploy the module to the test server and verify that the service behaves as expected. On the Assembly Diagram, right-click StateInfoServicecomponent and select Test Component. The Integration Test Client pop-up opens.
In the Initial request parameters panel, populate the SateName field with the value of AP, as shown in below Figure. Verify that the Integration Test Component contains the parameters as shown in below Figure.
Continue the test by selecting the deployment location and click Finish. At this point, your test server starts and your module is deployed automatically.
For the first run, the Java component fetches the State details for AP from the properties file. It then inserts the details into DynaCache. For any subsequent runs, it reads the country details for AP from DynaCache. Verify the response Business Object as shown in below Figure.
Verify via the console, which is shown in below Figure, that the State details were fetched from the properties file and inserted into the cache.
Rerun the same scenario and use the console to verify that for this run, the State details were fetched directly from the cache due to the insertion in the previous step.
This tutorial described how to configure DynaCache. This involved creating a properties file, creating the business object and service interface, building the caching component, and testing the component.
File Name | Description | Size | Download Link |
DynaCache.zip | DynaCacheApplication | 12.0 KB | |
EAI_DynaCache.pdf | DynaCache Document | 214 KB |
0 comments :
Post a Comment