Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fluent style builder API support(#3431) #3549

Merged
merged 2 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.apache.dubbo.config.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.dubbo.common.Constants;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Inherited
public @interface Method {
chickenlj marked this conversation as resolved.
Show resolved Hide resolved

/**
* Timeout value for service invocation, default value is 0
*/
int timeout() default 0;

/**
* Service invocation retry times
*
* @see Constants#DEFAULT_RETRIES
*/
int retries() default Constants.DEFAULT_RETRIES;

/**
* Load balance strategy, legal values include: random, roundrobin, leastactive
*
* @see Constants#DEFAULT_LOADBALANCE
*/
String loadbalance() default Constants.DEFAULT_LOADBALANCE;

/**
* Whether to enable async invocation, default value is false
*/
boolean async() default false;

/**
* Maximum active requests allowed, default value is 0
*/
int actives() default 0;

/**
* Whether the async request has already been sent, the default value is false
*/
boolean sent() default false;

/**
* Maximum concurrent executes for the service, default value is 0 - no limits
*/
int executes() default 0;

/**
* Whether the service is deprecated, default value is false
*/
boolean deprecated() default false;

/**
* Enable/Disable cluster sticky policy, default value is false.
*/
boolean sticky() default false;

/**
* Method result need return, when async is true.default value is true.
*/
boolean needReturn() default true;

/**
* Specify cache implementation for service invocation, legal values include: lru, threadlocal, jcache
*/
String cache() default "";

/**
* Whether to use JSR303 validation, legal values are: true, false
*/
boolean validation() default false;

/**
* Method return trigger. return attribute must be true
*/
String onReturn() default "";

/**
* Method invoke trigger.
*/
String onInvoke() default "";

/**
* Method on error trigger.return attribute must be true.
*/
String onThrow() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.builders;

import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractConfig;

import java.util.HashMap;
import java.util.Map;

/**
* AbstractBuilder
*
* @since 2.7
*/
public abstract class AbstractBuilder<T extends AbstractConfig, B extends AbstractBuilder> {
/**
* The config id
*/
protected String id;
protected String prefix;

protected B id(String id) {
this.id = id;
return getThis();
}

protected B prefix(String prefix) {
this.prefix = prefix;
return getThis();
}

protected abstract B getThis();

protected static Map<String, String> appendParameter(Map<String, String> parameters, String key, String value) {
if (parameters == null) {
parameters = new HashMap<>();
}
parameters.put(key, value);
return parameters;
}

protected static Map<String, String> appendParameters(Map<String, String> parameters, Map<String, String> appendParameters) {
if (parameters == null) {
parameters = new HashMap<>();
}
parameters.putAll(appendParameters);
return parameters;
}

protected void build(T instance) {
if (!StringUtils.isEmpty(id)) instance.setId(id);
if (!StringUtils.isEmpty(prefix)) instance.setPrefix(prefix);
}
}
Loading