com.alibaba.otter.shared.arbitrate.impl.config.ArbitrateConfigUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.alibaba.otter.shared.arbitrate.impl.config.ArbitrateConfigUtils.java

Source

/*
 * Copyright (C) 2010-2101 Alibaba Group Holding Limited.
 *
 * Licensed 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 com.alibaba.otter.shared.arbitrate.impl.config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.alibaba.otter.shared.common.model.config.channel.Channel;
import com.alibaba.otter.shared.common.model.config.node.Node;
import com.alibaba.otter.shared.common.model.config.pipeline.Pipeline;

/**
 * ????mock
 * 
 * @author jianghang 2011-9-27 ?08:27:04
 * @version 4.0.0
 */
public class ArbitrateConfigUtils {

    /**
     * ??nid?
     */
    public static Long getCurrentNid() {
        Node node = ArbitrateConfigRegistry.getConfig().currentNode();
        if (node != null) {
            return node.getId();
        } else {
            return null;
        }
    }

    /**
     * ?Nodezk?
     */
    public static List<String> getServerAddrs() {
        Node node = ArbitrateConfigRegistry.getConfig().currentNode();
        if (node != null) {
            String addr = StringUtils.join(node.getParameters().getZkCluster().getServerList(), ',');
            return Arrays.asList(addr);
        } else {
            return new ArrayList<String>();
        }
    }

    /**
     * ?task?pipeline
     */
    public static Pipeline getPipeline(Long pipelineId) {
        return ArbitrateConfigRegistry.getConfig().findPipeline(pipelineId);
    }

    /**
     * ?pipelineId?task????pipeline
     */
    public static Pipeline getOppositePipeline(Long pipelineId) {
        return ArbitrateConfigRegistry.getConfig().findOppositePipeline(pipelineId);
    }

    /**
     * ?pipelineId?task?channel
     */
    public static Channel getChannel(Long pipelineId) {
        return ArbitrateConfigRegistry.getConfig().findChannelByPipelineId(pipelineId);
    }

    /**
     * ?channelId?task?channel
     * 
     * @return
     */
    public static Channel getChannelByChannelId(Long channelId) {
        return ArbitrateConfigRegistry.getConfig().findChannel(channelId);
    }

    /**
     * 
     */
    public static int getParallelism(Long pipelineId) {
        return ArbitrateConfigRegistry.getConfig().findPipeline(pipelineId).getParameters().getParallelism()
                .intValue();
    }

    /**
     * ?nidnode?
     */
    public static Node findNode(Long nid) {
        return ArbitrateConfigRegistry.getConfig().findNode(nid);
    }
}