Ninth, JavaBean and RMI

xiaoxiao2021-03-06  57

[Before class thinking] 1. What is Javabean? 2. What is the relationship between javabean and java? 3. What kind of use is Javabean? 4. What is RMI? 5. What is the characteristics of RMI technology? 6. What is EJB? 7. What is the relationship between EJB and Javabean?

9.1 Basic Concepts of Javabean 9.1.1 Background Generated by JavaBean

Software components refer to software sections that can be independently separated, easy to reuse. JavaBean is a software component idea based on Java platform. JavaBean is also an application programming interface (API) independent of platform and structure. JavaBean retains the technical essence of other software components, and increases the technical features ignored by other software components, making it the basis for complete software component solutions and is conveniently used in the network world on portable Java platforms. .

9.1.2 JavaBean Basic Concept

Although JavaBean and Java have a clear boundary, there is still a place where the JavaBean and Java is still more confusing, such as reuse, Java language can also create reusable objects for users, but it doesn't Manage rules or criteria for these objects interaction, users can use pre-established objects in Java, but this must have a rich knowledge of the interface at the code hierarchy. For JavaBeans, users can use a variety of JavaBean components in the application constructor tool without having to write any code. This function of using multiple components simultaneously without considering its initialization is an important extension of the current Java model, so JavaBean can also be said that JavaBean is an extension of the Java language in component technology. If you really want to definition, the JavaBean definition is that JavaBean is a reused platform independent software component that can perform visual operations directly in the software constructor tool. In the above definition, the software constructor can be a web page constructor, a visual application constructor, a GUI design constructor, or a server application constructor. JavaBean can be a simple GUI element such as buttons and scroll bars; can also be a complex visualization software component, such as a database view. Some JavaBean is not a GUI performance form, but these Javabeans can still use the application constructor to be combined, such as many controls on JBuilder actually do not have a GUI form, but you can still drag and drop them in your application. Generate the corresponding code. A JavaBean and a Java Applet are very similar to a very simple Java class that follows some strict protocol. JavaBean has all the advantages of Java language, such as cross-platform, but it is an extension of Java in component technology, so many aspects it and applet are very similar, applet also has all the advantages of Java language, and Java is browsing Extension of the server. In fact, they are all strictly followed by the Java classes of some protocol, and their existence is inseparable from the powerful support of the Java language.

9.1.3 Properties, events and methods of JavaBean

Basically, JavaBean can be seen as a black box, that is, it is only necessary to know its function without the software equipment of its internal structure. The black box only introduces and defines its external features and interfaces with other parts, such as buttons, windows, colors, shapes, and the like. As a model of a black box to view JavaBean as a component building block for accepting events and processing events for actions.

A JavaBean consists of 3: (1) Properties JavaBean provides a high-level property concept, attribute is not just a traditional object-oriented concept in JavaBean, which also got a property read and attribute written Support for the API. Attribute values ​​can be performed by calling the appropriate bean method. For example, it may be a name attribute that may be a name attribute. The value of this property may need to call the string getName () method to read, and the write attribute value may need to call the Void SetName (String Str) method. Each JavaBean property should usually follow simple method naming rules so that the application constructor tool and end user can find the properties provided by JavaBean, then query or modify the attribute value, and operate the bean. JavaBean can also make a timely response to changes in property values. For example, a JavaBean that displays the current time, if the clock is changed, the clock will immediately redraw, display the time of the current specified time zone. (2) Method's method in javabean is the usual Java method, which can be called from other components or in a script environment. By default, all BEAN's public methods can be called outside, but Beans generally leads to a subset of their public methods. Since JavaBean itself is a Java object, the method called this object is the only way to interact with its interaction. JavaBean strictly abides by object-oriented class design logic and does not allow the external world to access its fields (no public fields). In this way, method call is the only way to contact Bean. Different from ordinary categories, for some beans, low-level mechanisms with calling instance methods are not the main ways to operate and use beans. The public bean method is reduced to auxiliary status in Bean operation because two advanced bean features - properties and events are better ways to interact with beans. Therefore, Bean can provide the public method to allow customers, but it should be recognized that the Bean designer wants to see that the functionality of the BEAN is reflected in the attributes and events, not in manual calls and each method. (3) The main way of the event (Event) bean and other software components is to send and accept events. We can regard the BEAN's event support function as an input and output pin in the integrated circuit: Engineers connect the pin together to make components to communicate. Some pins are used for input, some pins are used to output, equivalent to sending events and reception events in the event model. Events provide a method of sending notification to other components for JavabEan components. In the AWT event model, an event source can register the event listener object. When an event source detects a certain event, it will call an appropriate event processing method in the event listener object to handle this event. 9.1.4 Characteristics of JavaBean

