Kafka source resolution 1: cluster cluster information

Time:2020-1-17

Summary

During the operation of kafkaproducer, the cluster meta information is needed, which is stored in cluster

Node, topicpartition and partitioninfo

Cluster meta information is composed of three types of objectsNode, TopicPartition, PartitionInfo
Kafka source resolution 1: cluster cluster information

  • Node source code node represents a node in the cluster
  • Topicpartition source topicpartition represents a partition of topic
  • Partitioninfo source code partitioninfo represents the details of a partition

Immunity mode

Read the source code carefully. It can be seen that all three types of internal member variables are declared as final variables. Here, an immutability concurrent design pattern is used
Immutability’s concurrent design mode:Once the object is created, the state does not change, that is, member variables cannot be modified and immutable is used instead of locking (because immutable, no locking is needed), so as to solve the concurrency problem under multithreading.

Implementation of immutability mode

If all properties of a class are set to final and only read-only methods are allowed, then the class is basically immutable.More strictly, the class itself is final, that is, inheritance is not allowed. Because the subclass can override the method of the parent class, it is possible to change the immutability, so it is recommended that you use this stricter method in actual work.

Fast summary of immutable mode

  1. Class final
  2. Final attribute
  3. Method read-only

Reflection

  1. PartitionInfoCan classes be immutable?

Immutability mode extension [article reference]

Immunity mode extension

Recommended Today

RCAST 35: add type to currency

– font ALT: Simsun; MSO font charset: 134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:”Cambria Math”; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; Variable; Ose-1: 216301111; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /\* Style […]