dubbo EnableRouterSnapshot 源码

  • 2022-10-20
  • 浏览 (257)

dubbo EnableRouterSnapshot 代码

文件路径:/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableRouterSnapshot.java

/*
 * 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.dubbo.qos.command.impl;

import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ServiceMetadata;

@Cmd(name = "enableRouterSnapshot",
    summary = "Enable Dubbo Invocation Level Router Snapshot Print",
    example = "enableRouterSnapshot xx.xx.xxx.service")
public class EnableRouterSnapshot implements BaseCommand {
    private final RouterSnapshotSwitcher routerSnapshotSwitcher;
    private final FrameworkModel frameworkModel;

    public EnableRouterSnapshot(FrameworkModel frameworkModel) {
        this.frameworkModel = frameworkModel;
        this.routerSnapshotSwitcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
    }

    @Override
    public String execute(CommandContext commandContext, String[] args) {
        if (args.length != 1) {
            return "args count should be 1. example enableRouterSnapshot xx.xx.xxx.service";
        }
        String servicePattern = args[0];
        int count = 0;
        for (ConsumerModel consumerModel : frameworkModel.getServiceRepository().allConsumerModels()) {
            try {
                ServiceMetadata metadata = consumerModel.getServiceMetadata();
                if (metadata.getServiceKey().matches(servicePattern) || metadata.getDisplayServiceKey().matches(servicePattern)) {
                    routerSnapshotSwitcher.addEnabledService(metadata.getServiceKey());
                    count += 1;
                }
            } catch (Throwable ignore) {

            }
        }
        return "OK. Found service count: " + count + ". This will cause performance degradation, please be careful!";
    }
}

相关信息

dubbo 源码目录

相关文章

dubbo BaseOffline 源码

dubbo BaseOnline 源码

dubbo ChangeTelnet 源码

dubbo CountTelnet 源码

dubbo DisableDetailProfiler 源码

dubbo DisableRouterSnapshot 源码

dubbo DisableSimpleProfiler 源码

dubbo EnableDetailProfiler 源码

dubbo EnableSimpleProfiler 源码

dubbo GetEnabledRouterSnapshot 源码

0  赞