TP properties...
-------------------------------
Address local_addr
1. When the protocol layer is started, the TP layer first obtains local_addr. If local_addr is null, the event is triggered.
Event. get_local_address: Wait for the upper layer to tell the TP layer local_addr, and then obtain the TP that interacts with the machines in the group to break through NAT.
For example, the TCP physical address is composed of the TP properties external_addr, bind_addr, bind_port, and port_range,
The logic is: If external_addr is not empty, the IP address is external_addr; otherwise, the bind_addr is used. If bind_addr is not empty, the IP address is
Bind_addr; otherwise, use inetaddress. getlocalhost () as the IP address, and iterate bind_port to bind_port + port_range.
The port is used if it is not used. Add the IP ing of local_addr-> IP + port to logical_addr_cache.
2. When processing MSG events in the down logic, if the loopback value is true, it indicates that the data to be sent by TP is used.
If the multicast in the group or the message is sent to itself, you can directly up the MSG backup without network transmission. If the network transmission is used, TCP will not accept
At this time, you need to determine whether the target address sent to yourself is compared with local_addr.
3. When sending data, you must set the source address of MSG to local_addr.
4. After receiving the data, if the loopback is true and the data is multicast and the source address is local_addr, the MSG event will not be up.
5. If local_addr is empty during protocol startup, event. get_local_address is triggered to obtain the value from the upper layer. Similarly, in the down Logic
It will be interested in the event. set_local_address event. when listening to this event, a new local_addr will be set, and the new
Local_addr-> IP + port ing is added to logical_addr_cache.
-------------------------------
Set <address> Members
This is a data structure for maintaining the Member addresses in the group, mainly when the event. tmp_view or
When event. view_change comes in, the current Members will be cleared, the new member address list will be added to members, and
The ing of removed Member addresses in logical_addr_cache can be deleted.
-------------------------------
Reentrantlock connectlock
Mutex lock is mainly used to synchronize the connection process and disconnect the connection process.
1. When event. Connect, event. connect_with_state_transfer,
Event. connect_use_flush, event. connect_with_state_transfer_use_flush
The Accepter thread and mapper can listen to connection requests in the group and send data to machines in the group. This process requires mutex lock to protect
2. In the processing down logic, when event. Disconnect enters, the Accepter thread and mapper release need to be disabled for TCP.
Puts the connection resource and memory hard-reference, and this process also requires mutex lock to protect
-------------------------------
Executor oob_thread_pool
Threadfactory oob_thread_factory
Blockingqueue <runnable> oob_thread_pool_queue
This thread pool configuration is mainly used to process local data uploads. There are two scenarios:
1. The local multicast or receiver is the data of the local user, and when the local user wants to accept the Data & when the data is of the OOB type
In oob_thread_pool, add a logic task to bring up the MSG.
2. After the TCP connection receives the data, if the MSG is of the OOB type, it will add a logic to oob_thread_pool to make up the MSG.
Task
3. The TP layer protocol will start this thread pool during initialization and close this thread pool during destruction.
-------------------------------
Executor thread_pool
Threadfactory default_thread_factory
Blockingqueue <runnable> thread_pool_queue
This thread pool configuration is mainly used to process local data uploads. There are two scenarios:
1. The local multicast or receiver is the data of the local user, and when the local user wants to accept the Data & when the data is not OOB type data
Add a logic task to thread_pool to make up the MSG.
2. After the TCP connection receives the data, if the MSG is not of the OOB type, it will add a logical task to thread_pool to make up the MSG.
3. The TP layer protocol will start this thread pool during initialization and close this thread pool during destruction.
-------------------------------
Timescheduler Timer
Threadfactory timer_thread_factory
Timesched is actually a thread pool time task scheduler. The difference is that common periodic tasks are executed after they are added.
The cycle of the task is fixed, and its task supports dynamically changing the execution cycle of the task itself. Timer is not only used in the TP layer, but also in the upper layer of the TP layer.
You can obtain the reference of this scheduler to schedule tasks. The use of this scheduler in the TP layer mainly includes
1. Delete the invalid ing in logical_addr_cache.
2. When bundler needs to send data, add the task for sending data
3. When adding an element, the who_has_cache set with a lifecycle will add a scheduled Delete task to the timer.
-------------------------------
Future <?> Logical_addr_cache_reaper
During TP layer initialization, a periodic time task is added to the timer. The logic of this task is to delete the logical_addr_cache file.
Mark the address ing of the deleted address-> IP + port, and the future returned by adding this task is the convenience protocol of logical_addr_cache_reaper.
Cancel the execution of this task when the task is destroyed. When the task is added, the specified latency and cycle are both logical_addr_cache_expiration.
-------------------------------
Socketfactory socket_factory
-------------------------------
Bundler
This attribute is important. It is used to cache the data to be sent and trigger sending of cached data in multiple dimensions. bundler is an interface, mainly
Three behaviors are defined. When the TP layer needs to send network data, the data is submitted to the bundler and then returned. When the bundler needs to send data
The request is sent to the TCP layer over the network.
---
Void start ()
Void stop ()
Void send (Message MSG)
---
In fact, there are two types of defaultbundler and transferqueuebundler.
----------
Defaultbundler ensures data transmission in two dimensions
-Map <singletonaddress, list <message> msgs is used to cache the MSG linked list sent to an address.
-Long Count indicates the total data size cached by the current bundler. If the data size exceeds a certain limit, it is sent.
-Int num_bundling_tasks: number of tasks being sent in Timer
Running Logic
1. When a message is added to the outside world, check whether the current count + msg. length is greater than the limit. If the value is greater than the limit, the sending of the TCP layer is triggered.
Otherwise, add MSG to the msgs ing and accumulate count
2. When a message is added, the system checks whether num_bundling_tasks is smaller than 2. If yes, it adds a message to the timer.
The data task in msgs. After the task is executed, num_bundling_tasks --
----------
Transferqueuebundler
-Blockingqueue <message> the MSG sent by buffer is first placed in the blocking queue.
-Map <singletonaddress, list <message> msgs same as above
-Thread bundler_thread: Business thread
-Long Count: Same as above
-Long max_bundle_timeout: The business thread obtains the MSG blocking time.
Running Logic
1. When a message is added to the outside world, it is placed in the buffer. If the space is slow, blocking will occur.
2. The start function starts the bundler_thread business thread. The running logic is
-A. If the current buffer size is null, the read value will be permanently blocked; otherwise, the value of max_bundle_timeout will be obtained after hibernation.
-B. If the MSG cannot be obtained when you wake up, return to a. Otherwise, you can determine whether data can be sent. The result is based on count.
The threshold is exceeded or the buffer space is used to exceed 90%, or the time for the thread to sleep in the process exceeds max_bundle_timeout.
To send data, call the TCP network layer to send msgs cached data. Otherwise, add the retrieved MSG to msgs.
----------
-------------------------------
Diagnosticshandler diag_handler
List <probehandler> preregistered_probe_handlers
-------------------------------
Concurrentmap <string, protocol> up_prots
This is a channel-name ing to the virtual protocol layer. The role of the virtual protocol layer protocoladapter is mainly, for example, several jchannels
You want to use a TP to transmit data. The structure is as follows:
In this way, after the TP receives the data, it must go to up_prots to find the Protocol linked list of the message based on the Logical Address, and then
This Protocol linked list, if the TP layer needs to trigger any event, if there are multiple Protocol linked lists on it, it needs to be up one by one
-------------------------------
Tpheader Header
The tpheader contains only one channl-name parameter. Such a header is added to the data sent from the TP layer. Initialization of this value
Event. Connect, event. connect_with_state_transfer,
Event. connect_use_flush, event. connect_with_state_transfer_use_flush
-------------------------------
Lazyremovalcache <address, physicaladdress> logical_addr_cache
Ageoutcache <address> who_has_cache
The data stored in this delayed cache is mapped from the logical address to the physical address. When the TP layer needs to send a piece of data
You need to use the physical address to establish a connection to send data, first find it in logical_addr_cache. If you find the sent data, otherwise up
Event. get_physical_address indicates the upper layer of the event. The data is ignored and the data is not sent. who_has_cache is in this logic.
The main function is that the business logic may send a certain address data consecutively, while the upper layer needs to process event. get_physical_address.
Time is required, which will lead to repeated computing at the upper layer. Therefore, before initiating a computing task, check whether who_has_cache contains any information.
This event
Bytes ----------------------------------------------------------------------------------------------------------
TP event...
Event. get_local_address
In the entire jgroups Event System, event. get_local_address only processes the event at the TP layer and jchannel. jchannel has
Attribute local_addr. Before the jchannel startup protocol layer, UUID. randomuuid is called to randomly generate a string representing
Local_addr of jchannel. [After the start protocol layer is called, if TP. local_addr is null in the start logic of the TP layer,
Event. get_local_address event, and the event is always up to the jchannel layer. This event is encountered in the jchannel up logic.
Return local_addr when an event occurs] the probability of this event being very low is that jchannel directly generates its local_addr and starts the protocol stack.
The parameter that triggers an event. set_local_address event is its local_addr. This event is handled in the protocol stack configured in TCP. xml.
Protocols of interest include TCP, tcpping, merge2, fd_sock, FD, verify_suspect, nakack, unicast, stable,
View_sync, GMS, streaming_state_transfer, all of which hold a local_addr attribute, In the down
Set the local_addr attribute for this event.
----------------
Event. set_local_address
As mentioned above, the TP layer will receive the event. set_local_address from the jchannel, and then set its own local_addr
----------------
Event. config
During the protocol stack initialization process, because the TP layer is newly initialized, during the initialization process, if the bind_addr parameter is not empty, it indicates
The address needs to be bound to the TP network. A map (bind_addr-> $ bind_addr) is encapsulated as the up protocol layer of the event. config parameter,
Protocols that are interested in this event include:
Fd_sock-> has the bind_addr attribute, and accepts event. config to read map. bind_addr and assigns it to bind_addr.
Verify_suspect-> same as above
Streaming_state_transfer-> same as above
----------------
Event. get_physical_address
In the TP layer, there are two logics related to the event. get_physical_address event. One is up and the other is down.
1. When TP needs to send data to a machine in the group, the physical address cannot be found in logical_addr_cache according to its logical address.
Event. The parameter is the logical address of the machine to be connected.
2. TP obtains the physical address from logical_addr_cache when processing the down logic.
The protocol layers that interest this event mainly include:
Tcpping-> there are two main points: one is to trigger a down + Logical Address to the TP layer when sending data to obtain the physical address
Address. In addition, when receiving the TP event. get_physical_addres event request, the physical address of the logical address will be searched.
And return NULL. The tcpping protocol is the end point of event. get_physical_address In the UP direction. The starting point of the UP direction is TP.
The end point in the down direction is the TP layer.
When You Need To Know A local_addr physical address, a down + logical address is triggered to get the physical address to the TP layer.
Jchannel-> same as above
----------------
Event. set_physical_address
This event corresponds to event. get_physical_address. The TP layer does not know the physical address of a logical address when sending data.
An event. get_physical_addres event will be up. After receiving this event, tcpping will go to the physical location of the Logical Address.
Address. After the event is found, the event. set_physical_address is down. The TP layer handles the event in the down logic.
Put the ing between the logical and physical addresses in logical_addr_cache. The protocol layer interested in this event has
Tcpping-> after receiving the address request from the TP layer, tcpping performs network operations. If the MSG data is processed in the MSG event
If it is the address information, it will encapsulate the address in event. set_physical_address and go down to the TP layer below it.
----------------
Event. get_logical_physical_mappings
After receiving the event in the down logic, the TP layer returns the logical_addr_cache content of the map structure. Only
Tcpping Layer Protocol
----------------
Event. tmp_view
Event. view_change
Maintain a property in the TP layer for Members to keep the addresses of all machines in the group. When the two events are received in the down logic
The upper layer is responsible for maintaining the machine information in the group. If a change occurs to the group members, members is updated using the information of the new group members,
At the same time, because each machine in the group is connected, the machine in the group that no longer appears is disconnected from it. Interested in this event
The protocol layer
Tcpping-> like the TP layer, tcpping maintains the machine address information in the group and sets members when the two information is received.
Nakack-> it also maintains the address information of the machine in the group, and does other things, etc...
GMS-> This layer is the birthplace of event. tmp_view and event. view_change. When the protocol layer detects changes in group members
Up & down events
Streaming_state_transfer-> it maintains the address of the machine in the group. When these two events are detected, members is updated.
----------------
Event. Connect
Event. connect_with_state_transfer
Event. connect_use_flush
Event. connect_with_state_transfer_use_flush
When receiving these events, the TP layer indicates that the jchannel calls the connect connection request, and the TP layer starts to start the connection-related attributes.
Serversocket port and Mapper. The protocol stacks that are interested in this event have
Jchannel-> jchannel triggers these events when calling the connect functions and triggers the events according to the requirements of connect,
Details are analyzed in jchannel again. When establishing a connection, jchannel will specify two parameters flushable & stateable. In this case, four conditions exist,
When jchannel is down, the event continues to go down at the GMS layer. At that time, null is returned to jchannel to complete the connect function.
GMS-> when the GMS receives such events, it will return null to the jchannel and continue to down the event and start operations at this layer.
Unicast-> mark the attribute disconnected as false, but only process event. Connect events.
Fd_sock-> when the event is received, a serversock is opened at the fd_sock layer, and fd_sock is directed to event. config.
The event is of interest. The bind_addr set by TP is used to establish the serversock. If there is no need to use the default port, this serversock Port
If fd_sock is configured with start_port, the port is scanned from this port until it is not used. The default value of start_port is 0.
Tcpping-> set the event parameter cluster_name to its own property group_addr.
----------------
Event. Disconnect
When the TP layer receives these events, the jchannel calls the disconnect connection request. What the TP layer does is to disable
Serversock and socket set. The protocol layers that interest this event are
Jchannel-> after jchannel calls the disconnect function, this event is triggered to go down.
GMS-> when the GMS receives such events, it will return null to the jchannel and continue to down the event and start operations at this layer.
Unicast-> mark the property disconnected as true
Fd_sock-> close the serversocket that is triggered when the connection is established.
----------------
Event. remove_address
After receiving this event, the TP layer deletes the ing corresponding to the logic address specified by the event parameter in logical_addr_cache. This event only has
Jchannel will be triggered. When jchannel calls init for initialization or set-local_addr, it is found that its localhost is not empty, it is deleted in
The ing in logical_addr_cache triggers event. remove_address to the TP layer.
----------------
Event. msg
MSG events are the main work of the TP layer. The TP layer is used to send data, and its sending logic is
1. Set the source address of MSG. The source address is a logical address expressed by TP. local_addr. If TP is not a virtual protocol layer
Use local_addr, otherwise it will not be processed because MSG has been set to local_addr for each virtual layer when it is down to the Virtual Layer
2. If the destination address of MSG is a physical address, it indicates that the MSG comes from the list of members in the tcpping layer for sending information to initialization,
It does not use nakack for retransmission of transmission failures, so the target address is set to null.
3. If the TP layer loopback = true, it indicates that the message from multicast or sent to its own MSG upper layer will be accepted. The default value is true, and then the target address will be viewed.
Whether the multicast address or target address is your own. If you need to copy the data to yourself, make a copy and encapsulate the MSG
The MSG event is up. This process is done by the thread pool. If OOB is used, it is given to the OOB thread pool. Otherwise, it is given to the default thread pool,
When processing and sending, There is a logic for distinguishing between the virtual protocol layer and the virtual protocol layer. If there is a virtual protocol layer
The name of the virtual protocol layer in the tpheader goes to up_prots and obtains the application up of the virtual protocol layer.
4. in step 3, If the destination address is not a multicast address, the MSG event is handled. Otherwise, the MSG must be transmitted to other machines.
5. send information. If bundler is used, only MSG is thrown to bundler. Otherwise, send the message by yourself. The logic of the send operation is: if the address
If it is a multicast address, the iterative logical_addr_cache takes out all the physical addresses to send messages. Otherwise, the messages are sent from logical_addr_cache according to the logic
The address goes to the physical address. If there is no processing logic mentioned above, the sending details are mentioned at the TCP layer.
----------------
TP. Socket accept data
The TP layer establishes a connection with all the machines in the group. After the connection receives the data, it sends the connection to the TP, encapsulates the data into MSG, and then
The processing logic is submitted to different thread Pools Based on Whether MSG is OOB or not. The processing logic is to shield itself from sending data to itself.
Network Message
----------------
TP-init & start
1. The main task of init is to start several time task scheduling timer, oob_thread_pool, thread_pool, instantiate who_was_cache,
Logical_addr_cache. If bind_addr is set, event. config is triggered.
2. The main task of start is to initialize if bundler is used; otherwise, direct message sending will cause blocking during sending. In addition, if
If local_addr is null, event. get_local_address is triggered to be obtained by jchannel.