001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.components.rpc.motan; 017 018import io.jboot.app.config.annotation.ConfigModel; 019import io.jboot.utils.StrUtil; 020 021import java.util.Map; 022 023/** 024 * @author michael yang (fuhai999@gmail.com) 025 * @Date: 2020/3/31 026 * @see com.weibo.api.motan.config.AbstractServiceConfig 027 */ 028@ConfigModel(prefix = "jboot.rpc.motan") 029public class MotanrpcConfig { 030 031 /** 032 * 一个service可以按多个protocol提供服务,不同protocol使用不同port 利用export来设置protocol和port,格式如下: 033 * protocol1:port1,protocol2:port2 034 **/ 035 private String defaultExport; 036 037 038 /** 039 * 一般不用设置,由服务自己获取,但如果有多个ip,而只想用指定ip,则可以在此处指定 040 */ 041 private String defaultHost; 042 043 044 /** 045 * motan 对每个 service 设置的 export 046 */ 047 private Map<String, String> exports; 048 049 /** 050 * 某个服务暴露自己的主机 051 */ 052 private Map<String, String> hosts; 053 054 055 public String getDefaultExport() { 056 return defaultExport; 057 } 058 059 public void setDefaultExport(String defaultExport) { 060 this.defaultExport = defaultExport; 061 } 062 063 public String getDefaultHost() { 064 return defaultHost; 065 } 066 067 public void setDefaultHost(String defaultHost) { 068 this.defaultHost = defaultHost; 069 } 070 071 public Map<String, String> getExports() { 072 return exports; 073 } 074 075 public void setExports(Map<String, String> exports) { 076 this.exports = exports; 077 } 078 079 public String getExport(String className) { 080 String export = exports == null || exports.isEmpty() ? null : exports.get(className); 081 return StrUtil.isNotBlank(export) ? export : defaultExport; 082 } 083 084 public Map<String, String> getHosts() { 085 return hosts; 086 } 087 088 public void setHosts(Map<String, String> hosts) { 089 this.hosts = hosts; 090 } 091 092 public String getHost(String className) { 093 String host = hosts == null || hosts.isEmpty() ? null : hosts.get(className); 094 return StrUtil.isNotBlank(host) ? host : defaultHost; 095 } 096}