MASTEREJB 2 Reading Note - RMI-IIOP and JNDI TUTORIAL section

zhaozj2021-02-16  64

This article is part of the master ejb 2 for reading notes. Because I am not very familiar with EJB, there is a problem in the article, I welcome the discussion, email or msn: zhang1feng@hotmail.com

The following is Appendix A: RMI-IIOP and JNDI TUTORIAL reading notes.

1. RMI-IIOP (Java Remote Method Invocation over the Internet Inter-ORB Protocol)

l It is a simple, effective network communication mechanism;

l Enable objects in memory, Different physical machines in the Java virtual machine;

l RMI-IIOP is not the only choice for remote call, or you can use Java's RMI mechanism. RMI is the most original mechanism for remote calls in Java, placed in a java.rmi package. RMI-IIOP is a special version of RMI, mainly to be compatible with CORBA, which uses Java.RMI packages and Javax.RMI packages. RMI has some very useful features that are not in RMI-IIOP, such as distributed garbage collection, object activation, downloadable Class files, etc. However, RMI-IIOPs must be used in EJB and J2EE instead of RMI.

l Basic concept:

N Remote Producure Call (RPC): A process that allows a process (Producure) to call the process of other machines;

N Remote Method Invocation (RMI): Mechanism that allows distributed objects to communicate with each other. It allows objects to remotely call, not just the process. This can use object-oriented properties in the program, such as polymorphism, inheritance, packaging, etc .;

l Why do you want to use RMI-IIOP instead of RMI? Because there is still some problems in RMI:

n Marshalling and UNMarshalling (Assembly and Decomposition): Because the physical structure of different machines may be different, the data transmitted by each other should be assembled or decomposed to accommodate different types of machines.

n Parameter Pass: There are two main methods for passing the parameters when the Java call function: value transfer and reference delivery. Because it is difficult to operate in remote calls, the main use value is passed, but the value is passed to copy the parameters.

N network or machine reliability: In a virtual machine, if the virtual machine is embarrassed, the entire program will be paralyzed, so there is no need to consider too much. However, in remote calls, if the network is paralyzed or has a virtual machine involved in call, it will cause an error, which is a programmer to consider these issues.

n RMI-IIOP has made a lot of things to solve the above problems, which reduces programmers to handle these issues.

l Remote interface. Why do you have to use interfaces instead of specific classes? First of all, you must explain the concept of the interface:

n interface: It is the purpose of exposing some of the information of the class, such as the name and parameters of the function; hide the specific implementation. The client only faces the final result: the function of the object is exposed.

N Implementation: Core logic implementation.

n Separate the interface with implementation, you can change the specific implementation without modifying the client's code.

N RMI-IIOP uses this idea. Both transmitted in the network must be an interface, rather than a specific implementation, and directly calling the actual class is impossible. That is, it is necessary to establish an interface exposed to the remote interface (Remote Interface), which must inherit with java.rmi.Remote. N RMI-IIOP implements a mechanism for "local / remote transparency" through interface technology, to implement this mechanism, it uses two interfaces:

u stub: He accepts the call to the remote object, and then the agent (DELEGATE) calls to the server, which makes the remote call are just like local calls. You can imagine stub just like a touchholder, she knows how to find true objects on the web, because calling is local stub, so many nets have a cumbersome problem on the network is hidden.

u Skeleton: Receive the call or from STUB calls and proxy these calls to actual implementation, she is like STUB to provide a convenient way to remote objects to hide network issues.

The U J2EE server has an automation tool that generates stub and skeleton, such as a tool with a Sun's J2EE Server: RMIC.

u Note: I personally think that two interfaces of Stub and Skeleton must have two specific implementations. The two specific implementation work should be to establish a socket connection between the client and the server, through the underlying data communication. The purpose of the object method call.

l object serialization and parameter transmission

Most of N stub and skeleton are processing parameters.

N When using the RMI-IIOP to call the remote object, all parameters are passed. If the value is transmitted, it will cause a lot of problems, such as: An object is also referenced to another object, the memory addressing method of the other machine Different machines, even some references cannot be transferred at all, etc., to solve these problems, using Java's object serialization mechanism.

