large-scale applications are typically split into multiple subsystems.
For Java , these subsystems may be deployed in multiple different JVMs on the same machine or on different machines, but these subsystems are not completely independent and communicate with each other to realize business functions together.
For such Java applications, we call this a distributed Java application.
For distributed Java applications, there are typically 2 ways to accomplish this:
1. Communication between systems based on message mode
Communication between systems, it is necessary to send messages outward, the message can be a byte stream, an array of bytes, or even a Java object.
Inter-system communication between messages is usually implemented based on network protocols. Commonly used protocols are:TCP/IP,udp/ip.
TCP/IP is a reliable network data transfer protocol. TCP/IP requires that both parties first establish a connection before transmitting the data. TCP/IP is responsible for ensuring the reliability of data transmission.
UDP/IP is a network data transfer protocol that does not guarantee that data will arrive. Because UDP does not guarantee reliable data transmission, performance can be better.
TCP/IP and udp/ip can be used to complete the transfer of data, but to complete communication between systems, the data needs to be processed. For example: Read and write data, according to POSIX standard, divided into: synchronous io, asynchronous io. the most commonly used in synchronous io is BIO (Blocking io) and NIO (non-blocking io).
Bio: From a procedural point of view,bio is A blocking mode when initiating IO read or write operations, freeing resources only when the program reads the stream or writes the stream to the operating system.
NIO: From a procedural point of view, when initiating an IO Read or write operation, it is non-blocking; when the Socket has a stream -readable or writable Socket , the operating system notifies the appropriate application to process, and the application then reads the stream into the buffer or writes to the operating system.
aio: For async io way. From a procedural point of view, when reading and writing, only the api read or write method. Both of these methods are asynchronous. For read operations, when a stream is readable, the operating system streams the readable flow into the read write
AIO simplifies program authoring compared to NIO , and reads and writes of streams are replaced by the operating system.
2. Realization of communication between systems based on Remote Call method
When communicating between systems, a remote Java implementation can be transparently invoked by invoking a local Java interface method . The details are done by Java or the framework.
It is still cumbersome to use Java packages to implement communication between systems based on message mode.
in order for developers to focus more on the processing of data, rather than focusing on technical details, the open source industry has created many excellent frameworks for inter-system communication based on the various protocols above . Mina .
Mina is Apache 's top-level project, built on Java NIO , and supports both TCP/IP and UDP/IP Two kinds of protocols. Mina has shielded the complexity of Java NIO usage and has done a lot of optimizations on performance.
The remote invocation method is to make the communication between the system as much as possible, so that the user feels the call is local to the remote call.
inter-system communication based on Java 's own technology for Remote call mode
There are two ways to implement remote calls in Java , such as RMI and WebService :
RMI: Is An important mechanism for implementing transparent remote calls in Java. In a remote invocation, the client has only the interface provided by the server side.
JDK 6.0Previous versions,RMIimplementations are based on theTCP/IP + BIOWay OF,RMIserver-side through startupRMIThe registered object listens on a port for an externally provided interface, and its implementation instance is bound to a stringRMIregister the object. RMIClient throughProxyaccess to the server-side interface is represented by theRMIthe server-side object strings, methods, and parameters that the client will access are encapsulated into an object, serialized into streams, and passedTcp/ip+bioTransfer toRMIserver-side. RMIafter the server receives the client's request object, resolves the object string, method, and Parameters in the object string from theRMIThe registered object finds an instance that provides a business function, then, in combination with the method to be accessed to reflect the fetch to the method instance object, the incoming parameter completes the call to the server-side object instance, and the returned result is serialized as a stream toTcp/ip+biomethod is returned to the client, and the client is deserialized to the object after it receives the stream and returns it to the caller.
Distributed Java Applications