Skip to main content
Skip table of contents

Using unit of work listeners to share data updates

Unit of work listeners provide real-time updates of transactional data. NexJ CRM provides a unit of work listener holder to control the flow of data etween NexJ CRM and registered listeners.

To enable your system to receive persistence database changes from NexJ CRM, you must register your listener with the unit of work listener holder. When there is a persistence change in NexJ CRM, the unit of work listener holder collects the changes, and sends them to all registered listeners. The listeners can persist on, report on, or perform other actions on the data.

NexJ Data Analytics and Intelligence (NexJ DAi) uses semantic attribute modeling to compile customer data from disparate physical (source) systems into a single comprehensive customer record. You can register NexJ DAi
as a listener with the NexJ CRM listener holder. For more information about NexJ DAi, see the NexJ DAi documentation.

Unit of work listener architecture

This example assumes that data changes are persisted to the NexJ DAi reporting database.

The following diagram shows the architecture for the unit of work listeners. There can be many listeners, which are represented by (0..*) in the diagram.

The NexJ CDC adapter informs DAi of changes to persisted data. The CDC adapter houses the DAi listener and the CDC adapter runs on the application server. For more information about the CDC adapter, see the NexJ DAi documentation.

Unit of work listener architecture

Enabling the unit of work listener holder

The System.UOW.Listener.comp unit of work listener component is disabled by default. Enable the component if you want to use the listener holder to receive data update notifications from NexJ CRM. You can enable it by changing your properties file for your deployment.

Info

You can also enable the unit of work listener holder by modifying the System.UOWListener.comp component.

To enable the unit of work listener holder during deployment:

  1. Stop your application server.
  2. Using a text editor of your choice open your properties file.
  3. Either locate the uowListenerEnabled attribute, and change the attribute value as follows, or add the required attribute and attribute value to your properties file:
    uowListener.enabled=true
    To disable the unit of work listener, use:
    uowListener.enabled=false
  4. Save your changes.
  5. Restart your application server.

You have enabled the unit of work listener holder.

Next, add your listener to the unit of work listener holder.

Adding your listener to the unit of work listener holder

When an instance of the System.UOWListener component is retrieved, the NexJ framework provides a default unit of work listener with the listener holder. The unit of work listener holder can contain multiple listeners, and it relays notifications of commit events to all added listeners.

Info

For NexJ DAi, code runs on the application server that automatically adds the listener to the listener holder.


To add your listener to the unit of work listener holder:

  1. Create a Java class that implements the UnitOfWorkListener interface from core framework.
  2. In NexJ Studio, navigate to the Components tab in the Resources layer.
  3. Right-click in the components area and select New Component.
  4. In the Name field, enter a name for your component. For example, enter Application.UOWListener.comp.
  5. Click Finish.
  6. From the Activation drop-down, choose singleton.
  7. In the Type field, specify the path to the Java class you defined in step 1.
  8. Define the initialize method of the Java class by using the following Java code:

    JAVA
    UnitOfWorkListener uowListener =
     (UnitOfWorkListener)<context>.getComponentInstance("<yourComponentName>");
          ((UnitOfWorkListenerHolder)uowListener).addListener(this);

    where <context> is an InvocationContext, this is an instance of the listener you are trying to add, and <yourComponentName> is the component defined in step 4.

  9. Click the Save button
    to save your changes to the component.

Your listener is linked to the unit of work listener holder and any data changes will be sent to the listener.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.