...
Though there are slight differences between program types, in general all programs follow the same lifecycle. The exceptions are flows and services , as they which have sub-programs (flowlets and called service handlers).
When an application is deployed, the application is configured, followed by the configuring of all programs and sub-programs of the application, recursively. The configuration happens by calling the configure()
method of each entity, which creates a specification for that entity. These specifications are bundled together to create the application.
...
The initialize()
method is called once, at the start of the program. The destroy()
method is called once, at the end of program before it is shutdown. If there is any cleanup required, it can be implemented in this method.
Flows and services Services do not have an initialize()
because they have a sub-program (flowlets for a flow, service handlers for a service) which has have an initialize()
method instead.
Note that the instance of the object called at deployment is not the same instance of the object called at runtime. Because the result of the deployment stage is an immutable program specification, any local member variables set during deployment will not be available during runtime. This behavior can cause unexpected null-pointer exceptions. The solution is instead to set these as properties in the specification, which is available at runtime, as in the examples on initializing instance fields. For example, in a flowletSpark program:
Code Block |
---|
getContext().getSpecification().getProperties() |
Transactions
The relationship between transactions and lifecycle depends on the method involved:
...
Details on transactions in these methods are covered in the section on using the transaction system in programs.
Program Types
For convenience, most program types have a corresponding abstract program class. It is recommended to always extend the abstract class instead of implementing the program interface. The abstract classes provide:
...
Program Type | Sub-program Type | Abstract Class | Runtime Methods | Flow |
|
|
| Flowlet |
| |
---|---|---|---|---|---|---|---|---|---|---|
MapReduce |
|
|
| |||||||
| Mappper |
|
| |||||||
| Reducer |
|
| |||||||
Service |
|
|
Note: no | |||||||
| ServiceHandler |
|
Note: classes extending | |||||||
Spark |
|
|
| |||||||
| SparkMain |
|
| |||||||
| JavaSparkMain |
|
| |||||||
Worker |
|
|
| |||||||
Workflow |
|
|
| |||||||
| Custom Action |
|
|
...