N object serialization: is in the form of transforming objects into byte streams. Want to serialize an object, very simple, just let this object implement the java.lang.Serializable interface, this interface does not define any method, it is just a tag interface, he marks your objects can be Serialization and deserialization. WriteObject () and readObject () can be overloaded from define sequence.

N serialized rules:

u Basic type (int, long, float, etc.) can be automatically serialized;

u If an object is not allowed to be serialized, you can add the transient keyword in front of the object; otherwise, if this object does not join the transient keyword nor implements the serializable interface, it will report an error when serialization.

The child object referenced by the N object, as long as the above rules are met, it will be automatically serialized by Java.

N What circumstances should I mark an object as Transient?

u object is too large;

u Objects contain resources that cannot be transferred to remote machines, such as database connections or socket connections;

u objects include sensitive information such as passwords.

N object serialization is a Heavyweight operation.

N RMI-IIOP and Object Series u If the reference is passed, this parameter must be a remote object, and in actual calls, the parameters are actually replaced with the Stub of this remote object, so essentially the value is delivered.

n If you want a Client to find Server, SERVER must release yourself, this is to use another mechanism: JNDI.

2. JAVA Naming and Directory Interface

l JNDI is an API of J2EE, providing a standard excuse to locate resources in the system.

l Basic concept:

n Naming Service: Very like a phone operator, you don't have to remember the phone number and just provide the name of the other party. It mainly plays two roles:

u Set the name to the object, which is called binding binding. This is like a telephone company like a username and phone number.

u Provide a mechanism to be locate (LOOK UP) to the object.

n Directory Service: is an expanded and reinforced Naming Service, which can operate attributes as directory. A directory is a set of directory systems connected together. He has a tree-shaped hierarchy inheritance, and he is very similar to a database system in some ways.

n aotomic name: is a simple, basic, independent name;

n compound name: It is a name that is polymeric the zero or more atom name;

N binding: The association between the name and the object;

n Context: It is an object containing zero or more binding;

n Naming System: It is a set of connected context;

n Namingspace: It is all the names included in the Naming System;

n Composite Name: It is a composite name that uses multiple Naming System;

l There are many products that provide directory services, but they are not compatible, so Sun provides JDBC JNDI interface to unify these products, and its advantages have:

n You can operate all directory systems as long as you learn an API;

n hide the specific implementation details of the directory system;

n You can read Java objects from the directory system using JNDI;

n can connect different types of directory systems.

l There is the following role in JDI in J2EE:

n Get User Transaction Interfaces in JTA;

n Connect to the resource factory, such as: JDBC or JMS driver, etc .;

n Let a bean find other beans.

l JNDI's structure two blocks:

n Client API: The function used to operate the directory, these functions are the same for all directory systems, and we are actually primarily learning these functions when learning JNDI. Just like learning the Connection, Statement, ResultSet in JDBC;

N Service Provider Interface (SPI): This is an interface to which the directory system manufacturer is provided. It is independent of each manufacturer but can also provide special functions of different products like JDBC. l Entering the starting point of a directory system called Initial Context, you can use Initial Context Facotry to create Initial Context, most of this factory is the driver of JNDI.

l In the J2EE environment, if you want to get an initial context, you must provide some information:

N J2EE Server IP address and port number;

N JNDI tree starting point;

n The user information of J2EE Server can operate.

l Note: Some J2EE Server requires a long time when creating an Initial Context, so you should cook after creating an Initial Context.

l You can get Initial Context:

Javax.naming.context cxt = new javax.naming.initialcontext (system.getproperties ());

Java -djava.naming.factory.initial = com.sun.jndi.fscontext.reffsContextFactory -Djavax.naming.Provider.URL = file: C: /

The first -D parameter specifies the factory class that creates Initial Context; the second parameter specifies the entry point of the directory tree.

l After INITIAL Context, JNDI operation can be performed, and the common operation is:

n List (): Data from the current context;

n lookup (): Move from the current context to another Context; you can also find the object bound to the tree;

n bind (): Bind the object to the JNDI tree, actually writes data in the tree.

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

New Post(0)