The component model specified by JavaBean 1.0 specifies the following characteristics: (1) Instructions: Mechanism of the components can publish their support and attributes, but also support in other components (such as Beans development tools) found this mechanism Mechanisms. (2) Properties: The appearance and behavior characteristics can be changed when designing Bean. The development tool has known its attributes by taking the bean, thereby issuing its properties. (3) Customization: Bean can be customized when designing its properties. There are two ways to support customization: By using the properties editor of Beans, or use more complex bean customizers. (4) Communication: BEAN is communicated with each other by events. The development tool can detect an event that a bean can receive and initiate. (5) Continue: Make the bean to store and restore its status. After the attribute of a bean is modified, it can be saved by the end of the object and can be recovered when needed. 9.1.5 Introduction to JavaBean Features 1. Attribute bean's properties describe its appearance or behavioral characteristics, such as color, size, and so on. Properties can be obtained and set through the GET / SET method at runtime. End users can change them through a GET / SET method for a particular property. For example, for the color attribute of the bean, the end user can change this color attribute through the attribute dialog provided by the bean. The change in color is actually implemented by the following method: public color getfillcolor (); public void setfillcolor (Color C); this basic GET / SET method naming rule defined by the simple properties. There is a class of properties represented by a boolean value in the simple properties called Boolean properties. The JavaBean API also supports index properties, which is very similar to the array in traditional Java programming. Index attributes include the same elements of several data types, which can be accessed through an integer index value, and thus referred to as index properties. Attributes can index a value that supports a certain range, this property is a simple property. Corpled INT specified. Index properties have four access methods, and its numerical arrays can be accessed by an element, or access to the entire array: public void setLabel; public string getLabel (int index); public void setlabel (String [] labels) Public string [] getLabels (); similar to the standard Java array similar to index value may be outside the index attribute array. At this time, the visitor method for operating the index property is generally throwing an ArrayIndexOutOfboundSexception running environment exception, which is the same as the behavior that is performed when the standard Java array index exceeds the range. Relative to simple properties is associated attributes and restriction properties. These two properties are modified when they are running or design, automatically notify the external world, or have the ability to reject the properties set to a value. Association properties make a notification to other Beans and containers when the property changes. Association Attributes generate a PropertyChangeEvent event when changing, passes to the listener of the registered PropertyChangeListener associated.

