-
Notifications
You must be signed in to change notification settings - Fork 4
function
Function bundle provides API for functional programming and asynchronous/persistent invocations. The goal of this package to provide simple means (comparing to Java 8 Function package) for functional programming with "next transaction" semantics in mind, i.e. functions are persisted in a repository for execution in a new transaction in the future.
The entry interface of the API is Session. A session can be obtained by adapting a Context. Then session is used to create functions, and submit and/or schedule functions for future asynchronous execution.
Session supports creation of tree types of functions:
- Method function invokes a method of an object passed as an argument to
Session.createMethodFunction()
. - Service method function invokes a method of OSGi service looked up by service type and filter passed to
Session.createServiceMethodFunction()
. - Script function executes a script using Java Scripting.
Function.bind()
allows to bind arguments to function parameters. Arguments can be values or functions.
Session submit and schedule methods take a function and return a Promise. Promises can be used to define steps to be taken after a function is asynchronously executed or execution times out. This allows to write long-running code which can span multiple processes and JVM restarts in the same way as regular Java code. For example, an automated deployment process which includes approval steps and asynchronous interactions with external systems.
Session interface does not have close()
, commit()
and rollback()
methods. If session was obtained from a transaction context then commit
or rollback of session's actions is done as part of its context's commit/rollback.