11th Chapter Environment
11.1. Introduction
The environment component is a control inversion (IoC) container composed of a combination of connected environments. It reads configuration information, describes how objects should be instantiated, how they are configured, and how they are connected together.
The environment is used to obtain the resources and services required by the activity implementation and process virtual machines. The main purpose is to allow multiple parts of the process virtual machine to be configurable so that the PVM and running at the top of the language can work in a standard Java environment and can also be in an enterprise Java environment.
The environment is divided into a series of environments. Each environment can have its own lifecycle. For example, the process engine environment overwrites the full life time of the application. The block environment only works on the try-finally block cycle. Generally one block environment is responsible for a database transaction. Each environment exposes a key-value list. Pairs.
11.2. Environmentfactory
To start working with an environment, you need a environmentfactory. A single environment factory object can be used throughout the entire life of the application. So generally this is saved in a static member variable. Environmentfactory yourself in the process engine environment
A environmentfactory is generally obtained by parsing a configuration file, like this:
static EnvironmentFactory environmentFactory =
EnvironmentFactory.parse(new ResourceStreamSource("pvm.cfg.xml");
Refer to Javadocs packet org.jbpm.stream for more types of stream sources.
This is the default parser in an environment factory that creates defaultenvironmentfactory. The idea is that we will also support spring as the IOC container, but this is still in the TODO state. You are welcome to help us:-) in this respect. This parser can use the static setter method to configure Environmentfactory.setparser (Parser).
11.3. Environment block
An environment exists for the range of try-finally blocks. This is an environment block looks like how:
Environment environment = environmentFactory.openEnvironment();
try {
...
} finally {
environment.close();
}
Environment blocks define another life part: the block environment. A transaction can be a common example of an object defined in a block environment.
In such a block, an object can be found in the environment by name or type. If an object can be found from the environment by Environment.get (String name) or <T> T environment.get (class<t>).
When an environment is created, it has a process-engine environment and a block environment.
In the default implementation, the Process-engine environment and the block environment are wirecontext. A wirecontext contains how objects are created and if they are bound to a formal object graph.