10.5. JavaScript Filters

In addition to the supplied Java filters, Tungsten Replicator also includes support for custom script-based filters written in JavaScript and supported through the JavaScript filter. This filter provides a JavaScript environment that exposes the transaction information as it is processed internally through an object-based JavaScript API.

The JavaScript implementation is provided through the Rhino open-source implementation. Rhino provides a direct interface between the underlying Java classes used to implement the replicator code and a full JavaScript environment. This enables scripts to be developed that have access to the replicator constructs and data structures, and allows information to be updated, reformatted, combined, extracted and reconstructed.

At the simplest level, this allows for operations such as database renames and filtering. More complex solutions allow for modification of the individual data, such as removing nulls, bad dates, and duplication of information.

Warning

Updating the static properties file for the replicator will break automated upgrades through tpm. When upgrading, tpm relies on existing template files to create the new configuration based on the tpm parameters used.

Making a backup copy of the configuration file automatically generated by tpm, and then using this before performing an upgrade will enable you to update your configuration automatically. Settings for the JavaScript filter will then need to be updated in the configuration file manually.

To enable a JavaScript filter that has not already been configured, the static properties file (static-SERVICE.properties) must be edited to include the definition of the filter using the JavaScriptFilter class, using the script property to define the location of the actual JavaScript file containing the filter definition. For example, the supplied ansiquotes filter is defined as follows:

replicator.filter.ansiquotes=com.continuent.tungsten.replicator.filter.JavaScriptFilter
replicator.filter.ansiquotes.script=${replicator.home.dir}/support/filters-javascript/ansiquotes.js

To use the filter, add the filter name, ansiquotes in the above example, to the required stage:

replicator.stage.q-to-dbms.filters=mysqlsessions,pkey,bidiSlave,ansiquotes

Then restart the replicator to enable the configuration:

shell> replicator restart

Note

This procedure will need to be enabled on each replicator that you want to use the JavaScript filter.

If there is a problem with the JavaScript filter during restart, the replicator will be placed into the OFFLINE state and the reason for the error will be provided within the replicator trepsvc.log log.