May or cancellation by the following method multicast event listener: public void addPropertyChangeListener (PropertyChangeListener l); public void removePropertyChangeListener (PropertyChangeListener l); PropertyChangeListener is an interface when the associated outer member needs associated with one attribute, it must Call the AddPropertyChangeListener () method provides a suitable object that implements the PropertyChangeListener interface. The PropertyChangeListener interface is used to report changes to the associated properties, especially when an associated property value changes, call the PropertyChange () method on all registered PropertyChangeListener interfaces. This method accepts a PropertyChangeEvent object that contains information about the specific properties to modify and its new and old values. The JavaBean API also supports another method for registering the listener and a specific associated property. If a bean developer wants to provide a listener registration based on a single property, he must support a pair method for each such property: add listener () and remove listener (). This works on the method just as previously introduced to the global event listener registration method, but both methods are for specific properties. One of the following examples define these two ways named NAME: Public Void Addnamelistener (PropertyChangelistener L); PropertyChangelistener L); When the bean external related part is registered to the Name property When it simply invokes the AddNameListener () method to register itself. When the Name property is modified, a notification to the event listener is sent by calling the PropertyChange () method. This is the same as the previous introduction, just here the listener receives only a notification of the Name property. The restriction attribute is internal verification, if unqualified will be rejected. Users can know the rejected attributes through an exception. The restriction attribute is verified by VETOABLEELISTENER interface. You can use the following method to register or revoke the interface: Public Void AddveToableChangelistener (VoID RemoveveToableChangeListener (VetoableChangeListener V); the processing mechanism for restriction attributes and associated properties is very similar, when the attribute is modified, the value is reached, The listener can select the modification of the reject attribute by throwing the PropertyVetoException exception. If an exception is thrown, this bean is responsible for processing this exception and restores the original value of this restriction attribute. Similar to the associated properties, the restriction attribute also supports an event listening method for a single attribute.

Here is an example: Public Void Addnamelistener (VetoableChangelistener L); PUBLIC VOID RemoveNameListener (VetoableChangelistener L); Inland Province and custom Beans are often developed into general components, and the developer is configured when establishing an application. This is achieved by two Java technology accompanying JavaBeans API. The first is that Java reflects the API, which is a class for the perspective class file and the properties and methods displayed. The second is the Java serialization API for generating permanent storage of classes, including its current state. Both techniques are used to enable Beans to explore and display with build tools, and modify and store them for specific applications. JavaBean's internal provision showing the properties, methods, and events of Beans. The internal provincial process is actually very simple. If there is a method of setting or acquiring the attribute type, it is assumed that the bean has this attribute, which can be used: public get (); public void set ( P); If you only find a get / set method, make sure PropertyName is read or write. In addition to the above-mentioned built-in internal provinces and custom methods, the JavaBean API also provides displayed interface BeanInfo, which is used in the Bean designer to show the properties, events, methods, and all global information of Beans. You can define your own bean information class by implementing the BeanInfo interface: Public class mybeaninfo imports beanfo .. BeanInfo interface provides a series of methods for accessing bean information, Bean developers can also provide a dedicated description file that BeanInfo is used to define bean information. 3. Continuous JavaBean is a component-dependent component, and the status may change because of some of the operation or some movements during development. When the state of the bean changes, the designer can save the changed state, which is the continuation of JavaBean. The JavaBean state can be automatically saved through the serial mechanism of the Java object, or the designer can be saved by customizing the status of the BEAN object. 4. Event JavaBean communicates between beans by passing events. BEAN tells another bean with an event to take actions or tell their status. The event is registered or published from the source listener and passes to one or several target listeners through method calls. JavaBean's event model Similar to the event model of AWT. The event model in JavaBean is defined by the event source and event destination. The event source is the initiator of the event, which triggers one or more event destination. Event source and event goals create a group of methods for event source adjustment event listeners. 9.2.3 Introduction to the Development Tool of Javabean

1. Borland's JBuilder uses JBuilder, developers can use any JavaBean components included in this product or from third party vendors to quickly develop applications, or use JBuilder's visual design tools and Wizard to create their own Reuse JavaBean components. JBuilder contains powerful JavaBean database components that meet the needs of the application related to the database. In addition, JBuilder provides a Java optimization toolset to provide comprehensive, high-performance development solutions for professional Java developers. JBuilder's component development environment, including component designers and bidirectional tool engines, is built in Java using JavaBean. About JBUILDER more information, you can visit Borland's Web Site: http://www.borland.com/jbuilder 2. IBM's Visual Age for Java IBM's release of Visual Age for Java makes the implementation of the Internet application of the client / server system become reality. This tool combines Java's rapid development environment with visual programming. Visual Age for Java is a programming environment that creates an application, applet, and Javabean components that make developers can focus on the logic design of the application. Visual Age for Java can help developers implement the tasks that often need in many applications, such as communication code, perform web connection on the enterprise level, and creation of user interface code. More detailed information on Visual Age for Java can be viewed by Web site: http://www.software.ibm.com/ad/vajava 3. SunSoft's Java Studio Java Studio is a visual assembly tool, a "ready" HTML creation tool and a reusable component development tool that is fully used by Java. Java Studio uses JavaBean technology that includes a rich and strong business component set, including charts, curves, and database access and operations supported by forms and spreadsheets. In addition, it is also included to create a network software auxiliary component. Auxiliary components include spreadsheets, whiteboards and chat components. Java Studio's Web URL is located in: http://www.sun.com/studio/9.2.4 Using Beanbox Test JavaBeanbdk (Beans Developmen Kit) is the Beans Development Toolbox issued by Sun, which is used with JDK, which can be generated Beans of the bean event model. The use of BDK is dependent on JDK. Beanbox is a tool for testing Beans in BDK to manage Beans properties and events. Beanbox is not a tool to build Beans. It is just a test tool, we can learn Beans.

9.3 RMI Basic Concept and Programming Introduction 9.3.1 RMI Basic Concept

Java RMI (Remote Method Invocation) - The remote method of Java is a distributed computing technology unique to Java, which allows the object to be run on a Java virtual machine to call the object of the object on another Java virtual machine, thus Enables Java programmers to easily distribute them in a network environment. Object-oriented design requires that each task is performed by an object that is best for this task, and the RMI deepens this concept in a step, enabling tasks to be done on the machine that is best suited for this task.

RMI defines a set of remote interfaces to generate remote objects. The client can call the remote object with the same syntax like the same syntax as the method of calling the local object. The classes and methods provided by the RMI API can process serialization required for all access communication and parameter reference requirements for accessing remote methods. Remote method calls similar to the remote process call (RPC) feature proposed by Sun's 1985. RPC also requires serialization parameters and returns numerical data, but because there is no object involved, the situation is relatively simple. Sun has developed an external data representation (XDR) system that supports data serialization. An important difference between RPC and RMI is that RPC uses fast and insufficient UDP protocols, RMI with low-speed and reliable TCP / IP protocol. Remote Method Call (RMI) and CORBA are all distributed computing technologies, and there is a disadvantage in the distribution, in order to help understand the features and use of RMI, it is necessary to discuss the difference between CORBA and RMI. Corba (Common Object Request Broker Architecture) is an Object Management Architecture (Object Management Structure) of OMG, which is a standard for object-oriented distributed system. CORBA is designed to be an open instructions that can be used in all programming languages, that is, Java customers on a machine can request another machine service with SmallTalk or C . It is because the independence of this language makes Corba so flexible and attractive. In order to adapt to language independence, CORBA uses very common standards as its interface. In different languages, remote calls, signatures, and objects have their own different definitions, so CORBA must be as neutral and open. It is this versatility that is a weakness of CORBA. When developers use CORBA, they have to use a new standard definition language interface, which requires developers to learn new programming interfaces, thereby reducing transparency of the remote model. RMI is developed for Java's distributed computing in Java. The standard for remote call is developed for Java and application Java's natural Java signature and call, which makes RMI relatively transparent to Java developers and is easy to implement. RMI is closely integrated with Java language to provide very good fault tolerance compared to CORBA and to abnormally. Although Java's RMI standard is not as independent like CORBA, Java itself is a stand-alone platform, which makes RMI a good choice in cross-platform distribution software development. RMI is the basic model of Java language in distributed computing, many Java distributed systems, including our EJBs, which are involved in RMI, is built in RMI. 9.3.2 General Structure of RMI System

The RMI system includes a 3rd floor, a Tandle / Framelayer (Remote Reference Layer), Transport, as shown: The client's end is requested when the client calls the remote method. Head call. The client references the end as the representative of the object on the remote machine. All basic functions shown above can not be seen on the client. The end code is born by the RMIC compiler, and the method call request is passed to the server object with a remote reference layer (RRL).

9.3.3 Construct distributed application system using RMI

RMI applications are usually composed of two separate programs: a Server and a client. A typical Server application creates some remote objects to be referenced, and waits for the client to call the method of these remote objects. A typical Client application gets a remote reference for one or more remote objects on the Server, and calls the methods of these objects. RMI provides mechanism for Server and Client communication and delivery information. Such an application is called a distributed object application. Distributed object applications require location remote objects: applications can use one of two mechanisms to get references to remote objects. The application can use the RMI naming tool RMIREGISTRY to register its remote object, or transmit and return a reference to the remote object as in general operation. And remote object communication: Communication details between remote objects are processed by RMI. For programmers, remote communication is like a standard Java method called. Loading the class by-code code that is transmitted: Because the RMI allows the caller to pass objects to remote objects, it provides the necessary mechanisms that deliver data and load an object code. The figure below describes a RMI distributed application that uses a registration mechanism to get a remote object reference. The Server Call registrar links a remote object and a name. The Client party looks for remote objects through the name in the registrar in Server. The figure also shows that the RMI system uses an existing web server to load the class bytecode, and transmits the bytecode between Server and Client when needed.

An important and unique feature of RMI is that it can dynamically download the bytecode (or simple code) of an object class that is not defined in the recipient's virtual machine. The type and behavior of an object, which can only be available in a single virtual machine, which can be passed to the other may be a remote virtual machine. RMI communicates the object along with its true type, so behavior does not change when these objects are passed to another virtual machine. This allows new types to introduce a remote virtual machine to dynamically expand an application's behavior. Like other applications, a distributed application using Java RMI is also consisting of interfaces and classes. In the interface define some methods, classes defined in the interface, and define some other methods. In a distributed application, some implementations require resident on different virtual machines. Objects with methods that can be modified across the virtual machine called remote objects. An object is a remote object by implementing a remote interface, which has the following feature: 1) A remote interface is derived from java.rmi.Remote. 2) Each method in the interface must declare the java.rmi.RemoteException, except for other special exceptions. When the object is passed from a virtual machine to another virtual machine, the RMI is different from the non-remote object. For remote objects, the RMI passes a remote end of the recipient virtual machine, not a copy of an object. The end as a local identification or agent of the remote object, is a remote reference for the caller. The call party calls a method of local end, which is responsible for processing method calls for remote objects by local ends. The end of a remote object implements the same interface as the remote object. This allows one end to be converted to any of the interfaces implemented by the remote object. This also means that only methods defined in the remote interface can be called on the recipient virtual machine. When you use RMI to develop a distributed application, you need to follow steps below: 1) Design and implement your distributed application components. First, determine the structure of the application, which components are local objects, which should be remotely accessed. This step includes: Defining a remote interface: A remote interface defines a method that can be remotely called by the client. The client programming remote interface instead of a class that implements these interfaces. A part of the design of such an interface depends on the local object as the parameters of these methods and the return value. If there is no such interface and class existence, you need yourself to be defined. Implement a remote object: Remote objects must implement one or more remote interfaces. Remote object classes may include other interfaces (local or remote) and methods (only available locally). If there is a local class as a parameter or return value of these methods, these classes must also be implemented. Implement the client: Users using the remote object can be implemented at any time after the remote interface is defined, including the remote object being expanded. 2) Compile the source program and generate the end. This is a two-step operation process. The first step is to compile the source file using the Javac compiler, which contains a remote interface and its implementation part, a Server class, and a Client class. In the second step, use the RMIC compiler to generate the end of the remote object. RMI uses a remote object's end class as a client's agent, allowing the client to communicate with the same specific remote object. 3) Make the class can be accessed through the network. This step makes everything related to the remote interface, end, and other classes that need to download to the client party via a Web Server access. 4) Start the application. The launch application includes running the RMI Remote Object Registration Program, Server, and Client.

