Group communication uses the terms group and member. Members are part of a group. In the more common terminology,a member is a node and a groups is a cluster. We use these words interchangeably.
我们在组通信中使用术语组和成员.成员是组的一部分.成员是节点而组是集群.
A node is a process, residing on some host. A cluster can have one or more nodes belonging to it. There can be multiple nodes on the same host, and all may or may not be part of the same cluster.
节点是一个主机上的一个进程,一个集群可以有一个或多个节点.在一台机器上可以有多个节点,这些节点可以全部属于一个集群,也可以部分属于一个集群.
JGroups is toolkit for reliable group communication. Processes can join a group, send messages to all members or single members and receive messages from members in the group. The system keeps track of the members in every group, and notifies group members when a new member joins, or an existing member leaves or crashes. A group is identified by its name. Groups do not have to be created explicitly; when a process joins a non-existing group, that group will be created automatically. Member processes of a group can be located on the same host, within the same LAN, or across a WAN. A member can be part of multiple groups.
Jgroups是一个组通信组件.进程可以加入一个组,发送消息到所有成员或单个成员,并接受来自组内成员的消息.程序追踪每个组内的每个成员,但有成员加入,退出或毁坏时组内各个成员都会得到通知.组以其组名为标记,组的创建不必显示,当进程加入一个不存在的组时,组即可自动被创建.组内成员所在进程可以位于同一台机器上,也可位于局域网或广域网.一个成员同时可以属于多个组.
The architecture of JGroups is shown in Figure 1.1.
It consists of 3 parts: (1) the Channel API used by application programmers to build reliable group communication applications, (2) the building blocks, which are layered on top of the channel and provide a higher abstraction level and (3) the protocol stack, which implements the properties specified for a given channel.
jgroups体系结构如图1.1.
它包含3部分.1)channel API,用于程序员实现可靠的组通信应用程序.2)building blocks,位于通道的上层,提供更抽象的服务.3)协议栈,实现了通道的一些属性.
This document describes how to install and use JGroups, ie. the Channel API and the building blocks. The targeted audience is application programmers who want to use JGroups to build reliable distributed programs that need group communication. Programmers who want to implement their own protocols to be used with JGroups should consult the Programmer's Guide for more details about the architecture and implementation of JGroups.
这篇文档主要描述如何安装和使用jgroups.最终的阅读者是程序员,他们需要使用jgroups去实现基于组通信的分布式应用程序.如果用户要实现自己的协议栈,请参考用户手册去获取更细节的有关jgruops体系结构和实现的内容.
A channel is connected to a protocol stack. Whenever the application sends a message, the channel passes it on to the protocol stack, which passes it to the topmost protocol. The protocol processes the message and the passes it on to the protocol below it. Thus the message is handed from protocol to protocol until the bottom protocol puts it on the network. The same happens in the reverse direction: the bottom (transport) protocol listens for messages on the network. When a message is received it will be handed up the protocol stack until it reaches the channel. The channel stores the message in a queue until the application consumes it.
channel连接到协议栈,用户发送消息经过channel传到协议栈,然后传到最上层协议,该协议继续将消息传到下一协议,一直到该消息传到最底层协议,通过网络传输出去.同理,在最底层有协议监听来自网络上的消息,然后接受到消息并将他传送到协议栈直到channel,channel保存消息到队列直到应用程序来使用它.
When an application connects to the channel, the protocol stack will be started, and when it disconnects the stack will be stopped. When the channel is closed, the stack will be destroyed, releasing its resources.
The following three sections give an overview of channels, building blocks and the protocol stack.
当应用程序连接channel时,协议栈被启动,当断开连接时,协议栈被停止.当关闭连接时,协议栈被销毁,并释放相关资源.
下面三节分别给出了channel,building blocks和协议栈的综述.
1.1. Channel
To join a group and send messages, a process has to create a channel and connect to it using the group name (all channels with the same name form a group). The channel is the handle to the group. While connected, a member may send and receive messages to/from all other group members. The client leaves a group by disconnecting from the channel. A channel can be reused: clients can connect to it again after having disconnected. However, a channel allows only 1 client to be connected at a time. If multiple groups are to be joined, multiple channels can be created and connected to. A client signals that it no longer wants to use a channel by closing it. After this operation, the channel cannot be used any longer.
加入一个组并发送消息,进程必须创建一个channel并用组名进行连接(所有有相同组名的channel组成一个组).channel相当于组的句柄.当已连接,成员可以发送和接收消息.成员通过断开channel连接退出组.channel可以被重用.在断开channel后可以再次连接.但是,1个channel只允许一个客户端连接.当需要加入多个组,则必须创建多个channel并进行连接.当关闭一个channel时,一般以为着我们不再想使用它.
Each channel has a unique address. Channels always know who the other members are in the same group: a list of member addresses can be retrieved from any channel. This list is called a view. A process can select an address from this list and send a unicast message to it (also to itself), or it may send a multicast message to all members of the current view. Whenever a process joins or leaves a group, or when a crashed process has been detected, a new view is sent to all remaining group members. When a member process is suspected of having crashed, a suspicion message is received by all non-faulty members. Thus, channels receive regular messages, view messages and suspicion messages. A client may choose to turn reception of views and suspicions on/off on a channel basis.
每个channel有一个地址.channel总是知道组内其他成员有哪些.我们可以从任何一个channel获得成员地址列表,该列表称为view.进程可以选择表中某个地址发送单播消息(也可以发给自己),同样可以发送组播消息到该view的所有成员.但某个进程加入或离开组,或进程异常被检测出,一个新的view会发送到组内所有剩余的成员.当某个成员所在进程被怀疑有异常,一个猜疑消息亦会被其他没失败的成员接收到.所以,channel会接收到规则消息,视图消息和怀疑消息.客户端可以基于channel的设置关闭和开启接收视图消息和怀疑消息.
Channels are similar to BSD sockets: messages are stored in a channel until a client removes the next one (pull-principle). When no message is currently available, a client is blocked until the next available message has been received.
channel类似于BSD套接字.消息被存储在channel中直到被客户端移走.当当前没消息可用时,客户端会被阻塞知道下一个可用消息被接收到.
There is currently only one implementation of Channel: JChannel.
The properties of a channel are typically defined in an XML file, but JGroups also allows for configuration through simple strings, URIs, DOM trees or even programming.
The Channel API and its related classes is described in Chapter 3.
当前只有一种channel实现:JChannel.
channel的属性一般定义在一个XML文件中.当然,jgroups也支持其他的配置.
channel API和它相关的类我们将在第三章细说.
1.2. Building Blocks
Channels are simple and primitive. They offer the bare functionality of group communication, and have on purpose been designed after the simple model of BSD sockets, which are widely used and well understood. The reason is that an application can make use of just this small subset of JGroups, without having to include a whole set of sophisticated classes, that it may not even need. Also, a somewhat minimalistic interface is simple to understand: a client needs to know about 12 methods to be able to create and use a channel (and oftentimes will only use 3-4 methods frequently).
channels是简单的,原始的实现,它提供组通信的最基本功能,其设计的目标就是基于BSD套接字的简单模型,能被很好的理解并可广泛使用.因为许多应用程序只需要使用JGroups的这些小的子集功能,而不需要包含一整套的复杂的类,而且,简单的接口也易于被理解:一个客户端只需要知道12个创建和使用channel的方法(更多的时候只需要常用的3-4个).
Channels provide asynchronous message sending/reception, somewhat similar to UDP. A message sent is essentially put on the network and the send() method will return immediately. Conceptual requests, or responses to previous requests, are received in undefined order, and the application has to take care of matching responses with requests.
channel提供异步的消息发送/接收,类似于UDP.消息的发送本质上是传输到网络,发送函数即返回.回应消息被接收的顺序不确定,应用程序得自己区分响应消息和发送消息的对应关系.
Also, an application has to actively retrieve messages from a channel (pull-style); it is not notified when a message has been received. Note that pull-style message reception often needs another thread of execution, or some form of event-loop, in which a channel is periodically polled for messages.
另外,应用程序必须主动从channel中取数据,而不是当有消息被接收时主动通知应用程序.这种消息接收方式必须启动另一个线程来处理,或者事件轮循机制,周期性的从channel取数据.
JGroups offers building blocks that provide more sophisticated APIs on top of a Channel. Building blocks either create and use channels internally, or require an existing channel to be specified when creating a building block. Applications communicate directly with the building block, rather than the channel. Building blocks are intended to save the application programmer from having to write tedious and recurring code, e.g. request-response correlation.
Building blocks are described in Chapter 4.
JGroups的building blocks方式在基于channel之上提供了更复杂的API.building blocks在内部创建使用channel,或者需要一个已经存在的channel去创建building blocks.应用程序直接与building blocks通信而不再是和channel通信.building blocks可以将应用程序员从编写单调重复的代码中解放出来,如请求-回应关系代码.
building blocks将在第四章中详细介绍.
1.3. The Protocol Stack
The protocol stack containins a number of protocol layers in a bidirectional list. All messages sent and received over the channel have to pass through the protocol stack. Every layer may modify, reorder, pass or drop a message, or add a header to a message. A fragmentation layer might break up a message into several smaller messages, adding a header with an id to each fragment, and re-assemble the fragments on the receiver's side.
协议栈在双向列表中有一系列的协议层.所有通过channel发送和接收的消息都必须经过协议栈.每个协议层都可以修改,记录,传递或丢弃某个消息,或增加消息头等等.分裂协议层则可以将消息分成几个更小的消息并在每个小消息上加一个头,然后在接收端重新组装这些片段.
The composition of the protocol stack, i.e. its layers, is determined by the creator of the channel: an XML file defines the layers to be used (and the parameters for each layer). This string might be interpreted differently by each channel implementation; in JChannel it is used to create the stack, depending on the protocol names given in the property.
组成协议栈的协议层,是由channel创建者决定的,其配置的xml文件定义了要使用的各协议层(以及各协议层参数).这些配置属性对每个channel的实现可能不同,JChannel的实现中,协议栈的创建是根据属性中的协议名而来的.
Knowledge about the protocol stack is not necessary when only using channels in an application. However, when an application wishes to ignore the default properties for a protocol stack, and configure their own stack, then knowledge about what the individual layers are supposed to do is needed. Although it is syntactically possible to stack any layer on top of each other (they all have the same interface), this wouldn't make sense semantically in most cases.
如果仅仅是在应用程序中使用协议栈,那有关协议栈的知识可以不了解.但是,当一个应用程序不想使用默认的协议栈而想配置一个自己的协议栈,则有关每个协议的相关知识还是需要了解的.虽然语法上每个协议可以随意配置,当大部分情况下在语意上可能并不正确.