Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

...

configure()

destroy()

Note: no initialize()

configure()

initialize()

If annotated or process():

@ProcessInput

process()

If annotated or generate():

@Tick

generate()

destroy()

Program Type

Sub-program Type

Abstract Class

Runtime Methods

Flow

 

AbstractFlow

 

Flowlet

AbstractFlowlet

MapReduce

 

AbstractMapReduce

configure()

initialize()

destroy()

 

Mappper

Mapper

initialize()

map()

destroy()

 

Reducer

Reducer

initialize()

reduce()

destroy()

Service

 

AbstractService

configure()

destroy()


Note: no initialize()

 

ServiceHandler

AbstractHttpServiceHandler

configure()

initialize()

destroy()


@GET or

@PUT or

@POST or

@DELETE

@Path{"handlerPath"}

handlerMethod()


Note: classes extending AbstractHttpServiceHandler are only required to implement configure()

Spark

 

AbstractSpark

configure()

initialize()

destroy()

 

SparkMain

SparkMain

run()

 

JavaSparkMain

JavaSparkMain

run()

Worker

 

AbstractWorker

configure()

initialize()

destroy()

Workflow

 

AbstractWorkflow

configure()

initialize()

destroy()

 

Custom Action

AbstractCustomAction

configure()

initialize()

run()

destroy()

...