Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hard coded dubbo-config-api values and small code optimization #3108

Merged
merged 4 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public class Constants {

public static final String DOBBO_PROTOCOL = DUBBO;

public static final String ZOOKEEPER_PROTOCOL = "zookeeper";

public static final String PROXY_KEY = "proxy";

public static final String WEIGHT_KEY = "weight";
Expand Down Expand Up @@ -324,6 +326,8 @@ public class Constants {

public static final String EXCHANGER_KEY = "exchanger";

public static final String DISPACTHER_KEY = "dispacther";

public static final String TRANSPORTER_KEY = "transporter";

public static final String SERVER_KEY = "server";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.
khanimteyaz marked this conversation as resolved.
Show resolved Hide resolved
* 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.common;

public final class EnvironmentConstants {
/**
* Application name;
*/
public static final String NAME = "name";

/**
* Application owner name;
*/
public static final String OWNER = "owner";

/**
* Running application organization name.
*/
public static final String ORGANIZATION = "organization";

/**
* Application architecture name.
*/
public static final String ARCHITECTURE = "architecture";

/**
* Environment name
*/
public static final String ENVIRONMENT = "environment";

/**
* Test environment key.
*/
public static final String TEST_ENVIRONMENT = "test";

/**
* Development environment key.
*/
public static final String DEVELOPMENT_ENVIRONMENT = "develop";

/**
* Production environment key.
*/
public static final String PRODUCTION_ENVIRONMENT = "product";

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String getVersion() {
}

public void setVersion(String version) {
checkKey("version", version);
checkKey(Constants.VERSION_KEY, version);
this.version = version;
}

Expand All @@ -88,7 +88,7 @@ public String getGroup() {
}

public void setGroup(String group) {
checkKey("group", group);
checkKey(Constants.GROUP_KEY, group);
this.group = group;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public void setToken(Boolean token) {
}

public void setToken(String token) {
checkName("token", token);
checkName(Constants.TOKEN_KEY, token);
this.token = token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.EnvironmentConstants;
import org.apache.dubbo.common.compiler.support.AdaptiveCompiler;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
Expand Down Expand Up @@ -102,9 +103,9 @@ public String getName() {
}

public void setName(String name) {
checkName("name", name);
checkName(EnvironmentConstants.NAME, name);
this.name = name;
if (id == null || id.length() == 0) {
if (StringUtils.isEmpty(id)) {
id = name;
}
}
Expand All @@ -123,7 +124,7 @@ public String getOwner() {
}

public void setOwner(String owner) {
checkMultiName("owner", owner);
checkMultiName(EnvironmentConstants.OWNER, owner);
this.owner = owner;
}

Expand All @@ -132,7 +133,7 @@ public String getOrganization() {
}

public void setOrganization(String organization) {
checkName("organization", organization);
checkName(EnvironmentConstants.ORGANIZATION, organization);
this.organization = organization;
}

Expand All @@ -141,7 +142,7 @@ public String getArchitecture() {
}

public void setArchitecture(String architecture) {
checkName("architecture", architecture);
checkName(EnvironmentConstants.ARCHITECTURE, architecture);
this.architecture = architecture;
}

Expand All @@ -150,10 +151,18 @@ public String getEnvironment() {
}

public void setEnvironment(String environment) {
checkName("environment", environment);
checkName(EnvironmentConstants.ENVIRONMENT, environment);
if (environment != null) {
if (!("develop".equals(environment) || "test".equals(environment) || "product".equals(environment))) {
throw new IllegalStateException("Unsupported environment: " + environment + ", only support develop/test/product, default is product.");
if (!(EnvironmentConstants.DEVELOPMENT_ENVIRONMENT.equals(environment)
|| EnvironmentConstants.TEST_ENVIRONMENT.equals(environment)
|| EnvironmentConstants.PRODUCTION_ENVIRONMENT.equals(environment))) {

throw new IllegalStateException(String.format("Unsupported environment: %s, only support %s/%s/%s, default is %s.",
environment
khanimteyaz marked this conversation as resolved.
Show resolved Hide resolved
,EnvironmentConstants.DEVELOPMENT_ENVIRONMENT
,EnvironmentConstants.TEST_ENVIRONMENT
,EnvironmentConstants.PRODUCTION_ENVIRONMENT
,EnvironmentConstants.PRODUCTION_ENVIRONMENT));
}
}
this.environment = environment;
Expand Down Expand Up @@ -284,4 +293,5 @@ public void setShutwait(String shutwait) {
public boolean isValid() {
return !StringUtils.isEmpty(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private URL toConfigUrl() {
map.put(Constants.PATH_KEY, ConfigCenterConfig.class.getSimpleName());
// use 'zookeeper' as the default configcenter.
if (StringUtils.isEmpty(map.get(Constants.PROTOCOL_KEY))) {
map.put(Constants.PROTOCOL_KEY, "zookeeper");
map.put(Constants.PROTOCOL_KEY, Constants.ZOOKEEPER_PROTOCOL);
}
return UrlUtils.parseURL(address, map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public String getName() {
public void setName(String name) {
checkMethodName("name", name);
this.name = name;
if (id == null || id.length() == 0) {
if (StringUtils.isEmpty(id)) {
id = name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config;

import org.apache.dubbo.common.EnvironmentConstants;
import org.apache.dubbo.config.support.Parameter;

import java.util.ArrayList;
Expand Down Expand Up @@ -64,7 +65,7 @@ public String getName() {
}

public void setName(String name) {
checkName("name", name);
checkName(EnvironmentConstants.NAME, name);
this.name = name;
if (id == null || id.length() == 0) {
id = name;
Expand All @@ -85,7 +86,7 @@ public String getOwner() {
}

public void setOwner(String owner) {
checkName("owner", owner);
checkName(EnvironmentConstants.OWNER, owner);
this.owner = owner;
}

Expand All @@ -94,7 +95,7 @@ public String getOrganization() {
}

public void setOrganization(String organization) {
checkName("organization", organization);
checkName(EnvironmentConstants.ORGANIZATION, organization);
this.organization = organization;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.serialize.Serialization;
import org.apache.dubbo.common.status.StatusChecker;
Expand Down Expand Up @@ -154,7 +155,7 @@ public String getName() {
return name;
}

public void setName(String name) {
public final void setName(String name) {
checkName("name", name);
this.name = name;
this.updateIdIfAbsent(name);
Expand All @@ -166,7 +167,7 @@ public String getHost() {
}

public void setHost(String host) {
checkName("host", host);
checkName(Constants.HOST_KEY, host);
this.host = host;
}

Expand All @@ -175,7 +176,7 @@ public Integer getPort() {
return port;
}

public void setPort(Integer port) {
public final void setPort(Integer port) {
this.port = port;
}

Expand Down Expand Up @@ -205,7 +206,7 @@ public String getThreadpool() {
}

public void setThreadpool(String threadpool) {
checkExtension(ThreadPool.class, "threadpool", threadpool);
checkExtension(ThreadPool.class, Constants.THREADPOOL_KEY, threadpool);
this.threadpool = threadpool;
}

Expand Down Expand Up @@ -254,8 +255,8 @@ public String getCodec() {
}

public void setCodec(String codec) {
if ("dubbo".equals(name)) {
checkMultiExtension(Codec.class, "codec", codec);
if (Constants.DOBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Codec.class, Constants.CODEC_KEY, codec);
}
this.codec = codec;
}
Expand All @@ -265,8 +266,8 @@ public String getSerialization() {
}

public void setSerialization(String serialization) {
if ("dubbo".equals(name)) {
checkMultiExtension(Serialization.class, "serialization", serialization);
if (Constants.DOBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Serialization.class, Constants.SERIALIZATION_KEY, serialization);
}
this.serialization = serialization;
}
Expand Down Expand Up @@ -308,8 +309,8 @@ public String getServer() {
}

public void setServer(String server) {
if ("dubbo".equals(name)) {
checkMultiExtension(Transporter.class, "server", server);
if (Constants.DOBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Transporter.class, Constants.SERVER_KEY, server);
}
this.server = server;
}
Expand All @@ -319,8 +320,8 @@ public String getClient() {
}

public void setClient(String client) {
if ("dubbo".equals(name)) {
checkMultiExtension(Transporter.class, "client", client);
if (Constants.DOBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Transporter.class, Constants.CLIENT_KEY, client);
}
this.client = client;
}
Expand All @@ -338,7 +339,7 @@ public String getTelnet() {
}

public void setTelnet(String telnet) {
checkMultiExtension(TelnetHandler.class, "telnet", telnet);
checkMultiExtension(TelnetHandler.class, Constants.TELNET, telnet);
this.telnet = telnet;
}

Expand Down Expand Up @@ -373,7 +374,7 @@ public String getTransporter() {
}

public void setTransporter(String transporter) {
checkExtension(Transporter.class, "transporter", transporter);
checkExtension(Transporter.class, Constants.TRANSPORTER_KEY, transporter);
this.transporter = transporter;
}

Expand All @@ -382,7 +383,7 @@ public String getExchanger() {
}

public void setExchanger(String exchanger) {
checkExtension(Exchanger.class, "exchanger", exchanger);
checkExtension(Exchanger.class, Constants.EXCHANGER_KEY, exchanger);
this.exchanger = exchanger;
}

Expand Down Expand Up @@ -412,7 +413,7 @@ public String getDispatcher() {
}

public void setDispatcher(String dispatcher) {
checkExtension(Dispatcher.class, "dispacther", dispatcher);
checkExtension(Dispatcher.class, Constants.DISPACTHER_KEY, dispatcher);
this.dispatcher = dispatcher;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public String getThreadpool() {
}

public void setThreadpool(String threadpool) {
checkExtension(ThreadPool.class, "threadpool", threadpool);
checkExtension(ThreadPool.class, Constants.THREADPOOL_KEY, threadpool);
this.threadpool = threadpool;
}

Expand Down Expand Up @@ -258,7 +258,7 @@ public String getTelnet() {
}

public void setTelnet(String telnet) {
checkMultiExtension(TelnetHandler.class, "telnet", telnet);
checkMultiExtension(TelnetHandler.class, Constants.TELNET, telnet);
this.telnet = telnet;
}

Expand Down Expand Up @@ -320,7 +320,7 @@ public String getTransporter() {
}

public void setTransporter(String transporter) {
checkExtension(Transporter.class, "transporter", transporter);
checkExtension(Transporter.class, Constants.TRANSPORTER_KEY, transporter);
this.transporter = transporter;
}

Expand All @@ -329,7 +329,7 @@ public String getExchanger() {
}

public void setExchanger(String exchanger) {
checkExtension(Exchanger.class, "exchanger", exchanger);
checkExtension(Exchanger.class, Constants.EXCHANGER_KEY, exchanger);
this.exchanger = exchanger;
}

Expand Down
Loading