Sometimes in our application, we need to build custom
services that run when Maximo starts. We can extend the psdi.server.AppService
class and register it with MXServer by inserting a new entry into the MAXSERVICE
table. If the service executes slow running queries, it is a good idea to cache
the data in memory to improve performance. We can implement MaximoCache
interface for this purpose. By doing this, we can initialize the service when
MXServer starts and pre-load all data required by the service into JVM memory.
When the service is called, it will only use cached data to provide instant
response which gives a much better user experience.
Below are the steps to create a sample service that loads
all Location’s description into memory. The service will provide a function to
check if an input string matches with a location’s description or not. We will
call this check when user entering an Item’s description and it will throw an
error whenever the input matches with the description
of any existing Location. This is not a very good use-case. But for the sake of simplicity, I hope it gives you an idea on how it
can be implemented.
1. Create a LocationCache class, implementing psdi.mbo.MaximoCache
interface:
- For the getName() function, set a name for the cache, such as “LOCATION_CACHE”.
- Create method loadData() to query and load all locations’ description into a HashSet
- Call the loadData() method in the init(), reload(), reload(String) function overridden from the MaximoCache interface
- Create function isLocationExist(String) to check if an input String matches with a description contained in the HashSet
3. Insert a new entry into the MAXSERVICE table to register with MXServer to initialize the service when Maximo starts. Sample SQL statement to
insert the record is as follows:
4. Extend the LocationSet class to override the
fireEventsAfterDBCommit() method. Essentially this method will reload the cache
whenever there is a change to location data. This will
ensure that the information stored in the cache will always in sync with new update.
5. Create an FldDescription class to override the validate()
method, and associate it with the Item.Description field. In the validate()
method, we will check if the description entered is the same with a location’s
description stored inside the cache and throw an error dialog if there is a
match.
You can view or download full sample code from this GitHub repository: link
After deploying the code and associate the LocationSet to
the Location object and the FldDescription class the Description field of the
Item object, to test if the code works, open an Item and enter a description
that matches with the description of a location, it should throw an error
message as in the image below:
To check if the cache is reloaded properly, create a new location or update an existing one, enter the description of the updated location to an item’s description, it should also throw an error message.
To check if the cache is reloaded properly, create a new location or update an existing one, enter the description of the updated location to an item’s description, it should also throw an error message.
No comments:
Post a Comment