xyuanlu commented on code in PR #2845:
URL: https://github.com/apache/helix/pull/2845#discussion_r1693698665


##########
helix-gateway/src/main/java/org/apache/helix/gateway/service/GatewayServiceManager.java:
##########
@@ -89,33 +91,47 @@ public void run() {
    * It includes waiting for ZK connection, and also wait for previous 
LiveInstance to expire.
    */
   class participantConnectionProcessor implements Runnable {
-    GatewayServiceEvent _event;
+    private final GatewayServiceEvent _event;
 
-    public participantConnectionProcessor(GatewayServiceEvent event) {
+    private participantConnectionProcessor(GatewayServiceEvent event) {
       _event = event;
     }
 
     @Override
     public void run() {
-      HelixGatewayService helixGatewayService;
-      _helixGatewayServiceMap.computeIfAbsent(_event.getClusterName(),
-          k -> new HelixGatewayService(GatewayServiceManager.this, 
_event.getClusterName()));
-      helixGatewayService = 
_helixGatewayServiceMap.get(_event.getClusterName());
       if (_event.getEventType().equals(GatewayServiceEventType.CONNECT)) {
-        helixGatewayService.registerParticipant();
+        createHelixGatewayParticipant(_event.getClusterName(), 
_event.getInstanceName(),
+            _event.getShardStateMap());
       } else {
-        helixGatewayService.deregisterParticipant(_event.getClusterName(), 
_event.getInstanceName());
+        removeHelixGatewayParticipant(_event.getClusterName(), 
_event.getInstanceName());
       }
     }
   }
 
-  @VisibleForTesting
-  HelixGatewayServiceGrpcService getGrpcService() {
-    return _grpcService;
+  private void createHelixGatewayParticipant(String clusterName, String 
instanceName,
+      Map<String, Map<String, String>> initialShardStateMap) {
+    // Create and add the participant to the participant map
+    HelixGatewayParticipant.Builder participantBuilder =
+        new HelixGatewayParticipant.Builder(_gatewayServiceProcessor, 
instanceName, clusterName,
+            _zkAddress).addInitialShardState(initialShardStateMap);
+    SUPPORTED_MULTI_STATE_MODEL_TYPES.forEach(
+        participantBuilder::addMultiTopStateStateModelDefinition);
+    _helixGatewayParticipantMap.computeIfAbsent(clusterName, k -> new 
ConcurrentHashMap<>())
+        .put(instanceName, participantBuilder.build());
+  }
+
+  private void removeHelixGatewayParticipant(String clusterName, String 
instanceName) {
+    // Disconnect and remove the participant from the participant map
+    HelixGatewayParticipant participant = 
getHelixGatewayParticipant(clusterName, instanceName);
+    if (participant != null) {

Review Comment:
   can we have null check in getter? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org

Reply via email to