1 Aralık 2022 Perşembe

HazelcastAPI MulticastJoiner Sınıfı - MulticastService Nesnesini Kullanır

Giriş
Şu satırı dahil ederiz
import com.hazelcast.internal.cluster.impl.MulticastJoiner;
Açıklaması şöyle
In the Hazelcast codebase, MulticastJoiner and MulticastService are two classes that work together to implement multicast-based node discovery and joining.

MulticastService is responsible for sending and receiving multicast packets on a network interface to discover other nodes in the same network. When a new node wants to join the cluster, it sends a JoinMessage to the multicast group, and existing nodes in the group respond with a JoinRequest message containing information about the cluster configuration.

MulticastJoiner is responsible for handling the joining process after a new node has been discovered through multicast. It establishes a TCP/IP connection between the new node and the existing nodes in the cluster.

The MulticastJoiner class extends the AbstractJoiner class, which provides a common base for all joiner implementations in Hazelcast. AbstractJoiner provides a set of common methods and properties that are used by all joiners in Hazelcast, including MulticastJoiner.

MulticastJoiner uses MulticastService to discover other nodes in the cluster through multicast. When MulticastJoiner receives a JoinRequest message from an existing node, it initiates the joining process by establishing a TCP/IP connection with the existing node.

The relationship between MulticastJoiner and MulticastService can be seen in the code where MulticastJoiner receives a JoinRequest message in its handleJoinRequest method. The method then calls the createNewConnection method of MulticastService to establish a TCP/IP connection with the existing node.

Overall, MulticastJoiner and MulticastService work together to implement the multicast-based node discovery and joining mechanism in Hazelcast.
public class MulticastJoiner extends AbstractJoiner {

  private static final long JOIN_RETRY_INTERVAL = 1000L;
  private static final int PUBLISH_INTERVAL_MIN = 50;
  private static final int PUBLISH_INTERVAL_MAX = 200;
  private static final int TRY_COUNT_MAX_LAST_DIGITS = 512;
  private static final int TRY_COUNT_MODULO = 10;

  private final AtomicInteger currentTryCount = new AtomicInteger(0);
  private final AtomicInteger maxTryCount;

  // this deque is used as a stack, the SplitBrainMulticastListener adds 
  // to its head and the periodic split brain handler job
  // also polls from its head.
  private final BlockingDeque<SplitBrainJoinMessage> splitBrainJoinMessages = 
    new LinkedBlockingDeque<>();
  ...
} 
doJoin metodu
INFO 8172 --- [           main] c.h.i.cluster.impl.MulticastJoiner       : [ip]:5702 [dev] [5.2.1] Trying to join to discovered node: [ip]:5701

findMasterWithMulticast metodu
Kod şöyle. Node sınıfı içindeki MulticastService nesnesini kullanarak bir multicast paket gönderir. Eğer cevap gelirse bu adresine Join işlemi başlatır. Eğer cevap gelmezse kendisini master kabul eder.
private Address findMasterWithMulticast() {
  try {
    if (logger.isFineEnabled()) {
      logger.fine("Searching for master node. Max tries: " + maxTryCount.get());
    }
    JoinRequest joinRequest = node.createJoinRequest(null);
    while (node.isRunning() && currentTryCount.incrementAndGet() <= maxTryCount.get()) {
      joinRequest.setTryCount(currentTryCount.get());
      node.multicastService.send(joinRequest);
      Address masterAddress = clusterService.getMasterAddress();
      if (masterAddress == null) {
        //noinspection BusyWait
        Thread.sleep(getPublishInterval());
      } else {
        return masterAddress;
      }
    }
  } catch (final Exception e) {
     if (logger != null) {
       logger.warning(e);
     }
  } finally {
    currentTryCount.set(0);
  }
  return null;
}

Hiç yorum yok:

Yorum Gönder

THIRD-PARTY.txt Dosyası

Kullanılan harici kütüphanelerin sürümleri bu dosyada Dosyanın yolu şöyle hazelcast/licenses/THIRD-PARTY.txt