9.3.4 An example of a simple RMI, although an example of a simple but complete RMI distributed application, the program consists of two parts; the Server party including the remote object and the remote method of calling the Server SayHello () get a string " Hello World "and outputs the CLIENT of the string. 1. Construct a remote interface Hello: package hello; public interface hello extends java.rmi.Remote {// RMI application must inherit Java.rmi.Remote string Sayello () throws java.rmi.RemoteException; // Definition can be called remotely Interface} 2. Complete the Server program, define the HelloIMPL class to implement the Hello interface:

package hello; import java.rmi *;. import java.rmi.server.UnicastRemoteObject; public class HelloImpl extends UnicastRemoteObject implements Hello // implement the interface Hello {private String name; public HelloImpl (String s) throws java.rmi.RemoteException {super (); // call the parent class constructor Name = S;} public string Sayhello () throws remoteexception {return "Hello World!"; // Implement the method of Hello interface definition} public static void main (String args []) {System.SetSecurityManager ()); // Setting the security policy required by the RMI program try {helloimpl obj = new helloimpl ("HelloServer"); // Generate an instance of HelloImpl Naming.Rebind ("HelloServer", OBJ) ; // Bind this instance to a name system.out.println ("HelloImpl Created and Bound In the Registry to the name HelloServer);} catch (exception e) {system.out.println (" HelloImpl.main : an Exception Occured: "); E.PrintStackTrace (); // Generate an exception, print the error message}}} The Server party generates a remote object and binds with a name" HelloServer "that can be dialogue with the customer. The Client end can look for the corresponding remote object according to the name, and then call its remote method.

3. Complete client side program package hello; import java.rmi *;. Public class HelloClient {public static void main (String args []) {System.setSecurityManager (new RMISecurityManager ()); // set security policies need try {Hello RMI Obj = (Hello) Naming.lookup ("HelloServer"); // Get a Hello remote object from the server string message = obj.SAYHELLO (); // Remote call Hello method system.out.println (Message); // Print the output} catch (Exception E) {System.Ost.Println ("Hello Client: An Exception Occured); E.PrintStackTrace (); // If there is an abnormality, output exception information}}} Client takes Java The LOOKUP () method of the Naming class in the .rmi package obtains the remote object OBJ, then call its remote method SayHello () to obtain a string "Hello World" and output it on the screen. To run these programs, there are some work to do, these programs are named Hello.java, HelloImpl.java, HelloClient.java, they are placed in D: / Hello directory, in Windows Next, you need to run them in the command window: 1. Set classpath =% ClassPath%; D: / 2. Compile the source code under D: / Hello: javac -d .. * .java 3. In the generation of the end and frame modules, first switch back to D: / rmic -d. Hello.HelloIMPL 4. Run the RMI Remote Object Registration Program Start RMIREGISTRY 5 in D: / Under Run server program java -djava.security.policy = my.policy hello.policy = my.policy helpho.policy = my. In D: / Up Run Client Program Java -Djava.security.policy = my.policy Hello.HelloClient Among the steps of the 5th and 6, My.Policy appears in the step. Pocument, this file is related to the Java security mechanism. We don't need security restrictions in this program, so we can set the permissions to access. My.Policy is as follows: grant {permission java.security.Allpermission;}; You must remember to set this file, otherwise RMI will "reject access" errors. If you want to know other secure mechanisms of Java, you can refer to the information about Security in Java.

9.4 EJB Introduction 9.4.1 EJB The background of EJB EjB has a big promotion for Java technology, because EJB is mainly for enterprise-class applications, which makes Java have an enterprise application. Similarly, EJB is also built on Java language, like JavaBean, Java Applet, is also complied with a certain normative Java program, but this is a complex specification.

Traditional distributed applications are based on Client / Server structures, and in recent years, people have found a lot of shortcomings based on Client / Server architecture, such as: If the client's code needs to change, then client programs on all machines To reinstall; if a machine has a non-fixed damage, then you have to reinstall the client software on other machines to be used. BROWSER / SERVER-based applications do not have more shortcomings, we can use any browser machines to work, because all program logic is on the server, so the server-side code changes do not need to be used as customers. Did the browser does anything again. Due to these advantages of the Browser / Server structure, there have been many research and practices in recent years on Browser / Server program development model. Because Browser has no way to indicate complex program logic, there must be a layer between the Browser and Storage Media Database indicating the interface, which is responsible for complex program logic. This is what we said, in the Brower / Server structure, our job is to develop server-side components, but develop server-side components is very troublesome. Because the server-side component must accept a number of client requests, it must have multi-threaded and transaction processing, and these are also difficult for server-side components development. 9.4.2 EJB Summary In fact, EJB is the norm of Java in an enterprise application, so EJB is more complicated, EJB is just a component of the component, and in order to let EJB run up, there are many other things, such as containers, applications Server, etc., these are closely linked with EJB, because EJB is generally used in web applications, so there is a web server, and EJB clients can also be any Java programs, such as applet, servlet, etc. Therefore, EJB is just part of the enterprise application platform, and this enterprise application platform is Sun's J2EE (Java 2 Enterprise Edition). And WebLogic we mentioned above, WebSphere is actually in line with J2EE's enterprise application platform.

The definition of EJB in the document released by Sun is: EJB is a component architecture for developing and deploying multi-layer structures, distributed, object-oriented Java application systems. Adopting EJB can make the development commercial application make it easy, the application system can develop in a support for EJB, and deploy in other EJB environments after development, with the changes in the demand, the application system can not modify the migration to Other functions, more complex servers.

EJB simplifies the development process of multi-layer architecture application system. In the development of a distributed application system, there are many advantages in the method of multi-layer architecture, such as increasing scalability, reliability, flexibility, etc. of the application system. Because the server-side component can be modified according to application requirements, and the component is not related to the location and application in the network, the system administrator can easily reconfigure the system's load. Multi-layer architecture is ideal for business transaction systems for large data volume, especially in web-based applications, requires multi-layer architecture to support fast applet downloads of thin clients and browsers, and more and more systems are beginning to start Multi-layer architecture method, so-called multi-layer structure, can help understand: In the multilayer structure, the database is considered a layer, and the client is calculated, and the client and database are collectively referred to as N-2. Layers, the N-2 layer is mainly the logic of the program. The role of EJB is to represent the logic of the program and provide an interface to access the database in this N-2 layer. EJB is divided into two categories, one is entity bean (entity bean), which has a corresponding relationship in this EJB and database, which can automatically update the content in the table when data changes. Another category is a dialogue bean. This EJB is used to interact with the client, representing the logic of the program, we can use these two EJBs to easily build your own multi-layer system. EJB refers to a new height of Java's "Write Once, Run Anywhere", and the server-side component is executed within the component execution system, the specification means defines the services required by the component execution system, and the components that are developed in accordance with the EJB specification Any system that supports EJB. EJB is actually executed in the container. Sun also releases the specification of the EJB container. EJB can run in any compliant container. The container is actually serving EJB, such as EJB needs transaction, multi-threading and Security mechanism and other services. 9.4.3 EJB Soft Software Model Introduction JavaBean is also a component, but it is not a server-side member, which we call JavaBean is lightweight, while EJB is heavyweight.

The idea of ​​the soft member model is to create reusable components and combine it into the container to obtain a new application system, the component model defines the basic architecture of the component, the structure interface structure, and the mechanism of other components and containers interaction, etc. . With the specifications of the component model, component developers develop components that implement the application logic, while application system developers combine these pre-developed components into an application system, which can also be used as new components. Soft build model ideas have been quickly popular in the software development community, as it can reach these purposes: reuse, high-level development, automated development, simplifying development processes, etc. JavaBeans, EJB, COM / DCOM, etc. are examples of soft components models. There are two types of soft component models - client components and server-side component models. The client component model such as JavaBeans is specifically designed for handlers and user interface issues; server-side component models, such as EJB, providing infrastructure to middleware-oriented middleware. The server-side component model links the development and middleware of the component model. Enterprise-level intermediates are known for their complexity, but it refers not only to application logic, concurrency, and scalability issues, but also to how to combine incompatible systems together. The server-side component model solves the complexity problem of middleware development, which makes the middleware developers focus on the logical part of the application system without handling synchronous, scalability, transaction integration, network, distributed object framework, etc. Complicated complex issues in the application system. The EJB component model is shown below:

The EJB component model provides developers with support: 1. The component contains application logic 2. Reusable member 3. Scalability 4. Resource management 5. Business support 6. Conaciation Management 9.4.4 Relationship between EJB and other technologies

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

New Post(0)