Agile way of web development, list tags of HTML common tags

Production consumer queue is used for multi node distributed data structure, production and consumption data. The producer creates a data object and puts it in the queue; The consumer takes a data object from the queue and processes it. In ZooKeeper, queues can be implemented by creating multiple child nodes under a container node; When creating child nodes, CreateMode uses PERSISTENT_SEQUENTIAL, ZooKeeper will automatically add a unique serial number after the node name. EPHEMERAL_SEQUENTIAL also has the same characteristics. The difference is whether it will be automatically deleted after the session ends.

Knock on the blackboard:*_ SEQUENTIAL is a very important feature of ZooKeeper. Distributed lock and election system all rely on this feature.

1. Refactoring of previous code

In the previous article, we have implemented Watcher and Barrier with. The code for creating ZooKeeper connection has been copied again. Similar work is required in the follow-up, so refactor the original code to make the code taste cleaner.

The following is the code for process(WatchedEvent)

final public void process(WatchedEvent event) {
  if (Event.EventType.None.equals(event.getType())) {
    // Connection status changes
    if (Event.KeeperState.SyncConnected.equals(event.getState())) {
      // Connection established successfully
      connectedSemaphore.countDown();
    }
  } else if (Event.EventType.NodeCreated.equals(event.getType())) {
    processNodeCreated(event);
  } else if (Event.EventType.NodeDeleted.equals(event.getType())) {
    processNodeDeleted(event);
  } else if (Event.EventType.NodeDataChanged.equals(event.getType())) {
    processNodeDataChanged(event);
  } else if (Event.EventType.NodeChildrenChanged.equals(event.getType())) {
    processNodeChildrenChanged(event);
  }
}

Take ZooKeeperBarrier as an example to see the reconstructed constructor and the code for listening to events

ZooKeeperBarrier(String address, String tableSerial, int tableCapacity, String customerName)
    throws IOException {
  super(address);
  this.tableSerial = createRootNode(tableSerial);
  this.tableCapacity = tableCapacity;
  this.customerName = customerName;
}
protected void processNodeChildrenChanged(WatchedEvent event) {
  log.info("{} Notification received : {}", customerName, event.getType());
  // Child nodes change
  synchronized (mutex) {
    mutex.notify();
  }
}

2 queue producers

Producer's key code

String elementName = queueName + "/element";
ArrayList<ACL> ids = ZooDefs.Ids.OPEN_ACL_UNSAFE;
CreateMode createMode = CreateMode.PERSISTENT_SEQUENTIAL;
getZooKeeper().create(elementName, value, ids, createMode);

Note that the focus is PERSISTENT_SEQUENTIAL, PERSISTENT means to permanently store until there is a command to delete. SEQUENTIAL means to automatically add a self incremented unique serial number later. In this way, although the elementnames are the same, the actually generated zNode name will add 10 numbers in the format of% 010d after "element", such as 000000000 1. For example, a complete zNode name may be / queue/element0000000021.

3 queue consumers

The consumer attempts to obtain the child node with the smallest name of zNode from the child node list. If the queue is empty, wait

ending

There are many ways to learn the basic knowledge of html5, css and javascript, so I won't say much. For example, some other excellent blogs. But I think reading is also necessary, which can save a lot of time. Common javascript books, such as advanced programming of javascript, are an essential book for every front-end engineer. They can be used while reading and understand some basic knowledge of js. They are basically comprehensive. If you have time, you can read some books related to js performance and designer patterns, It will be used in practice.

Data collection method: stamp here for free

It will be used in practice.

Data collection method: stamp here for free

Keywords: Front-end Interview Programmer

Added by wolfan on Sun, 16 Jan 2022 10:53:14 +0200