MatthewAden commented on code in PR #16352: URL: https://github.com/apache/dolphinscheduler/pull/16352#discussion_r1686137586
########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftSubscribeDataManager.java: ########## @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.registry.raft; + +import static com.alipay.sofa.jraft.util.BytesUtil.readUtf8; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.registry.api.Event; +import org.apache.dolphinscheduler.registry.api.SubscribeListener; +import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; + +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import lombok.extern.slf4j.Slf4j; + +import com.alipay.sofa.jraft.rhea.client.RheaKVStore; +import com.alipay.sofa.jraft.rhea.storage.KVEntry; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +@Slf4j +public class RaftSubscribeDataManager implements IRaftSubscribeDataManager { + + private final Map<String, List<SubscribeListener>> dataSubScribeMap = new ConcurrentHashMap<>(); + + private final RaftRegistryProperties properties; + + private final RheaKVStore kvStore; + + public RaftSubscribeDataManager(RaftRegistryProperties properties, RheaKVStore kvStore) { + this.properties = properties; + this.kvStore = kvStore; + } + + private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool( + 1, + new ThreadFactoryBuilder().setNameFormat("SubscribeListenerCheckThread").setDaemon(true).build()); + + public void start() { Review Comment: updated ########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftConnectionStateManager.java: ########## @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.registry.raft; + +import org.apache.dolphinscheduler.registry.api.ConnectionListener; +import org.apache.dolphinscheduler.registry.api.ConnectionState; + +import java.time.Duration; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import lombok.extern.slf4j.Slf4j; + +import com.alipay.sofa.jraft.RouteTable; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.rpc.CliClientService; +import com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +@Slf4j +public class RaftConnectionStateManager implements IRaftConnectionStateManager { + + private static final String DEFAULT_REGION_ID = "--1"; + private ConnectionState currentConnectionState; + private static final Duration CONNECT_STATE_CHECK_INTERVENE = Duration.ofSeconds(2); + private final RaftRegistryProperties properties; + private final List<ConnectionListener> connectionListeners = new CopyOnWriteArrayList<>(); + private final ScheduledExecutorService scheduledExecutorService; + private final CliOptions cliOptions; + private final CliClientService cliClientService; + + public RaftConnectionStateManager(RaftRegistryProperties properties) { + this.properties = properties; + this.cliOptions = new CliOptions(); + this.cliOptions.setMaxRetry(3); + this.cliOptions.setTimeoutMs(5000); + this.cliClientService = new CliClientServiceImpl(); + this.scheduledExecutorService = Executors.newScheduledThreadPool( + 1, + new ThreadFactoryBuilder().setNameFormat("ConnectionStateRefreshThread").setDaemon(true).build()); + } + + public void start() { Review Comment: updated -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
