Avalon Basic Concept (2) COP in -avalon

zhaozj2021-02-16  69

Components in Avalon

The core of Avalon Framework is a component. We define it to "perform passive entities that perform specific roles."

(1) PASSIVE API

Passive entities must use the Passive API. The Passive API is performed and is performed relative to himself. Reference IOC mode is explained in detail.

(2) Specific role

When designing a system architecture, consider a variety of different characters in the system. This way, you will have a list of components.

For each role, you want to define its script or interface to the other parts of the system. Direct definition interface is not enough. To define your interface, you must define a specific contract and keep it in your mind. That is, the component is provided to those users, what is produced. After defining the interface and contract, you can implement the component.

(3) Component

Components are interdependent. That is why components have a variety of different relationships. Components directly supported by Avalon Framework are: configuration, external components, management, and execution.

Each relationship is described by a separate interface. It is important to understand the priority of these relationships, which makes us understand how they integrate all the contracts.

1. Configurable: Tag object is configurable

2. Serviceable: Tag objects are available components

3. Initializable: Mark objects can be initialized

4. Disposable: Tag objects are destroyed

5. Stoppable: Tag objects are bootable and stop

Such a sequential contract means that each of these interfaces is to be called in a specific order of the objects. Each interface is represented as a narrow view of a controlled component or object.

Serviceable

In Avalon, Serviceable is defined as a active entity that controls or uses components. This is very similar to the music composer. Composer in the Symphony (System), according to their role selection appliance (components), telling the attention of the performance.

Avalon Serviceable Follow IOC to assign a service management. The following chapters discuss how to find specific components, how to prepare the serviceManger for Serviceable.

For safety reasons, serviceable has a specific contract. ServiceManger can only be set once. This means that compose ignores all other setup requests for all settings ServiceManger after the ServiceManger settings.

Find components

(1) Service management

In most cases, using ServiceManger to get the instance you need. In Avalon, the role is defined by the Work interface of the component. The WORK interface is different from other interfaces because it is an interface to define the component role. Serviceable and components have an interface relationship because their address specifies the relationship of components.

ServiceManger has a method of finding components to lookup components based on a fully qualified name (FQn) in the Work interface (role). Below is an example:

Final mycomponent component = (mycomponent) Manager.

Lookup ("com.mycompany.myproject.mycomponent");

It should be noted that roles and functions are not equivalent.

(2) Service selector

Sometimes, there are several components with the same role. This requires the use of ServicesElectrors to select the actual one. For example, the same role has a different format: uses a separate component to implement the documentation in accordance with the rule. One format is to replace all Tab keys in the input document to 4 spaces; a format is the originality; and another format is formatted into a Canvas object. For serviceable, there is no difference in code, but the format of the text is different. Using the previous example, we realize that the use of ServiceManger gets the correct component is not suitable. The component address is the relationship between each component of the role. Fortunately, the ServicesElectror is a component, we can use ServiceManger to find the ServicesElectror. The ServicesElectror is designed to select a component from multiple components of the same role. Below is an example:

Final ServicesElectror Selector = (ServiceSelector) Manager.

Lookup ("Org.mycompany.myProject.formatterselector");

Final formatter formatter = (formatter) class.select (myURL);

(3) After using the components

ServiceManger and ServiceSelector are required to release components after using the components. The method of use is release (), a method of use is to use the try / catch / finally structure, which is an example:

Mycomponent component = null;

Try

{

Component = (MyComponent) Manager.lookup ("Org.Mycom.myComponent);

Component.mymethod ();

}

Catch (Exception E)

{

GetLogger (). Debug ("Error Using MyComponent", E);

}

Finally

{

IF (Component! = null) Manager.release (Component);

}

The reason is that the efficient component management of the components in the component pool can manage the correct management resources.

转载请注明原文地址:https://www.9cbs.com/read-16586.html

New Post(0)