Open-source framework analysis and Analysis of JBoss remoting

Source: Internet
Author: User
Tags jboss

Open-source framework analysis and Analysis of JBoss remoting
Analysis of JBoss remoting ------------- bluedavy http://blog.bluedavy.cn

Because the image cannot be pasted, read the full text and download the complete PDF content: JBoss remoting
1 distributed application Overview
In the Java field, compared with centralized applications, the first obvious problem to be solved is how objects communicate. In centralized applications, when other objects need to be called, generally, you only need to use the corresponding new object instance, inject the required object through IOC container, or obtain the required object through the factory, and then call it directly, it is different to convert to a distributed application scenario, because the caller or client only has a remote object interface, but does not implement it. How can I initiate a remote object call on the client, how does a remote object receive requests? This is a problem that must be solved by distributed calling.
To solve this problem, we must first solve how to transmit byte streams from one machine to another, the two machines need to use the standard transmission protocol to transmit byte streams from one machine to another. Currently, two transmission protocols are available: TCP and UDP, other HTTP, FTP, and telnet protocols are extended based on TCP, while DNS, TFTP, and other protocols are extended based on UDP. TCP is short for tranfer control protocol. It is a connection-oriented protocol that ensures reliable transmission. It is transmitted over TCP protocol to produce a sequential data stream without errors. The sender and receiver must establish a connection between two pairs of sockets to facilitate communication based on the TCP protocol. When a socket (usually a server socket) is waiting to establish a connection, another socket can require a connection. Once the two sockets are connected, they can perform two-way data transmission, and both parties can send or receive the data. UDP is short for user datasync protocol, is a connectionless protocol. Each datagram is an independent information, including the complete source address or destination address. It is transmitted to the destination in any possible path on the network, therefore, whether or not to reach the destination, the time to arrive at the destination, and the correctness of the content cannot be guaranteed.
So how can we implement network communication in Java? Java provides the java.net package to implement network communication. socket and serversocket can be used to implement network communication based on the TCP protocol, typical Network Communication Based on java.net socket Program Is implemented in this way: whether a port of the server listen (listener) has a connection request, the client sends a connect (connection) request to the server, and the server sends an accept (accept) to the client) message, a connection is established, and the server and client can communicate with each other through the send, write, and other methods; using java.net's ingress ramsocket and ingress rampacket can be used for UDP-based network communication.
It can be seen that the java.net package can easily implement distributed communication. However, to call remote objects, some encapsulation processing is required, java itself also provides remote object call protocols such as RMI. For small distributed applications, a complete distributed support framework or platform is not required,
Bluedavy http://china.osgiusers.org http://blog.bluedavy.cn-1-
Open-source framework analysis and Analysis of JBoss remoting
RMI, JMS, Hessian, or WebService can directly implement remote communication or calling. However, for large-scale distributed applications, it is necessary to upgrade to the framework level to better solve the more challenges posed by distributed applications compared to centralized applications, for example, support for remote calls of multiple protocols, reliable and efficient thread pool scheduling, minimize performance degradation after applications become distributed, handle exceptions caused by remote calls, and support for multiple call Methods and so on.
Compared with centralized applications, let's look at the differences brought about by distributed applications. The first obvious problem is naturally how to call remote objects, RMI, Hessian, and WebService are the most famous java fields. Based on these methods, remote object calling methods can be called from the client. What is derived here is the method of remote object calling, for example, synchronous and asynchronous. The second problem is a typical problem brought about by distributed processing, that is, remote objects receive requests through listening ports, to avoid every request blocking reading, after receiving the request, you need to start a new thread to execute the object method. The third problem is that when the application becomes distributed, exceptions that do not exist in centralized applications, such as network disconnection and thread occupation caused by long execution of a method, this requires that remote calls be capable of handling exceptions, such as timeout interruptions and automatic retries. The three problems described above are obvious problems in distributed applications, this is also a basic function that the remote call framework should provide. Of course, these three questions also contain more details, for example For example, in the first question, the possibility of transparent remote calls and the ability to compress the stream for transmission can be derived to increase the transmission speed.
2 analyze JBoss-remoting
There are many distributed frameworks in the Java field. It is necessary to analyze an existing remote call framework, whether it is intended to adopt existing results or build a distributed framework by itself, JBoss remoting is a very powerful framework. Here, we will conduct an in-depth analysis on JBoss remoting to see how JBoss remoting solves these problems based on the packages provided by java.net, the JBoss remoting source code analyzed in this article is 2.2.2 _ SP2.
JBoss remoting supports multiple Protocol call methods for remote objects, such as socket, RMI, and HTTP. In this example, select the socket Method for remote call for analysis.
2.1 remote SOCKET call
2.1.1 usage
First, let's take a look at how JBoss remoting implements remote object calling in the most basic way like socket. For example, the client needs to call the getbyid method of the defaultuserservice object on the server side, the interface implemented by object A is userservice. A typical Implementation Method Based on the socket method of JBoss remoting is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.