Scripting is what you're looking for. The default scripting language is mvel, but you can easily install plugins that support other languages, like javascript, groovy, python. You can also write your own native script in Java.
You can use scripts in different apis, here are some examples:
It's possible to preload scripts placing them on file system, from the documentation page:
Scripts can always be provided as part of the relevant API, but they
can also be preloaded by placing them under config/scripts and then
referencing them by the script name (instead of providing the full
script). This helps reduce the amount of data passed between the
client and the nodes.
The name of the script is derived from the hierarchy of directories it
exists under, and the file name without the lang extension. For
example, a script placed under config/scripts/group1/group2/test.py
will be named group1_group2_test.
Only native scripts written in java have to implement an interface. In case of either mvel, javascript python or groovy, you can just write the script that you need on file instead of passing it together with the relevant api and refer to it using its name.