Applying business logic when reading streaming formats

This only applies to streaming formats that are mapped to the Payment model.

It is possible to apply additional business logic when loading streaming formats into Trax by piggybacking on the streaming principles of the I/O Pack framework.

There are two ways to inject additional business logic:

By implementing the PaymentLogic interface as a plain Java class

By implementing a Groovy script that returns a PaymentLogic implementation

These implementations can be activated by adding the load-logic parameter to the desired format definition and listing either the fully qualified Java class name or the code of a System.Script value object as its value. In case of a script reference, the code must be prefixed by “script=”. The script must be present in the database and must be of type Groovy.

Multiple implementations can be combined as a comma-separated list and both plain Java implementations and Groovy script references can be mixed. They are executed in order of appearance.

An example of a Groovy implementation – conveniently called PaymentLogicSample – is available in the Sample data-set for your reference.

Thread safety

It is important to understand that a single instance of a PaymentLogic implementation is used to process all levels of the mapped value objects, meaning that all envelopes and payments are passed through this single instance. This is in contrast to the streaming mappers and validators/notifiers of which a new instance is created for each individual envelope and payment.

This implies that instance data is accessed by different threads and all read and write operations must made thread-safe by either using proper synchronization or other techniques such as the atomic classes or collections in the java.util.concurrent package.

If a class takes care of its own thread safety, the class or all of its implemented methods must be annotated with the @PaymentLogic.ThreadSafe annotation.

If a class or its methods are not annotated with the above annotation, a reflective proxy is created to externally synchronize all method calls. This has an impact on performance and hinders parallelism, so it is recommended to think about proper thread safety yourself.