For new codeStyle in nacos-api module (#3190)

This commit is contained in:
杨翊 SionYang 2020-06-29 13:54:31 +08:00 committed by GitHub
parent 51c0eb25ad
commit c9bf5f2f70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 1285 additions and 1099 deletions

View File

@ -15,7 +15,7 @@
~ limitations under the License. ~ limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<groupId>com.alibaba.nacos</groupId> <groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId> <artifactId>nacos-all</artifactId>

View File

@ -13,27 +13,28 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api;
import java.util.Properties; package com.alibaba.nacos.api;
import com.alibaba.nacos.api.config.ConfigFactory; import com.alibaba.nacos.api.config.ConfigFactory;
import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingMaintainFactory; import com.alibaba.nacos.api.naming.NamingMaintainFactory;
import com.alibaba.nacos.api.naming.NamingMaintainService; import com.alibaba.nacos.api.naming.NamingMaintainService;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import java.util.Properties;
/** /**
* Nacos Factory * Nacos Factory.
* *
* @author Nacos * @author Nacos
*/ */
public class NacosFactory { public class NacosFactory {
/** /**
* Create config service * Create config service.
* *
* @param properties init param * @param properties init param
* @return config * @return config
@ -44,7 +45,7 @@ public class NacosFactory {
} }
/** /**
* Create config service * Create config service.
* *
* @param serverAddr server list * @param serverAddr server list
* @return config * @return config
@ -55,7 +56,7 @@ public class NacosFactory {
} }
/** /**
* Create naming service * Create naming service.
* *
* @param serverAddr server list * @param serverAddr server list
* @return Naming * @return Naming
@ -66,7 +67,7 @@ public class NacosFactory {
} }
/** /**
* Create naming service * Create naming service.
* *
* @param properties init param * @param properties init param
* @return Naming * @return Naming
@ -77,9 +78,9 @@ public class NacosFactory {
} }
/** /**
* Create maintain service * Create maintain service.
* *
* @param serverAddr * @param serverAddr server address
* @return NamingMaintainService * @return NamingMaintainService
* @throws NacosException Exception * @throws NacosException Exception
*/ */
@ -88,9 +89,9 @@ public class NacosFactory {
} }
/** /**
* Create maintain service * Create maintain service.
* *
* @param properties * @param properties server address
* @return NamingMaintainService * @return NamingMaintainService
* @throws NacosException Exception * @throws NacosException Exception
*/ */

View File

@ -13,59 +13,60 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api; package com.alibaba.nacos.api;
/** /**
* Property Key Const * Property Key Const.
* *
* @author Nacos * @author Nacos
*/ */
public class PropertyKeyConst { public class PropertyKeyConst {
public final static String IS_USE_CLOUD_NAMESPACE_PARSING = "isUseCloudNamespaceParsing"; public static final String IS_USE_CLOUD_NAMESPACE_PARSING = "isUseCloudNamespaceParsing";
public final static String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule"; public static final String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
public final static String ENDPOINT = "endpoint"; public static final String ENDPOINT = "endpoint";
public final static String ENDPOINT_PORT = "endpointPort"; public static final String ENDPOINT_PORT = "endpointPort";
public final static String NAMESPACE = "namespace"; public static final String NAMESPACE = "namespace";
public final static String USERNAME = "username"; public static final String USERNAME = "username";
public final static String PASSWORD = "password"; public static final String PASSWORD = "password";
public final static String ACCESS_KEY = "accessKey"; public static final String ACCESS_KEY = "accessKey";
public final static String SECRET_KEY = "secretKey"; public static final String SECRET_KEY = "secretKey";
public final static String RAM_ROLE_NAME = "ramRoleName"; public static final String RAM_ROLE_NAME = "ramRoleName";
public final static String SERVER_ADDR = "serverAddr"; public static final String SERVER_ADDR = "serverAddr";
public final static String CONTEXT_PATH = "contextPath"; public static final String CONTEXT_PATH = "contextPath";
public final static String CLUSTER_NAME = "clusterName"; public static final String CLUSTER_NAME = "clusterName";
public final static String ENCODE = "encode"; public static final String ENCODE = "encode";
public final static String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout"; public static final String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
public final static String CONFIG_RETRY_TIME = "configRetryTime"; public static final String CONFIG_RETRY_TIME = "configRetryTime";
public final static String MAX_RETRY = "maxRetry"; public static final String MAX_RETRY = "maxRetry";
public final static String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig"; public static final String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
public final static String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart"; public static final String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
public final static String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount"; public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
public final static String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount"; public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
/** /**
* Get the key value of some variable value from the system property * Get the key value of some variable value from the system property.
*/ */
public static class SystemEnv { public static class SystemEnv {

View File

@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api; package com.alibaba.nacos.api;
/** /**
* <p> * Support for reading the value of the specified variable from the -D parameter.
* Support for reading the value of the specified variable from the -D parameter *
* </P> * <p>Properties that are preferred to which in {@link PropertyKeyConst}
* Properties that are preferred to which in {@link PropertyKeyConst}
* *
* @author pbting * @author pbting
* @date 2019-02-22 3:38 PM
*/ */
public interface SystemPropertyKeyConst { public interface SystemPropertyKeyConst {
@ -31,8 +30,8 @@ public interface SystemPropertyKeyConst {
String NAMING_WEB_CONTEXT = "nacos.naming.web.context"; String NAMING_WEB_CONTEXT = "nacos.naming.web.context";
/** /**
* In the cloud (Alibaba Cloud or other cloud vendors) environment, * In the cloud (Alibaba Cloud or other cloud vendors) environment, whether to enable namespace resolution in the
* whether to enable namespace resolution in the cloud environment. * cloud environment.
* <p> * <p>
* The default is on. * The default is on.
* </p> * </p>
@ -40,8 +39,8 @@ public interface SystemPropertyKeyConst {
String IS_USE_CLOUD_NAMESPACE_PARSING = "nacos.use.cloud.namespace.parsing"; String IS_USE_CLOUD_NAMESPACE_PARSING = "nacos.use.cloud.namespace.parsing";
/** /**
* In the cloud environment, if the process level requires a globally uniform namespace, * In the cloud environment, if the process level requires a globally uniform namespace, it can be specified with
* it can be specified with the -D parameter. * the -D parameter.
*/ */
String ANS_NAMESPACE = "ans.namespace"; String ANS_NAMESPACE = "ans.namespace";

View File

@ -13,12 +13,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.annotation; package com.alibaba.nacos.api.annotation;
import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* An annotation to inject {@link ConfigService} or {@link NamingService} instance into the target Bean. * An annotation to inject {@link ConfigService} or {@link NamingService} instance into the target Bean.

View File

@ -13,14 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.annotation; package com.alibaba.nacos.api.annotation;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* An annotation for Nacos Properties * An annotation for Nacos Properties.
* *
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see PropertyKeyConst * @see PropertyKeyConst
@ -32,153 +37,156 @@ import java.lang.annotation.*;
public @interface NacosProperties { public @interface NacosProperties {
/** /**
* The prefix of property name of Nacos * The prefix of property name of Nacos.
*/ */
String PREFIX = "nacos."; String PREFIX = "nacos.";
/** /**
* The property name of "endpoint" * The property name of "endpoint".
*/ */
String ENDPOINT = "endpoint"; String ENDPOINT = "endpoint";
/** /**
* The property name of "namespace" * The property name of "namespace".
*/ */
String NAMESPACE = "namespace"; String NAMESPACE = "namespace";
/** /**
* The property name of "access-key" * The property name of "access-key".
*/ */
String ACCESS_KEY = "access-key"; String ACCESS_KEY = "access-key";
/** /**
* The property name of "secret-key" * The property name of "secret-key".
*/ */
String SECRET_KEY = "secret-key"; String SECRET_KEY = "secret-key";
/** /**
* The property name of "server-addr" * The property name of "server-addr".
*/ */
String SERVER_ADDR = "server-addr"; String SERVER_ADDR = "server-addr";
/** /**
* The property name of "context-path" * The property name of "context-path".
*/ */
String CONTEXT_PATH = "context-path"; String CONTEXT_PATH = "context-path";
/** /**
* The property name of "cluster-name" * The property name of "cluster-name".
*/ */
String CLUSTER_NAME = "cluster-name"; String CLUSTER_NAME = "cluster-name";
/** /**
* The property name of "encode" * The property name of "encode".
*/ */
String ENCODE = "encode"; String ENCODE = "encode";
/** /**
* The property name of "long-poll.timeout" * The property name of "long-poll.timeout".
*/ */
String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout"; String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
/** /**
* The property name of "config.retry.time" * The property name of "config.retry.time".
*/ */
String CONFIG_RETRY_TIME = "configRetryTime"; String CONFIG_RETRY_TIME = "configRetryTime";
/** /**
* The property name of "maxRetry" * The property name of "maxRetry".
*/ */
String MAX_RETRY = "maxRetry"; String MAX_RETRY = "maxRetry";
/** /**
* The property name of "enableRemoteSyncConfig" * The property name of "enableRemoteSyncConfig".
*/ */
String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig"; String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
/** /**
* The property name of "username" * The property name of "username".
*/ */
String USERNAME = "username"; String USERNAME = "username";
/** /**
* The property name of "password" * The property name of "password".
*/ */
String PASSWORD = "password"; String PASSWORD = "password";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>.
*/ */
String ENDPOINT_PLACEHOLDER = "${" + PREFIX + ENDPOINT + ":}"; String ENDPOINT_PLACEHOLDER = "${" + PREFIX + ENDPOINT + ":}";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code>.
*/ */
String NAMESPACE_PLACEHOLDER = "${" + PREFIX + NAMESPACE + ":}"; String NAMESPACE_PLACEHOLDER = "${" + PREFIX + NAMESPACE + ":}";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code>.
*/ */
String ACCESS_KEY_PLACEHOLDER = "${" + PREFIX + ACCESS_KEY + ":}"; String ACCESS_KEY_PLACEHOLDER = "${" + PREFIX + ACCESS_KEY + ":}";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code>.
*/ */
String SECRET_KEY_PLACEHOLDER = "${" + PREFIX + SECRET_KEY + ":}"; String SECRET_KEY_PLACEHOLDER = "${" + PREFIX + SECRET_KEY + ":}";
/** /**
* The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code> * The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code>.
*/ */
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}"; String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}";
/** /**
* The placeholder of endpoint, the value is ${nacos.context-path:}" * The placeholder of endpoint, the value is ${nacos.context-path:}".
*/ */
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}"; String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code>.
*/ */
String CLUSTER_NAME_PLACEHOLDER = "${" + PREFIX + CLUSTER_NAME + ":}"; String CLUSTER_NAME_PLACEHOLDER = "${" + PREFIX + CLUSTER_NAME + ":}";
/** /**
* The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code> * The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code>.
*/ */
String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}"; String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}";
/** /**
* The placeholder of {@link NacosProperties#CONFIG_LONG_POLL_TIMEOUT configLongPollTimeout}, the value is <code>"${nacos.configLongPollTimeout:}"</code> * The placeholder of {@link NacosProperties#CONFIG_LONG_POLL_TIMEOUT configLongPollTimeout}, the value is
* <code>"${nacos.configLongPollTimeout:}"</code>.
*/ */
String CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER = "${" + PREFIX + CONFIG_LONG_POLL_TIMEOUT + ":}"; String CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER = "${" + PREFIX + CONFIG_LONG_POLL_TIMEOUT + ":}";
/** /**
* The placeholder of {@link NacosProperties#CONFIG_RETRY_TIME configRetryTime}, the value is <code>"${nacos.configRetryTime:}"</code> * The placeholder of {@link NacosProperties#CONFIG_RETRY_TIME configRetryTime}, the value is
* <code>"${nacos.configRetryTime:}"</code>.
*/ */
String CONFIG_RETRY_TIME_PLACEHOLDER = "${" + PREFIX + CONFIG_RETRY_TIME + ":}"; String CONFIG_RETRY_TIME_PLACEHOLDER = "${" + PREFIX + CONFIG_RETRY_TIME + ":}";
/** /**
* The placeholder of {@link NacosProperties#MAX_RETRY maxRetry}, the value is <code>"${nacos.maxRetry:}"</code> * The placeholder of {@link NacosProperties#MAX_RETRY maxRetry}, the value is <code>"${nacos.maxRetry:}"</code>.
*/ */
String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}"; String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}";
/** /**
* The placeholder of {@link NacosProperties#ENABLE_REMOTE_SYNC_CONFIG enableRemoteSyncConfig}, the value is <code>"${nacos.enableRemoteSyncConfig:}"</code> * The placeholder of {@link NacosProperties#ENABLE_REMOTE_SYNC_CONFIG enableRemoteSyncConfig}, the value is
* <code>"${nacos.enableRemoteSyncConfig:}"</code>.
*/ */
String ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER = "${" + PREFIX + ENABLE_REMOTE_SYNC_CONFIG + ":}"; String ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER = "${" + PREFIX + ENABLE_REMOTE_SYNC_CONFIG + ":}";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.username:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.username:}"</code>.
*/ */
String USERNAME_PLACEHOLDER = "${" + PREFIX + USERNAME + ":}"; String USERNAME_PLACEHOLDER = "${" + PREFIX + USERNAME + ":}";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.password:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.password:}"</code>.
*/ */
String PASSWORD_PLACEHOLDER = "${" + PREFIX + PASSWORD + ":}"; String PASSWORD_PLACEHOLDER = "${" + PREFIX + PASSWORD + ":}";
/** /**
* The property of "endpoint" * The property of "endpoint".
* *
* @return empty as default value * @return empty as default value
* @see #ENDPOINT_PLACEHOLDER * @see #ENDPOINT_PLACEHOLDER
@ -186,7 +194,7 @@ public @interface NacosProperties {
String endpoint() default ENDPOINT_PLACEHOLDER; String endpoint() default ENDPOINT_PLACEHOLDER;
/** /**
* The property of "namespace" * The property of "namespace".
* *
* @return empty as default value * @return empty as default value
* @see #NAMESPACE_PLACEHOLDER * @see #NAMESPACE_PLACEHOLDER
@ -194,7 +202,7 @@ public @interface NacosProperties {
String namespace() default NAMESPACE_PLACEHOLDER; String namespace() default NAMESPACE_PLACEHOLDER;
/** /**
* The property of "access-key" * The property of "access-key".
* *
* @return empty as default value * @return empty as default value
* @see #ACCESS_KEY_PLACEHOLDER * @see #ACCESS_KEY_PLACEHOLDER
@ -202,7 +210,7 @@ public @interface NacosProperties {
String accessKey() default ACCESS_KEY_PLACEHOLDER; String accessKey() default ACCESS_KEY_PLACEHOLDER;
/** /**
* The property of "secret-key" * The property of "secret-key".
* *
* @return empty as default value * @return empty as default value
* @see #SECRET_KEY_PLACEHOLDER * @see #SECRET_KEY_PLACEHOLDER
@ -210,7 +218,7 @@ public @interface NacosProperties {
String secretKey() default SECRET_KEY_PLACEHOLDER; String secretKey() default SECRET_KEY_PLACEHOLDER;
/** /**
* The property of "server-addr" * The property of "server-addr".
* *
* @return empty as default value * @return empty as default value
* @see #SERVER_ADDR_PLACEHOLDER * @see #SERVER_ADDR_PLACEHOLDER
@ -218,7 +226,7 @@ public @interface NacosProperties {
String serverAddr() default SERVER_ADDR_PLACEHOLDER; String serverAddr() default SERVER_ADDR_PLACEHOLDER;
/** /**
* The property of "context-path" * The property of "context-path".
* *
* @return empty as default value * @return empty as default value
* @see #CONTEXT_PATH_PLACEHOLDER * @see #CONTEXT_PATH_PLACEHOLDER
@ -226,7 +234,7 @@ public @interface NacosProperties {
String contextPath() default CONTEXT_PATH_PLACEHOLDER; String contextPath() default CONTEXT_PATH_PLACEHOLDER;
/** /**
* The property of "cluster-name" * The property of "cluster-name".
* *
* @return empty as default value * @return empty as default value
* @see #CLUSTER_NAME_PLACEHOLDER * @see #CLUSTER_NAME_PLACEHOLDER
@ -234,7 +242,7 @@ public @interface NacosProperties {
String clusterName() default CLUSTER_NAME_PLACEHOLDER; String clusterName() default CLUSTER_NAME_PLACEHOLDER;
/** /**
* The property of "encode" * The property of "encode".
* *
* @return "UTF-8" as default value * @return "UTF-8" as default value
* @see #ENCODE_PLACEHOLDER * @see #ENCODE_PLACEHOLDER
@ -242,7 +250,7 @@ public @interface NacosProperties {
String encode() default ENCODE_PLACEHOLDER; String encode() default ENCODE_PLACEHOLDER;
/** /**
* The property of "configLongPollTimeout" * The property of "configLongPollTimeout".
* *
* @return empty as default value * @return empty as default value
* @see #CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER * @see #CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER
@ -250,7 +258,7 @@ public @interface NacosProperties {
String configLongPollTimeout() default CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER; String configLongPollTimeout() default CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER;
/** /**
* The property of "configRetryTime" * The property of "configRetryTime".
* *
* @return empty as default value * @return empty as default value
* @see #CONFIG_RETRY_TIME_PLACEHOLDER * @see #CONFIG_RETRY_TIME_PLACEHOLDER
@ -258,7 +266,7 @@ public @interface NacosProperties {
String configRetryTime() default CONFIG_RETRY_TIME_PLACEHOLDER; String configRetryTime() default CONFIG_RETRY_TIME_PLACEHOLDER;
/** /**
* The property of "maxRetry" * The property of "maxRetry".
* *
* @return empty as default value * @return empty as default value
* @see #MAX_RETRY * @see #MAX_RETRY
@ -266,7 +274,7 @@ public @interface NacosProperties {
String maxRetry() default MAX_RETRY_PLACEHOLDER; String maxRetry() default MAX_RETRY_PLACEHOLDER;
/** /**
* The property of "enableRemoteSyncConfig" * The property of "enableRemoteSyncConfig".
* *
* @return empty as default value * @return empty as default value
* @see #ENABLE_REMOTE_SYNC_CONFIG * @see #ENABLE_REMOTE_SYNC_CONFIG
@ -274,7 +282,7 @@ public @interface NacosProperties {
String enableRemoteSyncConfig() default ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER; String enableRemoteSyncConfig() default ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER;
/** /**
* The property of "username" * The property of "username".
* *
* @return empty as default value * @return empty as default value
* @see #USERNAME_PLACEHOLDER * @see #USERNAME_PLACEHOLDER
@ -282,7 +290,7 @@ public @interface NacosProperties {
String username() default USERNAME_PLACEHOLDER; String username() default USERNAME_PLACEHOLDER;
/** /**
* The property of "password" * The property of "password".
* *
* @return empty as default value * @return empty as default value
* @see #PASSWORD_PLACEHOLDER * @see #PASSWORD_PLACEHOLDER

View File

@ -13,18 +13,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.cmdb.pojo; package com.alibaba.nacos.api.cmdb.pojo;
import java.util.Map; import java.util.Map;
/** /**
* CMDB entity.
*
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
*/ */
public class Entity { public class Entity {
private String type; private String type;
private String name; private String name;
private Map<String, String> labels; private Map<String, String> labels;
public String getType() { public String getType() {

View File

@ -13,16 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.cmdb.pojo; package com.alibaba.nacos.api.cmdb.pojo;
/** /**
* CMDB entity event.
*
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
*/ */
public class EntityEvent { public class EntityEvent {
private EntityEventType type; private EntityEventType type;
private String entityName; private String entityName;
private String entityType; private String entityType;
public EntityEventType getType() { public EntityEventType getType() {

View File

@ -13,19 +13,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.cmdb.pojo; package com.alibaba.nacos.api.cmdb.pojo;
/** /**
* CMDB entity event type.
*
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
*/ */
public enum EntityEventType { public enum EntityEventType {
/** /**
* * Add or update entity.
*/ */
ENTITY_ADD_OR_UPDATE, ENTITY_ADD_OR_UPDATE,
/** /**
* * Remove entity.
*/ */
ENTITY_REMOVE ENTITY_REMOVE
} }

View File

@ -13,18 +13,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.cmdb.pojo; package com.alibaba.nacos.api.cmdb.pojo;
import java.util.Set; import java.util.Set;
/** /**
* CMDB lable.
*
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
*/ */
public class Label { public class Label {
private String name; private String name;
private Set<String> values; private Set<String> values;
private String description; private String description;
public String getName() { public String getName() {

View File

@ -13,19 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.cmdb.pojo; package com.alibaba.nacos.api.cmdb.pojo;
/** /**
* CMDB preserverd entity type.
*
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
*/ */
public enum PreservedEntityTypes { public enum PreservedEntityTypes {
/** /**
* Ip * Ip.
*/ */
ip, ip,
/** /**
* Service * Service.
*/ */
service service
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.cmdb.spi; package com.alibaba.nacos.api.cmdb.spi;
import com.alibaba.nacos.api.cmdb.pojo.Entity; import com.alibaba.nacos.api.cmdb.pojo.Entity;
@ -24,7 +25,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
* Service to visit CMDB store * Service to visit CMDB store.
* *
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
@ -32,21 +33,21 @@ import java.util.Set;
public interface CmdbService { public interface CmdbService {
/** /**
* Get all label names stored in CMDB * Get all label names stored in CMDB.
* *
* @return label name set * @return label name set
*/ */
Set<String> getLabelNames(); Set<String> getLabelNames();
/** /**
* Get all possible entity types in CMDB * Get all possible entity types in CMDB.
* *
* @return all entity types * @return all entity types
*/ */
Set<String> getEntityTypes(); Set<String> getEntityTypes();
/** /**
* Get label info * Get label info.
* *
* @param labelName label name * @param labelName label name
* @return label info * @return label info
@ -54,33 +55,33 @@ public interface CmdbService {
Label getLabel(String labelName); Label getLabel(String labelName);
/** /**
* Get label value of label name of ip * Get label value of label name of ip.
* *
* @param entityName entity name * @param entityName entity name
* @param entityType entity type * @param entityType entity type
* @param labelName target label name * @param labelName target label name
* @return label value * @return label value
*/ */
String getLabelValue(String entityName, String entityType, String labelName); String getLabelValue(String entityName, String entityType, String labelName);
/** /**
* Get all label value of ip * Get all label value of ip.
* *
* @param entityName entity name * @param entityName entity name
* @param entityType entity type * @param entityType entity type
* @return all label values * @return all label values
*/ */
Map<String, String> getLabelValues(String entityName, String entityType); Map<String, String> getLabelValues(String entityName, String entityType);
/** /**
* Dump all entities in CMDB * Dump all entities in CMDB.
* *
* @return all entities * @return all entities
*/ */
Map<String, Map<String, Entity>> getAllEntities(); Map<String, Map<String, Entity>> getAllEntities();
/** /**
* get label change events * get label change events.
* *
* @param timestamp start time of generated events * @param timestamp start time of generated events
* @return label events * @return label events
@ -88,7 +89,7 @@ public interface CmdbService {
List<EntityEvent> getEntityEvents(long timestamp); List<EntityEvent> getEntityEvents(long timestamp);
/** /**
* Get single entity * Get single entity.
* *
* @param entityName name of entity * @param entityName name of entity
* @param entityType type of entity * @param entityType type of entity

View File

@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.common; package com.alibaba.nacos.api.common;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* Constant * Constants.
* *
* @author Nacos * @author Nacos
*/ */
@ -26,7 +27,7 @@ public class Constants {
public static final String CLIENT_VERSION = "3.0.0"; public static final String CLIENT_VERSION = "3.0.0";
public static int DATA_IN_BODY_VERSION = 204; public static final int DATA_IN_BODY_VERSION = 204;
public static final String DEFAULT_GROUP = "DEFAULT_GROUP"; public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
@ -83,47 +84,47 @@ public class Constants {
public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow"; public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow";
/** /**
* second * second.
*/ */
public static final int ASYNC_UPDATE_ADDRESS_INTERVAL = 300; public static final int ASYNC_UPDATE_ADDRESS_INTERVAL = 300;
/** /**
* second * second.
*/ */
public static final int POLLING_INTERVAL_TIME = 15; public static final int POLLING_INTERVAL_TIME = 15;
/** /**
* millisecond * millisecond.
*/ */
public static final int ONCE_TIMEOUT = 2000; public static final int ONCE_TIMEOUT = 2000;
/** /**
* millisecond * millisecond.
*/ */
public static final int SO_TIMEOUT = 60000; public static final int SO_TIMEOUT = 60000;
/** /**
* millisecond * millisecond.
*/ */
public static final int CONFIG_LONG_POLL_TIMEOUT = 30000; public static final int CONFIG_LONG_POLL_TIMEOUT = 30000;
/** /**
* millisecond * millisecond.
*/ */
public static final int MIN_CONFIG_LONG_POLL_TIMEOUT = 10000; public static final int MIN_CONFIG_LONG_POLL_TIMEOUT = 10000;
/** /**
* millisecond * millisecond.
*/ */
public static final int CONFIG_RETRY_TIME = 2000; public static final int CONFIG_RETRY_TIME = 2000;
/** /**
* Maximum number of retries * Maximum number of retries.
*/ */
public static final int MAX_RETRY = 3; public static final int MAX_RETRY = 3;
/** /**
* millisecond * millisecond.
*/ */
public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5; public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;
@ -146,13 +147,17 @@ public class Constants {
public static final String LONGPOLLING_LINE_SEPARATOR = "\r\n"; public static final String LONGPOLLING_LINE_SEPARATOR = "\r\n";
public static final String CLIENT_APPNAME_HEADER = "Client-AppName"; public static final String CLIENT_APPNAME_HEADER = "Client-AppName";
public static final String CLIENT_REQUEST_TS_HEADER = "Client-RequestTS"; public static final String CLIENT_REQUEST_TS_HEADER = "Client-RequestTS";
public static final String CLIENT_REQUEST_TOKEN_HEADER = "Client-RequestToken"; public static final String CLIENT_REQUEST_TOKEN_HEADER = "Client-RequestToken";
public static final int ATOMIC_MAX_SIZE = 1000; public static final int ATOMIC_MAX_SIZE = 1000;
public static final String NAMING_INSTANCE_ID_SPLITTER = "#"; public static final String NAMING_INSTANCE_ID_SPLITTER = "#";
public static final int NAMING_INSTANCE_ID_SEG_COUNT = 4; public static final int NAMING_INSTANCE_ID_SEG_COUNT = 4;
public static final String NAMING_HTTP_HEADER_SPILIER = "\\|"; public static final String NAMING_HTTP_HEADER_SPILIER = "\\|";
public static final String DEFAULT_CLUSTER_NAME = "DEFAULT"; public static final String DEFAULT_CLUSTER_NAME = "DEFAULT";

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.common;
package com.alibaba.nacos.api.common;
/** /**
* Response code definitions. * Response code definitions.
* <p> *
* This class and inherited classes define codes separated from HTTP code to provide richer and preciser * <p>This class and inherited classes define codes separated from HTTP code to provide richer and preciser information of
* information of the API results. A recommended rule for defining response code is: * the API results. A recommended rule for defining response code is:
* <li> Global and common code starts with 10001. * <li> Global and common code starts with 10001.
* <li> Naming module code starts with 20001. * <li> Naming module code starts with 20001.
* <li> Config module code starts with 30001. * <li> Config module code starts with 30001.
@ -31,7 +31,7 @@ package com.alibaba.nacos.api.common;
public class ResponseCode { public class ResponseCode {
/** /**
* Everything normal * Everything normal.
*/ */
public static final int OK = 10200; public static final int OK = 10200;
} }

View File

@ -13,20 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config;
import com.alibaba.nacos.api.config.ConfigChangeItem; package com.alibaba.nacos.api.config;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
/** /**
* ConfigChangeEvent * ConfigChangeEvent.
* *
* @author rushsky518 * @author rushsky518
*/ */
public class ConfigChangeEvent { public class ConfigChangeEvent {
private Map<String, ConfigChangeItem> data;
private final Map<String, ConfigChangeItem> data;
public ConfigChangeEvent(Map<String, ConfigChangeItem> data) { public ConfigChangeEvent(Map<String, ConfigChangeItem> data) {
this.data = data; this.data = data;

View File

@ -13,16 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config; package com.alibaba.nacos.api.config;
/** /**
* ConfigChangeItem * ConfigChangeItem.
* *
* @author rushsky518 * @author rushsky518
*/ */
public class ConfigChangeItem { public class ConfigChangeItem {
private String key; private String key;
private String oldValue; private String oldValue;
private String newValue; private String newValue;
private PropertyChangeType type; private PropertyChangeType type;
@ -67,11 +71,7 @@ public class ConfigChangeItem {
@Override @Override
public String toString() { public String toString() {
return "ConfigChangeItem{" + return "ConfigChangeItem{" + "key='" + key + '\'' + ", oldValue='" + oldValue + '\'' + ", newValue='" + newValue
"key='" + key + '\'' + + '\'' + ", type=" + type + '}';
", oldValue='" + oldValue + '\'' +
", newValue='" + newValue + '\'' +
", type=" + type +
'}';
} }
} }

View File

@ -13,23 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config;
import java.lang.reflect.Constructor; package com.alibaba.nacos.api.config;
import java.util.Properties;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import java.lang.reflect.Constructor;
import java.util.Properties;
/** /**
* Config Factory * Config Factory.
* *
* @author Nacos * @author Nacos
*/ */
public class ConfigFactory { public class ConfigFactory {
/** /**
* Create Config * Create Config.
* *
* @param properties init param * @param properties init param
* @return ConfigService * @return ConfigService
@ -47,7 +48,7 @@ public class ConfigFactory {
} }
/** /**
* Create Config * Create Config.
* *
* @param serverAddr serverList * @param serverAddr serverList
* @return Config * @return Config

View File

@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config; package com.alibaba.nacos.api.config;
import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
/** /**
* Config Service Interface * Config Service Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface ConfigService { public interface ConfigService {
/** /**
* Get config * Get config.
* *
* @param dataId dataId * @param dataId dataId
* @param group group * @param group group
@ -37,29 +38,28 @@ public interface ConfigService {
String getConfig(String dataId, String group, long timeoutMs) throws NacosException; String getConfig(String dataId, String group, long timeoutMs) throws NacosException;
/** /**
* Get config and register Listener * Get config and register Listener.
* *
* If you want to pull it yourself when the program starts to get the configuration for the first time, * <p>If you want to pull it yourself when the program starts to get the configuration for the first time, and the
* and the registered Listener is used for future configuration updates, you can keep the original * registered Listener is used for future configuration updates, you can keep the original code unchanged, just add
* code unchanged, just add the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead); * the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead); therefore we recommend
* therefore we recommend that you use this interface directly * that you use this interface directly
* *
* @param dataId dataId * @param dataId dataId
* @param group group * @param group group
* @param timeoutMs read timeout * @param timeoutMs read timeout
* @param listener {@link Listener} * @param listener {@link Listener}
* @return config value * @return config value
* @throws NacosException NacosException * @throws NacosException NacosException
*/ */
String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener) throws NacosException; String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener)
throws NacosException;
/** /**
* Add a listener to the configuration, after the server modified the * Add a listener to the configuration, after the server modified the configuration, the client will use the
* configuration, the client will use the incoming listener callback. * incoming listener callback. Recommended asynchronous processing, the application can implement the getExecutor
* Recommended asynchronous processing, the application can implement the * method in the ManagerListener, provide a thread pool of execution. If provided, use the main thread callback, May
* getExecutor method in the ManagerListener, provide a thread pool of * block other configurations or be blocked by other configurations.
* execution. If provided, use the main thread callback, May block other
* configurations or be blocked by other configurations.
* *
* @param dataId dataId * @param dataId dataId
* @param group group * @param group group
@ -80,7 +80,7 @@ public interface ConfigService {
boolean publishConfig(String dataId, String group, String content) throws NacosException; boolean publishConfig(String dataId, String group, String content) throws NacosException;
/** /**
* Remove config * Remove config.
* *
* @param dataId dataId * @param dataId dataId
* @param group group * @param group group
@ -90,7 +90,7 @@ public interface ConfigService {
boolean removeConfig(String dataId, String group) throws NacosException; boolean removeConfig(String dataId, String group) throws NacosException;
/** /**
* Remove listener * Remove listener.
* *
* @param dataId dataId * @param dataId dataId
* @param group group * @param group group
@ -99,14 +99,14 @@ public interface ConfigService {
void removeListener(String dataId, String group, Listener listener); void removeListener(String dataId, String group, Listener listener);
/** /**
* Get server status * Get server status.
* *
* @return whether health * @return whether health
*/ */
String getServerStatus(); String getServerStatus();
/** /**
* Shutdown the resource service * Shutdown the resource service.
* *
* @throws NacosException exception. * @throws NacosException exception.
*/ */

View File

@ -17,38 +17,39 @@
package com.alibaba.nacos.api.config; package com.alibaba.nacos.api.config;
/** /**
* Config data type.
*
* @author liaochuntao * @author liaochuntao
* @date 2019-06-14 21:12
**/ **/
public enum ConfigType { public enum ConfigType {
/** /**
* config type is "properties" * config type is "properties".
*/ */
PROPERTIES("properties"), PROPERTIES("properties"),
/** /**
* config type is "xml" * config type is "xml".
*/ */
XML("xml"), XML("xml"),
/** /**
* config type is "json" * config type is "json".
*/ */
JSON("json"), JSON("json"),
/** /**
* config type is "text" * config type is "text".
*/ */
TEXT("text"), TEXT("text"),
/** /**
* config type is "html" * config type is "html".
*/ */
HTML("html"), HTML("html"),
/** /**
* config type is "yaml" * config type is "yaml".
*/ */
YAML("yaml"); YAML("yaml");

View File

@ -13,18 +13,25 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config; package com.alibaba.nacos.api.config;
/** /**
* Property Change Type * Property Change Type.
* *
* @author rushsky518 * @author rushsky518
*/ */
public enum PropertyChangeType { public enum PropertyChangeType {
/** add */ /**
* add.
*/
ADDED, ADDED,
/** modified */ /**
* modified.
*/
MODIFIED, MODIFIED,
/** deleted */ /**
* deleted.
*/
DELETED DELETED
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.annotation; package com.alibaba.nacos.api.config.annotation;
import com.alibaba.nacos.api.annotation.NacosProperties; import com.alibaba.nacos.api.annotation.NacosProperties;
@ -20,7 +21,11 @@ import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigType; import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.api.config.convert.NacosConfigConverter; import com.alibaba.nacos.api.config.convert.NacosConfigConverter;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP; import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
@ -36,21 +41,21 @@ import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
public @interface NacosConfigListener { public @interface NacosConfigListener {
/** /**
* Nacos Group ID * Nacos Group ID.
* *
* @return default value {@link Constants#DEFAULT_GROUP}; * @return default value {@link Constants#DEFAULT_GROUP};
*/ */
String groupId() default DEFAULT_GROUP; String groupId() default DEFAULT_GROUP;
/** /**
* Nacos Data ID * Nacos Data ID.
* *
* @return required value. * @return required value.
*/ */
String dataId(); String dataId();
/** /**
* Nacos Config type * Nacos Config type.
* *
* @return "properties" * @return "properties"
*/ */

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.annotation; package com.alibaba.nacos.api.config.annotation;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
@ -20,7 +21,11 @@ import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigType; import com.alibaba.nacos.api.config.ConfigType;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP; import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
@ -37,37 +42,35 @@ import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
public @interface NacosConfigurationProperties { public @interface NacosConfigurationProperties {
/** /**
* config prefix name * config prefix name.
* *
* @return default value is <code>""</code> * @return default value is <code>""</code>
*/ */
String prefix() default ""; String prefix() default "";
/** /**
* Nacos Group ID * Nacos Group ID.
* *
* @return default value {@link Constants#DEFAULT_GROUP}; * @return default value {@link Constants#DEFAULT_GROUP};
*/ */
String groupId() default DEFAULT_GROUP; String groupId() default DEFAULT_GROUP;
/** /**
* Nacos Data ID * Nacos Data ID.
* *
* @return required value. * @return required value.
*/ */
String dataId(); String dataId();
/** /**
* set config type is yaml * set config type is yaml this method is deprecated, we support you use {@link #type()} to set config type.
* this method is deprecated, we support you use {@link #type()} to set config type
* *
* @return default value <code>false</code> * @return default value <code>false</code>
*/ */
@Deprecated @Deprecated boolean yaml() default false;
boolean yaml() default false;
/** /**
* config style * config style.
* *
* @return default value is {@link ConfigType#PROPERTIES} * @return default value is {@link ConfigType#PROPERTIES}
*/ */

View File

@ -13,9 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.annotation; package com.alibaba.nacos.api.config.annotation;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* An annotation for ignore field from annotated {@link NacosConfigurationProperties} Properties Object. * An annotation for ignore field from annotated {@link NacosConfigurationProperties} Properties Object.
@ -29,4 +34,5 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
public @interface NacosIgnore { public @interface NacosIgnore {
} }

View File

@ -13,9 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.annotation; package com.alibaba.nacos.api.config.annotation;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* An annotation for Nacos Property name of Nacos Configuration to bind a field from annotated {@link * An annotation for Nacos Property name of Nacos Configuration to bind a field from annotated {@link
@ -32,7 +37,7 @@ import java.lang.annotation.*;
public @interface NacosProperty { public @interface NacosProperty {
/** /**
* The property name of Nacos Configuration to bind a field * The property name of Nacos Configuration to bind a field.
* *
* @return property name * @return property name
*/ */

View File

@ -13,12 +13,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.annotation; package com.alibaba.nacos.api.config.annotation;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* Annotation which extends value to support auto-refresh * Annotation which extends value to support auto-refresh.
* *
* @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a> * @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a>
* @since 0.2.0 * @since 0.2.0

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.convert; package com.alibaba.nacos.api.config.convert;
/** /**
* Nacos Config Converter * Nacos Config Converter.
* *
* @param <T> the target type that wanted * @param <T> the target type that wanted
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
@ -25,7 +26,7 @@ package com.alibaba.nacos.api.config.convert;
public interface NacosConfigConverter<T> { public interface NacosConfigConverter<T> {
/** /**
* can convert to be target type or not * can convert to be target type or not.
* *
* @param targetType the type of target * @param targetType the type of target
* @return If can , return <code>true</code>, or <code>false</code> * @return If can , return <code>true</code>, or <code>false</code>

View File

@ -13,24 +13,26 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.filter; package com.alibaba.nacos.api.config.filter;
/** /**
* Config Context Interface * Config Context Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface IConfigContext { public interface IConfigContext {
/** /**
* Get context param by key * Get context param by key.
* *
* @param key * @param key parameter key
* @return context * @return context
*/ */
Object getParameter(String key); Object getParameter(String key);
/** /**
* Set context param * Set context param.
* *
* @param key key * @param key key
* @param value value * @param value value

View File

@ -13,25 +13,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.filter; package com.alibaba.nacos.api.config.filter;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
/** /**
* Config Filter Interface * Config Filter Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface IConfigFilter { public interface IConfigFilter {
/** /**
* Init * Init.
* *
* @param filterConfig Filter Config * @param filterConfig Filter Config
*/ */
void init(IFilterConfig filterConfig); void init(IFilterConfig filterConfig);
/** /**
* do filter * do filter.
* *
* @param request request * @param request request
* @param response response * @param response response
@ -42,19 +44,19 @@ public interface IConfigFilter {
throws NacosException; throws NacosException;
/** /**
* deploy * deploy.
*/ */
void deploy(); void deploy();
/** /**
* Get order * Get order.
* *
* @return order number * @return order number
*/ */
int getOrder(); int getOrder();
/** /**
* Get filterName * Get filterName.
* *
* @return filter name * @return filter name
*/ */

View File

@ -13,18 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.filter; package com.alibaba.nacos.api.config.filter;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
/** /**
* Config Filter Chain Interface * Config Filter Chain Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface IConfigFilterChain { public interface IConfigFilterChain {
/** /**
* Filter aciton * Filter action.
* *
* @param request request * @param request request
* @param response response * @param response response

View File

@ -13,16 +13,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.filter; package com.alibaba.nacos.api.config.filter;
/** /**
* Config Request Interface * Config Request Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface IConfigRequest { public interface IConfigRequest {
/** /**
* get param * get param.
* *
* @param key key * @param key key
* @return value * @return value
@ -30,9 +32,9 @@ public interface IConfigRequest {
Object getParameter(String key); Object getParameter(String key);
/** /**
* get config context * get config context.
* *
* @return * @return {@link IConfigContext}
*/ */
IConfigContext getConfigContext(); IConfigContext getConfigContext();

View File

@ -13,16 +13,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.filter; package com.alibaba.nacos.api.config.filter;
/** /**
* Config Response Interface * Config Response Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface IConfigResponse { public interface IConfigResponse {
/** /**
* get param * get param.
* *
* @param key key * @param key key
* @return value * @return value
@ -30,7 +32,7 @@ public interface IConfigResponse {
Object getParameter(String key); Object getParameter(String key);
/** /**
* Get config context * Get config context.
* *
* @return configContext * @return configContext
*/ */

View File

@ -13,26 +13,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.filter; package com.alibaba.nacos.api.config.filter;
/** /**
* Filter Config Interface * Filter Config Interface.
* *
* @author Nacos * @author Nacos
*/ */
public interface IFilterConfig { public interface IFilterConfig {
/** /**
* get filter name * get filter name.
* *
* @return * @return filter name
*/ */
String getFilterName(); String getFilterName();
/** /**
* Get init param * Get init param.
* *
* @param name * @param name parameter name
* @return param * @return param
*/ */
Object getInitParameter(String name); Object getInitParameter(String name);

View File

@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.listener; package com.alibaba.nacos.api.config.listener;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
* Listener Adapter,use default notify thread * Listener Adapter,use default notify thread.
* *
* @author water.lyl * @author water.lyl
*/ */
@ -26,7 +27,7 @@ import java.util.concurrent.Executor;
public abstract class AbstractListener implements Listener { public abstract class AbstractListener implements Listener {
/** /**
* Use default executor * Use default executor.
*/ */
@Override @Override
public Executor getExecutor() { public Executor getExecutor() {

View File

@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.listener; package com.alibaba.nacos.api.config.listener;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
* Shared Listener * Shared Listener.
* *
* @author Nacos * @author Nacos
*/ */
@ -26,6 +27,7 @@ import java.util.concurrent.Executor;
public abstract class AbstractSharedListener implements Listener { public abstract class AbstractSharedListener implements Listener {
private volatile String dataId; private volatile String dataId;
private volatile String group; private volatile String group;
public final void fillContext(String dataId, String group) { public final void fillContext(String dataId, String group) {
@ -44,7 +46,7 @@ public abstract class AbstractSharedListener implements Listener {
} }
/** /**
* receive * receive.
* *
* @param dataId data ID * @param dataId data ID
* @param group group * @param group group

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.listener; package com.alibaba.nacos.api.config.listener;
import com.alibaba.nacos.api.config.ConfigChangeItem; import com.alibaba.nacos.api.config.ConfigChangeItem;
@ -21,25 +22,28 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
/** /**
* ConfigChangeParser * ConfigChangeParser.
* *
* @author rushsky518 * @author rushsky518
*/ */
public interface ConfigChangeParser { public interface ConfigChangeParser {
/** /**
* judge type * Judge type.
* @param type *
* @return * @param type data type
* @return true if is responsible type, otherwise false
*/ */
boolean isResponsibleFor(String type); boolean isResponsibleFor(String type);
/** /**
* compare old and new data * Compare old and new data.
* @param oldContent *
* @param newContent * @param oldContent old content
* @param type * @param newContent new content
* @return * @param type data type
* @throws IOException * @return key and change item map
* @throws IOException io exception
*/ */
Map<String, ConfigChangeItem> doParse(String oldContent, String newContent, String type) throws IOException; Map<String, ConfigChangeItem> doParse(String oldContent, String newContent, String type) throws IOException;
} }

View File

@ -13,26 +13,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.listener; package com.alibaba.nacos.api.config.listener;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
* Listener for watch config * Listener for watch config.
* *
* @author Nacos * @author Nacos
*/ */
public interface Listener { public interface Listener {
/** /**
* Get executor for execute this receive * Get executor for execute this receive.
* *
* @return Executor * @return Executor
*/ */
Executor getExecutor(); Executor getExecutor();
/** /**
* Receive config info * Receive config info.
* *
* @param configInfo config info * @param configInfo config info
*/ */

View File

@ -61,10 +61,6 @@ public class NacosDeserializationException extends NacosRuntimeException {
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetType.toString()), throwable); super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetType.toString()), throwable);
} }
public Class<?> getTargetClass() { public Class<?> getTargetClass() {
return targetClass; return targetClass;
} }

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming; package com.alibaba.nacos.api.naming;
/** /**
* Common parameters for service discovery * Common parameters for service discovery.
* *
* @author nkorange * @author nkorange
* @since 1.0.0 * @since 1.0.0

View File

@ -13,36 +13,51 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming; package com.alibaba.nacos.api.naming;
import com.alibaba.nacos.api.exception.NacosException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.Properties; import java.util.Properties;
import com.alibaba.nacos.api.exception.NacosException;
/** /**
* Naming Factory * Naming Factory.
* *
* @author nkorange * @author nkorange
*/ */
public class NamingFactory { public class NamingFactory {
/**
* Create a new naming service.
*
* @param serverList server list
* @return new naming service
* @throws NacosException nacos exception
*/
public static NamingService createNamingService(String serverList) throws NacosException { public static NamingService createNamingService(String serverList) throws NacosException {
try { try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService"); Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService");
Constructor constructor = driverImplClass.getConstructor(String.class); Constructor constructor = driverImplClass.getConstructor(String.class);
NamingService vendorImpl = (NamingService)constructor.newInstance(serverList); NamingService vendorImpl = (NamingService) constructor.newInstance(serverList);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }
/**
* Create a new naming service.
*
* @param properties naming service properties
* @return new naming service
* @throws NacosException nacos exception
*/
public static NamingService createNamingService(Properties properties) throws NacosException { public static NamingService createNamingService(Properties properties) throws NacosException {
try { try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService"); Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService");
Constructor constructor = driverImplClass.getConstructor(Properties.class); Constructor constructor = driverImplClass.getConstructor(Properties.class);
NamingService vendorImpl = (NamingService)constructor.newInstance(properties); NamingService vendorImpl = (NamingService) constructor.newInstance(properties);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);

View File

@ -22,27 +22,43 @@ import java.lang.reflect.Constructor;
import java.util.Properties; import java.util.Properties;
/** /**
* Maintain service factory.
*
* @author liaochuntao * @author liaochuntao
* @since 1.0.1 * @since 1.0.1
*/ */
public class NamingMaintainFactory { public class NamingMaintainFactory {
/**
* create a new maintain service.
*
* @param serverList server list
* @return new maintain service
* @throws NacosException nacos exception
*/
public static NamingMaintainService createMaintainService(String serverList) throws NacosException { public static NamingMaintainService createMaintainService(String serverList) throws NacosException {
try { try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingMaintainService"); Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingMaintainService");
Constructor constructor = driverImplClass.getConstructor(String.class); Constructor constructor = driverImplClass.getConstructor(String.class);
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList); NamingMaintainService vendorImpl = (NamingMaintainService) constructor.newInstance(serverList);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }
/**
* create a new maintain service.
*
* @param properties properties
* @return new maintain service
* @throws NacosException nacos exception
*/
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException { public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
try { try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingMaintainService"); Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingMaintainService");
Constructor constructor = driverImplClass.getConstructor(Properties.class); Constructor constructor = driverImplClass.getConstructor(Properties.class);
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties); NamingMaintainService vendorImpl = (NamingMaintainService) constructor.newInstance(properties);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);

View File

@ -24,7 +24,7 @@ import com.alibaba.nacos.api.selector.AbstractSelector;
import java.util.Map; import java.util.Map;
/** /**
* Operations related to Nacos * Operations related to Nacos.
* *
* @author liaochuntao * @author liaochuntao
* @since 1.0.1 * @since 1.0.1
@ -32,136 +32,138 @@ import java.util.Map;
public interface NamingMaintainService { public interface NamingMaintainService {
/** /**
* update instance info * update instance info.
* *
* @param serviceName * @param serviceName service name
* @param instance * @param instance instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
void updateInstance(String serviceName, Instance instance) throws NacosException; void updateInstance(String serviceName, Instance instance) throws NacosException;
/** /**
* update instance info * update instance info.
* *
* @param serviceName * @param serviceName service name
* @param groupName * @param groupName group name
* @param instance * @param instance instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException; void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException;
/** /**
* query service * query service.
* *
* @param serviceName * @param serviceName service name
* @return * @return service
* @throws NacosException * @throws NacosException nacos exception
*/ */
Service queryService(String serviceName) throws NacosException; Service queryService(String serviceName) throws NacosException;
/** /**
* query service * query service.
* *
* @param serviceName * @param serviceName service name
* @param groupName * @param groupName group name
* @return * @return service
* @throws NacosException * @throws NacosException nacos exception
*/ */
Service queryService(String serviceName, String groupName) throws NacosException; Service queryService(String serviceName, String groupName) throws NacosException;
/** /**
* create service to Nacos * create service to Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @throws NacosException * @throws NacosException nacos exception
*/ */
void createService(String serviceName) throws NacosException; void createService(String serviceName) throws NacosException;
/** /**
* create service to Nacos * create service to Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @throws NacosException * @throws NacosException nacos exception
*/ */
void createService(String serviceName, String groupName) throws NacosException; void createService(String serviceName, String groupName) throws NacosException;
/** /**
* create service to Nacos * create service to Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param protectThreshold protectThreshold of service * @param protectThreshold protectThreshold of service
* @throws NacosException * @throws NacosException nacos exception
*/ */
void createService(String serviceName, String groupName, float protectThreshold) throws NacosException; void createService(String serviceName, String groupName, float protectThreshold) throws NacosException;
/** /**
* create service to Nacos * create service to Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param protectThreshold protectThreshold of service * @param protectThreshold protectThreshold of service
* @param expression expression of selector * @param expression expression of selector
* @throws NacosException * @throws NacosException nacos exception
*/ */
void createService(String serviceName, String groupName, float protectThreshold, String expression) throws NacosException; void createService(String serviceName, String groupName, float protectThreshold, String expression)
throws NacosException;
/** /**
* create service to Nacos * create service to Nacos.
* *
* @param service name of service * @param service name of service
* @param selector selector * @param selector selector
* @throws NacosException * @throws NacosException nacos exception
*/ */
void createService(Service service, AbstractSelector selector) throws NacosException; void createService(Service service, AbstractSelector selector) throws NacosException;
/** /**
* delete service from Nacos * delete service from Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @return if delete service success return true * @return if delete service success return true
* @throws NacosException * @throws NacosException nacos exception
*/ */
boolean deleteService(String serviceName) throws NacosException; boolean deleteService(String serviceName) throws NacosException;
/** /**
* delete service from Nacos * delete service from Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @return if delete service success return true * @return if delete service success return true
* @throws NacosException * @throws NacosException nacos exception
*/ */
boolean deleteService(String serviceName, String groupName) throws NacosException; boolean deleteService(String serviceName, String groupName) throws NacosException;
/** /**
* update service to Nacos * update service to Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param protectThreshold protectThreshold of service * @param protectThreshold protectThreshold of service
* @throws NacosException * @throws NacosException nacos exception
*/ */
void updateService(String serviceName, String groupName, float protectThreshold) throws NacosException; void updateService(String serviceName, String groupName, float protectThreshold) throws NacosException;
/** /**
* update service to Nacos * update service to Nacos.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param protectThreshold protectThreshold of service * @param protectThreshold protectThreshold of service
* @param metadata metadata of service * @param metadata metadata of service
* @throws NacosException * @throws NacosException nacos exception
*/ */
void updateService(String serviceName, String groupName, float protectThreshold, Map<String, String> metadata) throws NacosException; void updateService(String serviceName, String groupName, float protectThreshold, Map<String, String> metadata)
throws NacosException;
/** /**
* update service to Nacos with selector * update service to Nacos with selector.
* *
* @param service {@link Service} pojo of service * @param service {@link Service} pojo of service
* @param selector {@link AbstractSelector} pojo of selector * @param selector {@link AbstractSelector} pojo of selector
* @throws NacosException * @throws NacosException nacos exception
*/ */
void updateService(Service service, AbstractSelector selector) throws NacosException; void updateService(Service service, AbstractSelector selector) throws NacosException;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming; package com.alibaba.nacos.api.naming;
import com.alibaba.nacos.api.common.ResponseCode; import com.alibaba.nacos.api.common.ResponseCode;
@ -20,7 +21,7 @@ import com.alibaba.nacos.api.common.ResponseCode;
/** /**
* Business response code of naming module * Business response code of naming module
* *
* Every code stays between 20001 to 29999. * <p>Every code stays between 20001 to 29999.
* *
* @author nkorange * @author nkorange
* @author 1.2.0 * @author 1.2.0
@ -28,7 +29,7 @@ import com.alibaba.nacos.api.common.ResponseCode;
public class NamingResponseCode extends ResponseCode { public class NamingResponseCode extends ResponseCode {
/** /**
* The requested resource is not found * The requested resource is not found.
*/ */
public static final int RESOURCE_NOT_FOUND = 20404; public static final int RESOURCE_NOT_FOUND = 20404;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming; package com.alibaba.nacos.api.naming;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
@ -25,302 +26,309 @@ import com.alibaba.nacos.api.selector.AbstractSelector;
import java.util.List; import java.util.List;
/** /**
* Naming Service * Naming Service.
* *
* @author nkorange * @author nkorange
*/ */
public interface NamingService { public interface NamingService {
/** /**
* register a instance to service * register a instance to service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @throws NacosException * @throws NacosException nacos exception
*/ */
void registerInstance(String serviceName, String ip, int port) throws NacosException; void registerInstance(String serviceName, String ip, int port) throws NacosException;
/** /**
* register a instance to service * register a instance to service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @throws NacosException * @throws NacosException nacos exception
*/ */
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException; void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
/** /**
* register a instance to service with specified cluster name * register a instance to service with specified cluster name.
* *
* @param serviceName name of service * @param serviceName name of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @param clusterName instance cluster name * @param clusterName instance cluster name
* @throws NacosException * @throws NacosException nacos exception
*/ */
void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException; void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
/** /**
* register a instance to service with specified cluster name * register a instance to service with specified cluster name.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @param clusterName instance cluster name * @param clusterName instance cluster name
* @throws NacosException * @throws NacosException nacos exception
*/ */
void registerInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException; void registerInstance(String serviceName, String groupName, String ip, int port, String clusterName)
throws NacosException;
/** /**
* register a instance to service with specified instance properties * register a instance to service with specified instance properties.
* *
* @param serviceName name of service * @param serviceName name of service
* @param instance instance to register * @param instance instance to register
* @throws NacosException * @throws NacosException nacos exception
*/ */
void registerInstance(String serviceName, Instance instance) throws NacosException; void registerInstance(String serviceName, Instance instance) throws NacosException;
/** /**
* register a instance to service with specified instance properties * register a instance to service with specified instance properties.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param instance instance to register * @param instance instance to register
* @throws NacosException * @throws NacosException nacos exception
*/ */
void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException; void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException;
/** /**
* deregister instance from a service * deregister instance from a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @throws NacosException * @throws NacosException nacos exception
*/ */
void deregisterInstance(String serviceName, String ip, int port) throws NacosException; void deregisterInstance(String serviceName, String ip, int port) throws NacosException;
/** /**
* deregister instance from a service * deregister instance from a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @throws NacosException * @throws NacosException nacos exception
*/ */
void deregisterInstance(String serviceName, String groupName, String ip, int port) throws NacosException; void deregisterInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
/** /**
* deregister instance with specified cluster name from a service * deregister instance with specified cluster name from a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @param clusterName instance cluster name * @param clusterName instance cluster name
* @throws NacosException * @throws NacosException nacos exception
*/ */
void deregisterInstance(String serviceName, String ip, int port, String clusterName) throws NacosException; void deregisterInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
/** /**
* deregister instance with specified cluster name from a service * deregister instance with specified cluster name from a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param ip instance ip * @param ip instance ip
* @param port instance port * @param port instance port
* @param clusterName instance cluster name * @param clusterName instance cluster name
* @throws NacosException * @throws NacosException nacos exception
*/ */
void deregisterInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException; void deregisterInstance(String serviceName, String groupName, String ip, int port, String clusterName)
throws NacosException;
/** /**
* deregister instance with full instance information and default groupName * deregister instance with full instance information and default groupName.
* @param serviceName *
* @param instance * @param serviceName name of service
* @throws NacosException * @param instance instance
* @throws NacosException nacos exception
*/ */
void deregisterInstance(String serviceName, Instance instance) throws NacosException; void deregisterInstance(String serviceName, Instance instance) throws NacosException;
/** /**
* deregister instance with full instance information * deregister instance with full instance information.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param instance instance information * @param instance instance information
* @throws NacosException * @throws NacosException nacos exception
*/ */
void deregisterInstance(String serviceName, String groupName, Instance instance) throws NacosException; void deregisterInstance(String serviceName, String groupName, Instance instance) throws NacosException;
/** /**
* get all instances of a service * get all instances of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @return A list of instance * @return A list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName) throws NacosException; List<Instance> getAllInstances(String serviceName) throws NacosException;
/** /**
* get all instances of a service * get all instances of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @return A list of instance * @return A list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, String groupName) throws NacosException; List<Instance> getAllInstances(String serviceName, String groupName) throws NacosException;
/** /**
* Get all instances of a service * Get all instances of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A list of instance * @return A list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, boolean subscribe) throws NacosException; List<Instance> getAllInstances(String serviceName, boolean subscribe) throws NacosException;
/** /**
* Get all instances of a service * Get all instances of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A list of instance * @return A list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, String groupName, boolean subscribe) throws NacosException; List<Instance> getAllInstances(String serviceName, String groupName, boolean subscribe) throws NacosException;
/** /**
* Get all instances within specified clusters of a service * Get all instances within specified clusters of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters list of cluster * @param clusters list of cluster
* @return A list of qualified instance * @return A list of qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, List<String> clusters) throws NacosException; List<Instance> getAllInstances(String serviceName, List<String> clusters) throws NacosException;
/** /**
* Get all instances within specified clusters of a service * Get all instances within specified clusters of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters list of cluster * @param clusters list of cluster
* @return A list of qualified instance * @return A list of qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters) throws NacosException; List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters) throws NacosException;
/** /**
* Get all instances within specified clusters of a service * Get all instances within specified clusters of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters list of cluster * @param clusters list of cluster
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A list of qualified instance * @return A list of qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe) throws NacosException; List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe) throws NacosException;
/** /**
* Get all instances within specified clusters of a service * Get all instances within specified clusters of a service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters list of cluster * @param clusters list of cluster
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A list of qualified instance * @return A list of qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException; List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters, boolean subscribe)
throws NacosException;
/** /**
* Get qualified instances of service * Get qualified instances of service.
* *
* @param serviceName name of service * @param serviceName name of service.
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException; List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException;
/** /**
* Get qualified instances of service * Get qualified instances of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, String groupName, boolean healthy) throws NacosException; List<Instance> selectInstances(String serviceName, String groupName, boolean healthy) throws NacosException;
/** /**
* Get qualified instances of service * Get qualified instances of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException; List<Instance> selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException;
/** /**
* Get qualified instances of service * Get qualified instances of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, String groupName, boolean healthy, boolean subscribe) throws NacosException; List<Instance> selectInstances(String serviceName, String groupName, boolean healthy, boolean subscribe)
throws NacosException;
/** /**
* Get qualified instances within specified clusters of service * Get qualified instances within specified clusters of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters list of cluster * @param clusters list of cluster
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy) throws NacosException; List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy) throws NacosException;
/** /**
* Get qualified instances within specified clusters of service * Get qualified instances within specified clusters of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters list of cluster * @param clusters list of cluster
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy) throws NacosException; List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy)
throws NacosException;
/** /**
* Get qualified instances within specified clusters of service * Get qualified instances within specified clusters of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters list of cluster * @param clusters list of cluster
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy, boolean subscribe) throws NacosException; List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy, boolean subscribe)
throws NacosException;
/** /**
* Get qualified instances within specified clusters of service * Get qualified instances within specified clusters of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
@ -328,229 +336,236 @@ public interface NamingService {
* @param healthy a flag to indicate returning healthy or unhealthy instances * @param healthy a flag to indicate returning healthy or unhealthy instances
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return A qualified list of instance * @return A qualified list of instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy, boolean subscribe) throws NacosException; List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy,
boolean subscribe) throws NacosException;
/** /**
* Select one healthy instance of service using predefined load balance strategy * Select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName) throws NacosException; Instance selectOneHealthyInstance(String serviceName) throws NacosException;
/** /**
* Select one healthy instance of service using predefined load balance strategy * Select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, String groupName) throws NacosException; Instance selectOneHealthyInstance(String serviceName, String groupName) throws NacosException;
/** /**
* select one healthy instance of service using predefined load balance strategy * select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, boolean subscribe) throws NacosException; Instance selectOneHealthyInstance(String serviceName, boolean subscribe) throws NacosException;
/** /**
* select one healthy instance of service using predefined load balance strategy * select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, String groupName, boolean subscribe) throws NacosException; Instance selectOneHealthyInstance(String serviceName, String groupName, boolean subscribe) throws NacosException;
/** /**
* Select one healthy instance of service using predefined load balance strategy * Select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters a list of clusters should the instance belongs to * @param clusters a list of clusters should the instance belongs to
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, List<String> clusters) throws NacosException; Instance selectOneHealthyInstance(String serviceName, List<String> clusters) throws NacosException;
/** /**
* Select one healthy instance of service using predefined load balance strategy * Select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters a list of clusters should the instance belongs to * @param clusters a list of clusters should the instance belongs to
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters) throws NacosException; Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters)
throws NacosException;
/** /**
* Select one healthy instance of service using predefined load balance strategy * Select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters a list of clusters should the instance belongs to * @param clusters a list of clusters should the instance belongs to
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe) throws NacosException; Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe)
throws NacosException;
/** /**
* Select one healthy instance of service using predefined load balance strategy * Select one healthy instance of service using predefined load balance strategy.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters a list of clusters should the instance belongs to * @param clusters a list of clusters should the instance belongs to
* @param subscribe if subscribe the service * @param subscribe if subscribe the service
* @return qualified instance * @return qualified instance
* @throws NacosException * @throws NacosException nacos exception
*/ */
Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException; Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters, boolean subscribe)
throws NacosException;
/** /**
* Subscribe service to receive events of instances alteration * Subscribe service to receive events of instances alteration.
* *
* @param serviceName name of service * @param serviceName name of service
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void subscribe(String serviceName, EventListener listener) throws NacosException; void subscribe(String serviceName, EventListener listener) throws NacosException;
/** /**
* Subscribe service to receive events of instances alteration * Subscribe service to receive events of instances alteration.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void subscribe(String serviceName, String groupName, EventListener listener) throws NacosException; void subscribe(String serviceName, String groupName, EventListener listener) throws NacosException;
/** /**
* Subscribe service to receive events of instances alteration * Subscribe service to receive events of instances alteration.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters list of cluster * @param clusters list of cluster
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void subscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException; void subscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException;
/** /**
* Subscribe service to receive events of instances alteration * Subscribe service to receive events of instances alteration.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters list of cluster * @param clusters list of cluster
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException; void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener)
throws NacosException;
/** /**
* Unsubscribe event listener of service * Unsubscribe event listener of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void unsubscribe(String serviceName, EventListener listener) throws NacosException; void unsubscribe(String serviceName, EventListener listener) throws NacosException;
/** /**
* unsubscribe event listener of service * unsubscribe event listener of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void unsubscribe(String serviceName, String groupName, EventListener listener) throws NacosException; void unsubscribe(String serviceName, String groupName, EventListener listener) throws NacosException;
/** /**
* Unsubscribe event listener of service * Unsubscribe event listener of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param clusters list of cluster * @param clusters list of cluster
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void unsubscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException; void unsubscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException;
/** /**
* Unsubscribe event listener of service * Unsubscribe event listener of service.
* *
* @param serviceName name of service * @param serviceName name of service
* @param groupName group of service * @param groupName group of service
* @param clusters list of cluster * @param clusters list of cluster
* @param listener event listener * @param listener event listener
* @throws NacosException * @throws NacosException nacos exception
*/ */
void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException; void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener)
throws NacosException;
/** /**
* Get all service names from server * Get all service names from server.
* *
* @param pageNo page index * @param pageNo page index
* @param pageSize page size * @param pageSize page size
* @return list of service names * @return list of service names
* @throws NacosException * @throws NacosException nacos exception
*/ */
ListView<String> getServicesOfServer(int pageNo, int pageSize) throws NacosException; ListView<String> getServicesOfServer(int pageNo, int pageSize) throws NacosException;
/** /**
* Get all service names from server * Get all service names from server.
* *
* @param pageNo page index * @param pageNo page index
* @param pageSize page size * @param pageSize page size
* @param groupName group name * @param groupName group name
* @return list of service names * @return list of service names
* @throws NacosException * @throws NacosException nacos exception
*/ */
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException; ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException;
/** /**
* Get all service names from server with selector * Get all service names from server with selector.
* *
* @param pageNo page index * @param pageNo page index
* @param pageSize page size * @param pageSize page size
* @param selector selector to filter the resource * @param selector selector to filter the resource
* @return list of service names * @return list of service names
* @throws NacosException * @throws NacosException nacos exception
* @since 0.7.0 * @since 0.7.0
*/ */
ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException; ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException;
/** /**
* Get all service names from server with selector * Get all service names from server with selector.
* *
* @param pageNo page index * @param pageNo page index
* @param pageSize page size * @param pageSize page size
* @param groupName group name * @param groupName group name
* @param selector selector to filter the resource * @param selector selector to filter the resource
* @return list of service names * @return list of service names
* @throws NacosException * @throws NacosException nacos exception
*/ */
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException; ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector)
throws NacosException;
/** /**
* Get all subscribed services of current client * Get all subscribed services of current client.
* *
* @return subscribed services * @return subscribed services
* @throws NacosException * @throws NacosException nacos exception
*/ */
List<ServiceInfo> getSubscribeServices() throws NacosException; List<ServiceInfo> getSubscribeServices() throws NacosException;
/** /**
* get server health status * get server health status.
* *
* @return is server healthy * @return is server healthy
*/ */

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming; package com.alibaba.nacos.api.naming;
/** /**
* Some keys of metadata that are recognized by Nacos * Some keys of metadata that are recognized by Nacos.
* *
* @author nkorange * @author nkorange
* @since 1.0.0 * @since 1.0.0

View File

@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.listener; package com.alibaba.nacos.api.naming.listener;
/** /**
* Event Interface * Event Interface.
* *
* @author nkorange * @author nkorange
*/ */
public interface Event { public interface Event {
} }

View File

@ -13,18 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.listener; package com.alibaba.nacos.api.naming.listener;
/** /**
* Event Listener * Event Listener.
* *
* @author Nacos * @author Nacos
*/ */
public interface EventListener { public interface EventListener {
/** /**
* callback event * callback event.
* *
* @param event * @param event event
*/ */
void onEvent(Event event); void onEvent(Event event);
} }

View File

@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.listener;
import java.util.List; package com.alibaba.nacos.api.naming.listener;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import java.util.List;
/** /**
* Naming Event * Naming Event.
* *
* @author nkorange * @author nkorange
*/ */

View File

@ -13,33 +13,38 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.pojo;
import java.util.HashMap; package com.alibaba.nacos.api.naming.pojo;
import java.util.Map;
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker; import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import java.util.HashMap;
import java.util.Map;
/** /**
* Cluster * Cluster.
*
* <p>The class will be serialized to json, and there are some variables and method can't use Camel naming rule for
* compatibility
* *
* @author nkorange * @author nkorange
*/ */
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class Cluster { public class Cluster {
/** /**
* Name of belonging service * Name of belonging service.
*/ */
private String serviceName; private String serviceName;
/** /**
* Name of cluster * Name of cluster.
*/ */
private String name; private String name;
/** /**
* Health check config of this cluster * Health check config of this cluster.
*/ */
private AbstractHealthChecker healthChecker = new Tcp(); private AbstractHealthChecker healthChecker = new Tcp();

View File

@ -182,10 +182,10 @@ public class Instance {
@Override @Override
public String toString() { public String toString() {
return "Instance{" + "instanceId='" + instanceId + '\'' + ", ip='" + ip + '\'' + ", port=" + port return "Instance{" + "instanceId='" + instanceId + '\'' + ", ip='" + ip + '\'' + ", port=" + port + ", weight="
+ ", weight=" + weight + ", healthy=" + healthy + ", enabled=" + enabled + ", ephemeral=" + weight + ", healthy=" + healthy + ", enabled=" + enabled + ", ephemeral=" + ephemeral
+ ephemeral + ", clusterName='" + clusterName + '\'' + ", serviceName='" + serviceName + ", clusterName='" + clusterName + '\'' + ", serviceName='" + serviceName + '\'' + ", metadata="
+ '\'' + ", metadata=" + metadata + '}'; + metadata + '}';
} }
public String toInetAddr() { public String toInetAddr() {

View File

@ -13,18 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.pojo; package com.alibaba.nacos.api.naming.pojo;
import java.util.List; import java.util.List;
/** /**
* ListView * ListView.
* *
* @author nkorange * @author nkorange
*/ */
public class ListView<T> { public class ListView<T> {
private List<T> data; private List<T> data;
private int count; private int count;
public List<T> getData() { public List<T> getData() {
@ -45,9 +47,6 @@ public class ListView<T> {
@Override @Override
public String toString() { public String toString() {
return "ListView{" + return "ListView{" + "data=" + data + ", count=" + count + '}';
"data=" + data +
", count=" + count +
'}';
} }
} }

View File

@ -13,34 +13,36 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.pojo; package com.alibaba.nacos.api.naming.pojo;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Service of Nacos * Service of Nacos.
* <p> *
* We introduce a 'service --> cluster --> instance' model, in which service stores a list of clusters, * <p>We introduce a 'service --> cluster --> instance' model, in which service stores a list of clusters, which contains a
* which contains a list of instances. * list of instances.
* <p> *
* Typically we put some unique properties between instances to service level. * <p>Typically we put some unique properties between instances to service level.
* *
* @author nkorange * @author nkorange
*/ */
public class Service { public class Service {
/** /**
* service name * service name.
*/ */
private String name; private String name;
/** /**
* protect threshold * protect threshold.
*/ */
private float protectThreshold = 0.0F; private float protectThreshold = 0.0F;
/** /**
* application name of this service * application name of this service.
*/ */
private String appName; private String appName;
@ -104,12 +106,7 @@ public class Service {
@Override @Override
public String toString() { public String toString() {
return "Service{" + return "Service{" + "name='" + name + '\'' + ", protectThreshold=" + protectThreshold + ", appName='" + appName
"name='" + name + '\'' + + '\'' + ", groupName='" + groupName + '\'' + ", metadata=" + metadata + '}';
", protectThreshold=" + protectThreshold +
", appName='" + appName + '\'' +
", groupName='" + groupName + '\'' +
", metadata=" + metadata +
'}';
} }
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.pojo; package com.alibaba.nacos.api.naming.pojo;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
@ -27,7 +28,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
* ServiceInfo * ServiceInfo.
* *
* @author nkorange * @author nkorange
*/ */
@ -146,6 +147,11 @@ public class ServiceInfo {
return new ArrayList<Instance>(hosts); return new ArrayList<Instance>(hosts);
} }
/**
* Judge whether service info is validate.
*
* @return true if validate, otherwise false
*/
public boolean validate() { public boolean validate() {
if (isAllIPs()) { if (isAllIPs()) {
return true; return true;
@ -179,6 +185,16 @@ public class ServiceInfo {
return getKey(name, clusters); return getKey(name, clusters);
} }
@JsonIgnore
public static String getKey(String name, String clusters) {
if (!isEmpty(clusters)) {
return name + Constants.SERVICE_INFO_SPLITER + clusters;
}
return name;
}
@JsonIgnore @JsonIgnore
public String getKeyEncoded() { public String getKeyEncoded() {
try { try {
@ -188,11 +204,17 @@ public class ServiceInfo {
} }
} }
/**
* Get {@link ServiceInfo} from key.
*
* @param key key of service info
* @return new service info
*/
public static ServiceInfo fromKey(String key) { public static ServiceInfo fromKey(String key) {
ServiceInfo serviceInfo = new ServiceInfo(); ServiceInfo serviceInfo = new ServiceInfo();
int maxSegCount = 3; int maxSegCount = 3;
String[] segs = key.split(Constants.SERVICE_INFO_SPLITER); String[] segs = key.split(Constants.SERVICE_INFO_SPLITER);
if (segs.length == maxSegCount -1) { if (segs.length == maxSegCount - 1) {
serviceInfo.setGroupName(segs[0]); serviceInfo.setGroupName(segs[0]);
serviceInfo.setName(segs[1]); serviceInfo.setName(segs[1]);
} else if (segs.length == maxSegCount) { } else if (segs.length == maxSegCount) {
@ -203,16 +225,6 @@ public class ServiceInfo {
return serviceInfo; return serviceInfo;
} }
@JsonIgnore
public static String getKey(String name, String clusters) {
if (!isEmpty(clusters)) {
return name + Constants.SERVICE_INFO_SPLITER + clusters;
}
return name;
}
@Override @Override
public String toString() { public String toString() {
return getKey(); return getKey();
@ -230,14 +242,14 @@ public class ServiceInfo {
return str == null || str.length() == 0; return str == null || str.length() == 0;
} }
private static boolean strEquals(String str1, String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
}
private static boolean isEmpty(Collection coll) { private static boolean isEmpty(Collection coll) {
return (coll == null || coll.isEmpty()); return (coll == null || coll.isEmpty());
} }
private static boolean strEquals(String str1, String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
}
private static final String EMPTY = ""; private static final String EMPTY = "";
private static final String ALL_IPS = "000--00-ALL_IPS--00--000"; private static final String ALL_IPS = "000--00-ALL_IPS--00--000";

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.pojo.healthcheck; package com.alibaba.nacos.api.naming.pojo.healthcheck;
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker.None; import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker.None;
@ -25,15 +26,14 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
/** /**
* Abstract health checker.
*
* @author nkorange * @author nkorange
*/ */
@JsonTypeInfo(use = Id.NAME, property = "type", defaultImpl = None.class) @JsonTypeInfo(use = Id.NAME, property = "type", defaultImpl = None.class)
@JsonSubTypes({ @JsonSubTypes({@JsonSubTypes.Type(name = Http.TYPE, value = Http.class),
@JsonSubTypes.Type(name = Http.TYPE, value = Http.class), @JsonSubTypes.Type(name = Mysql.TYPE, value = Mysql.class),
@JsonSubTypes.Type(name = Mysql.TYPE, value = Mysql.class), @JsonSubTypes.Type(name = Tcp.TYPE, value = Tcp.class)})
@JsonSubTypes.Type(name = Tcp.TYPE, value = Tcp.class)
})
public abstract class AbstractHealthChecker implements Cloneable { public abstract class AbstractHealthChecker implements Cloneable {
@JsonIgnore @JsonIgnore

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.naming.pojo.healthcheck; package com.alibaba.nacos.api.naming.pojo.healthcheck;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
@ -25,57 +26,75 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* Health check type.
*
* @author nkorange * @author nkorange
*/ */
public enum HealthCheckType { public enum HealthCheckType {
/** /**
* TCP type * TCP type.
*/ */
TCP(Tcp.class), TCP(Tcp.class),
/** /**
* HTTP type * HTTP type.
*/ */
HTTP(Http.class), HTTP(Http.class),
/** /**
* MySQL type * MySQL type.
*/ */
MYSQL(Mysql.class), MYSQL(Mysql.class),
/** /**
* No check * No check.
*/ */
NONE(AbstractHealthChecker.None.class); NONE(AbstractHealthChecker.None.class);
private final Class<? extends AbstractHealthChecker> healthCheckerClass; private final Class<? extends AbstractHealthChecker> healthCheckerClass;
/**
* In JDK 1.6, the map need full class for general. So ignore check style.
*/
@SuppressWarnings("checkstyle:linelength")
private static final Map<String, Class<? extends AbstractHealthChecker>> EXTEND = new ConcurrentHashMap<String, Class<? extends AbstractHealthChecker>>(); private static final Map<String, Class<? extends AbstractHealthChecker>> EXTEND = new ConcurrentHashMap<String, Class<? extends AbstractHealthChecker>>();
HealthCheckType(Class<? extends AbstractHealthChecker> healthCheckerClass) { HealthCheckType(Class<? extends AbstractHealthChecker> healthCheckerClass) {
this.healthCheckerClass = healthCheckerClass; this.healthCheckerClass = healthCheckerClass;
} }
public static void registerHealthChecker(String type, Class<? extends AbstractHealthChecker> healthCheckerClass){ /**
* Register extend health checker.
*
* @param type type name of extend health checker
* @param healthCheckerClass class of extend health checker
*/
public static void registerHealthChecker(String type, Class<? extends AbstractHealthChecker> healthCheckerClass) {
if (!EXTEND.containsKey(type)) { if (!EXTEND.containsKey(type)) {
EXTEND.put(type, healthCheckerClass); EXTEND.put(type, healthCheckerClass);
HealthCheckerFactory.registerSubType(healthCheckerClass, type); HealthCheckerFactory.registerSubType(healthCheckerClass, type);
} }
} }
public static Class<? extends AbstractHealthChecker> ofHealthCheckerClass(String type){ /**
* Get health checker class from type.
*
* @param type type name of extend health checker
* @return registered class if have, otherwise default class
*/
public static Class<? extends AbstractHealthChecker> ofHealthCheckerClass(String type) {
HealthCheckType enumType; HealthCheckType enumType;
try { try {
enumType = valueOf(type); enumType = valueOf(type);
}catch (Exception e){ } catch (Exception e) {
return EXTEND.get(type); return EXTEND.get(type);
} }
return enumType.healthCheckerClass; return enumType.healthCheckerClass;
} }
public static List<Class<? extends AbstractHealthChecker>> getLoadedHealthCheckerClasses(){ public static List<Class<? extends AbstractHealthChecker>> getLoadedHealthCheckerClasses() {
List<Class<? extends AbstractHealthChecker>> all = new ArrayList<Class<? extends AbstractHealthChecker>>(); List<Class<? extends AbstractHealthChecker>> all = new ArrayList<Class<? extends AbstractHealthChecker>>();
for(HealthCheckType type : values()){ for (HealthCheckType type : values()) {
all.add(type.healthCheckerClass); all.add(type.healthCheckerClass);
} }
for(Map.Entry<String, Class<? extends AbstractHealthChecker>> entry : EXTEND.entrySet()){ for (Map.Entry<String, Class<? extends AbstractHealthChecker>> entry : EXTEND.entrySet()) {
all.add(entry.getValue()); all.add(entry.getValue());
} }
return all; return all;

View File

@ -16,14 +16,14 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck; package com.alibaba.nacos.api.naming.pojo.healthcheck;
import java.io.IOException;
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker.None; import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker.None;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType; import com.fasterxml.jackson.databind.jsontype.NamedType;
import java.io.IOException;
/** /**
* health checker factory. * health checker factory.
* *
@ -50,9 +50,10 @@ public class HealthCheckerFactory {
* Register new sub type of health checker to factory for serialize and deserialize. * Register new sub type of health checker to factory for serialize and deserialize.
* *
* @param extendHealthCheckerClass extend health checker * @param extendHealthCheckerClass extend health checker
* @param typeName typeName of health checker * @param typeName typeName of health checker
*/ */
public static void registerSubType(Class<? extends AbstractHealthChecker> extendHealthCheckerClass, String typeName) { public static void registerSubType(Class<? extends AbstractHealthChecker> extendHealthCheckerClass,
String typeName) {
MAPPER.registerSubtypes(new NamedType(extendHealthCheckerClass, typeName)); MAPPER.registerSubtypes(new NamedType(extendHealthCheckerClass, typeName));
} }
@ -81,7 +82,7 @@ public class HealthCheckerFactory {
} }
/** /**
* Serialize a instance of health checker to json * Serialize a instance of health checker to json.
* *
* @param healthChecker health checker instance * @param healthChecker health checker instance
* @return son string after serializing * @return son string after serializing

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.selector; package com.alibaba.nacos.api.selector;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
@ -20,7 +21,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
/** /**
* Abstract selector that only contains a type * Abstract selector that only contains a type.
* *
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.selector; package com.alibaba.nacos.api.selector;
/** /**

View File

@ -17,6 +17,8 @@
package com.alibaba.nacos.api.selector; package com.alibaba.nacos.api.selector;
/** /**
* None selector.
*
* @author liaochuntao * @author liaochuntao
* @since 1.0.1 * @since 1.0.1
*/ */

View File

@ -13,25 +13,26 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.selector; package com.alibaba.nacos.api.selector;
/** /**
* The types of selector accepted by Nacos * The types of selector accepted by Nacos.
* *
* @author nkorange * @author nkorange
* @since 0.7.0 * @since 0.7.0
*/ */
public enum SelectorType { public enum SelectorType {
/** /**
* not match any type * not match any type.
*/ */
unknown, unknown,
/** /**
* not filter out any entity * not filter out any entity.
*/ */
none, none,
/** /**
* select by label * select by label.
*/ */
label label
} }

View File

@ -13,5 +13,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
version=${project.version} version=${project.version}

View File

@ -13,20 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.annotation; package com.alibaba.nacos.api.annotation;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.env.MockEnvironment;
import static com.alibaba.nacos.api.annotation.NacosProperties.*; import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.CLUSTER_NAME_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.CONTEXT_PATH_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.ENCODE_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.ENDPOINT_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_PLACEHOLDER;
import static com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER;
/**
* {@link NacosProperties} Test
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 0.2.1
*/
public class NacosPropertiesTest { public class NacosPropertiesTest {
@Test @Test
@ -68,7 +70,8 @@ public class NacosPropertiesTest {
testResolvePlaceholder(ENCODE_PLACEHOLDER, "", "test-value", "UTF-8"); testResolvePlaceholder(ENCODE_PLACEHOLDER, "", "test-value", "UTF-8");
} }
private void testResolvePlaceholder(String placeholder, String propertyName, String propertyValue, String expectValue) { private void testResolvePlaceholder(String placeholder, String propertyName, String propertyValue,
String expectValue) {
MockEnvironment environment = new MockEnvironment(); MockEnvironment environment = new MockEnvironment();
environment.setProperty(propertyName, propertyValue); environment.setProperty(propertyName, propertyValue);
String resolvedValue = environment.resolvePlaceholders(placeholder); String resolvedValue = environment.resolvePlaceholders(placeholder);

View File

@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -57,6 +58,7 @@ public class ServiceInfoTest {
} }
@Test @Test
@SuppressWarnings("checkstyle:linelength")
public void testDeserialize() throws IOException { public void testDeserialize() throws IOException {
String example = "{\"name\":\"testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}"; String example = "{\"name\":\"testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class); ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);

View File

@ -16,18 +16,18 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck; package com.alibaba.nacos.api.naming.pojo.healthcheck;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType; import com.fasterxml.jackson.databind.jsontype.NamedType;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.IOException;
public class AbstractHealthCheckerTest { public class AbstractHealthCheckerTest {
private final ObjectMapper objectMapper = new ObjectMapper(); private final ObjectMapper objectMapper = new ObjectMapper();

View File

@ -16,9 +16,8 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck; package com.alibaba.nacos.api.naming.pojo.healthcheck;
import org.junit.Test;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

View File

@ -16,18 +16,17 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl; package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException; import static org.junit.Assert.assertEquals;
import com.fasterxml.jackson.databind.ObjectMapper; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class HttpTest { public class HttpTest {

View File

@ -16,13 +16,12 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl; package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
import java.io.IOException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;