Java Component Development: A Conceptual Framework
Abstract: Java Component Development: A Conceptual Framework
:
Disclaimer: Matrix authorized access to any site, reprint, you must identify the form of hyperlinks to the original source and author of the article and the information statement Author: Palash Ghosh; kelvincheng
Original Address: http://www.onjava.com/pub/a/onjava/2005/03/23/components.html
Chinese Address: http://www.matrix.org.cn/resource/article/43/43899_Java_Component_Developmen.html
Key words: Java Component Development
I first introduced in several Construction and design solutions to adapt to the commercial activities of the continuing need to pay attention to changes in the business scene:
Companies will be required to file paper documents from the warehouse to a network file.
Companies need to replace their security provider.
Because of the huge economic changes, insurance companies must expand their insurance policies to the wider process.
The same thing is sure, demand changes as fast as commercial and technical change. But for all the changes, regardless of their size, we all need to discard the original re-start the entire system? This is unnecessary - architecture and design solutions by adding a little consideration, a good strategy and best practices to adapt to the current changes in the structure of the system without the need to argue too much.
In object-oriented programming and distributed object technology, and the interface of the component is a collection of reusable through the external API to meet demand (functional as well as non-functional). Components should be able to run in the distributed network environment to form networks procedures. Component-based design and development to follow the object-oriented analysis and design (OOAD) methodology, the expert is not a new topic.
The purpose of this paper is based on the best practices and java first started step by step to achieve a common conceptual model to develop java components. In this paper, readers need to be oriented Java, UML and Java/J2EE design knowledge. This article describes the scope is:
The basic components nature.
How to use Java design best practices (design patterns) to achieve these Java components of the basic nature of the design, and creating a conceptual framework for the development of the basic components of the framework will be able to conveniently used for any component in the development.
The basic components nature
To allow interaction with the other components can be, the components must have a service interface (API).
There must be a suitable component of the life cycle mechanism (start, stop, initialize, etc.)
Components can be configured to be.
There is only one example of components in the enterprise operating procedures.
Configuration changes should be dynamic (in the operation).
There must be a suitable component of the third-party software integration mechanism.
Components must be a suitable mechanism for dealing with errors
How to achieve the basic components of nature
Components must have a service interface (API)
Whether we are in a class or category wrote several 100 lines to 1,000 lines of code, the ultimate outcome of labor (the combination of category or categories) to provide some basic senior services. Return to think about, we can even achieve their definition of who we want before the basic senior services.
Let us give an example from the insurance industry, insurers in his daily work on the following:
Inspection insurance applications.
Background information collection and assessment.
According to the company's existing rules of insurance money
Collect information from other departments, as well as a variety of reports (medical, etc.).
Preparation of related policies.
Now if we wanted to write an insurer of commercial components, we must have the service interface in Figure 1, as well as its realization:
Figure 1. Underwriter service interfac
When the other components of the service request components insurers, does not need to consider the operation of the internal components. Packaging, its business logic components for easier maintenance and expansion.
Services will be a major component of the service implementation class (Service Interface Implementation), as well as the use of this class assistant class that is part of the components, may also use other components
In the product development, we need to have many components provide different services. For example, in the insurance industry, we have the "Request process components," "insured services components," as well as many other components. Therefore, we must have a mechanism in the Enterprise Solutions to register these services components, it can be under the special needs of enterprises using or suspension of these services.
Below are examples of XML structure, it can automatically handle service registration process.
Com.org.service.UnderWriterServiceImpl
Com.org.service.PolicyHolderServiceImpl
Should have the appropriate components of the life cycle component also needs a mechanism in the life cycle of its built-in, we can see that, independent of the mechanism, so it can be started and need to be suspended. ComponentControllerFactory (control components factory) is a singleton, because of their need only one example. The plant is responsible for the distribution of content providers to create different types of examples. ComponentControllerFactory play a dual role: First, its through its init (), reload (), etc. approach to the management of the life cycle of components (which is why it is a "factory"), Figure 2 shows the way
Figure 2. Component controller factory
The life cycle of components is:
DoStart (): Start component
(): Help from the XML configuration file allocation targets for the creation of the appropriate instance of the class
DoStop (): cessation of components
Reload (): If the components has already begun but XML configuration file changes occur, this method will be re-read XML configuration files and restart gradually.
GetInstance (): Back ComponentControllerFactory instance of the class
Can be a component of the usual configuration, each component has its own configurable parameters do not always change. For example, assume that we need to write a cache components, it needs a half-hour from the database static data to refresh their state. Updated time should be set in the configuration file, as we can not change the source code to change parameter values.
Below are the logger components on the XML configuration file example, dedicated to the management of business processes at all levels of logging.
Apache
WebLogic
In the enterprise application components only one instance of a component in the operation and there should be only one instance in the running, Singleton design pattern is appropriate to ensure that the choice of only one instance of JVM. But when this mode in a single JVM where feasible, but in many cases there will be problems JVM. But in the configuration information at the beginning of components without the need to load changes and to deal with all static information, with Singleton design pattern is still feasible
We assume that the components in a single JVM circumstances feasible, ComponentControllerFactory will be as in Figure 3:
Figure 3. Component controller factory in a single JVM
Singleton control method is provided by the factory
GetXXXService (): return method in the definition of XML documents in the provision of services to achieve category
GetXXXAdapter (): return method in XML document type definition Adapter achieve
Configuration files should be dynamic changes
If the component is not changed, there should be a code string singleton with a copy of the same examples, but if it is not becoming, we need change, configuration files need dynamic change.
There are two possible scenarios but the dynamic configuration file changes:
In a single JVM
More JVM situation
If the situation in a single JVM procedures in a single JVM run things on a much simpler. We now know that in the JVM SingletonControllerFactory usually in a case, and therefore, any time any change in configuration file will be needed according to some notification mechanism rotation included in the allocation of serial java object factory object to reload. This is based on the Observer-Observable pattern and do two things:
Through XMLizer (Individual components) to read and handle XML configuration files and included in the Java configuration object.
XML configuration file monitoring possible changes.
Figure 4 shows ConfigManager approach:
Figure 4. ConfigManager
ConfigManager type of notification when play was Observable Observer role, and its update method will be called. Update () method will be called SingletonControllerFactory the reload () method, the new java object will be created from the configuration information to reload.
ConfigurationChangeNotifier Observable play the role of XML configuration files and changes to activate the thread ConfigManger notice, and that its contents change. Figure 5 shows the relationship:
Figure 5. ConfigurationChangeNotifier
More JVM situation
In many JVM circumstances, things will not be so simple. We must have a
Need mechanisms in the run-time dynamic load changes to the XML configuration files without closure of the whole business process.
Necessary mechanism to ensure only one instance of group in the operation.
RMI use of JNDI is a choice to ensure that the cluster environment, the number of nodes in a specific example of a free node running. RMI services need to prepare, RMI stub to create services in the RMI. Created RMI stub needs to be bundled with the server's JNDI tree. This object will remain in the container, the container can object in the cluster can be used.
In order to address this situation, we need to introduce ConfigManager, it will do what tasks:
Need to create dynamic change XML configuration files.
Creating XML documents from the java serial documents. Serial and non-serial of the different components will be completed in the middle.
Create RMI, RMI services from registered created by the RMI stub, and through RMI services include serial configuration object.
RMI stub with the cluster will be in the environment of any JNDI tree nodes bundled.
Create notification system, it will re-bind RMI services and XML documents when changes seem to occur when reload object.
Figure 6 shows the RMI service interface, as well as its realization:
Figure 6. RMI service
In many JVM circumstances, ConfigManager Figure 7:
Figure 7. ConfigManager in a multiple-JVM scenario
ConfigManagerMultipleJVM of the role played Observer. When he was Observable notice, the update method will be called. Through update () method, rebindRMIService () method will be called, the object of this newly created (by the latest configuration information) will be reloaded.
SingletonControllFactory RMI services will play a role wrapper, has been returned to the appropriate allocation of the object.
This approach would create problems, because there is only one example, it can only allow one point mistake. ConfigManager stronger components needed to deal with mistakes.
But equally there are other ways, through MDB JMS and the masses of different cache synchronization node configuration object. In such circumstances, there is no need RMI services. Below are the realization of this method steps:
SingletonControllerFactory configured object initialized and started components.
ConfigManager the Observer-Observable model through its notification mechanism XML configuration file to track any changes. When it is discovered that changes, he will publish a message to JMS topic.
Running on the cluster environment of each group in the MDB trigger its onMessage () method, and included in the changes the configuration Java objects.
Components should have the right third-party software integration mechanisms, if reliance on third-party software components to build integrated services, third-party API should not be directly used in the achievement category. The best strategy is the development of third-party software and separate adapter and the adapter to achieve call.
Figure 8 shows the components call logger adapter example, demonstrated how to allow more convenient third-party APIs.
Figure 8. Application logger interface
The advantages of using adapter mode is easier and third-party software APIs merger. Furthermore, when these APIs change, adaptation need to achieve change, and using this adapter interface service will be no need for change.
Through XML configuration files from different adapters option is convenient, as described above, as this section.
Components should have the right mechanism for handling errors each component should have its own category of exception handling, it can help to capture the appropriate anomaly. We specific assumptions about the use of commercial components of a separate procedure to deal with the anomalies. The specific components of abnormal (Underwriter exception) will need services from the Exception Handling components.
Figure 9. Component exception handling
Exception handling of this type is specific for Underwriter services and the expansion of business processes based on the abnormal category. Its work is in the service category to cover up the anomaly and re-release.
Conclusion Overall, the following is the integration of the basic steps:
As part of the process of beginning of the process, through XMLizer ConfigManager button (for XML-to-java object conversion separate objects) to read for different components of XML configuration file, and through the server node JNDI tree to bind Java Configuration object.
As proceedings began the process of a configuration object will be read, the relevant provider / adapter / service needs to be that.
If changes in configuration files, ConfigManager changes will be read after the XML file and re-bonding configuration object.
Components to be re-printed in the configuration object and its latest changes to re-initialization.
Back to where we started, if you plan to develop a strong framework of the system components will be effectively adapted to the commercial and technological changes. The best part of the conceptual framework through the introduction of different plug-and-play service provider concept, totally component management / life cycle processes and business logic and different third-party APIs isolation. Even if the change occurred, in addition to changes / alternative service provider, you do not need to worry about the other parts of the code. This keeps the process easier to maintain, easier to adapt to, and stronger.
Author:
Palash Ghosh is a six-year framework, design and development solutions expertise Java/J2EE software architect.
Resources:
Matrix-Chinese Java developer community: http://www.matrix.org.cn
Matrix Uml and OO Forum: http://www.matrix.org.cn/topic.shtml?forumId=20 Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss , spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd
↑ Back
Tags: Component, framework, java framework






