Skip to content

Commit

Permalink
Revert "Polish apache#6389 : [Issue] Resolving the issues with Consul…
Browse files Browse the repository at this point in the history
…ServiceDiscovery"

This reverts commit 7791051.
  • Loading branch information
mercyblitz committed Jul 1, 2020
1 parent e631872 commit 839be93
Show file tree
Hide file tree
Showing 29 changed files with 83 additions and 404 deletions.
39 changes: 1 addition & 38 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.USERNAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.convert.Converter.convertIfPossible;
import static org.apache.dubbo.common.utils.StringUtils.isBlank;

/**
* URL - Uniform Resource Locator (Immutable, ThreadSafe)
Expand Down Expand Up @@ -623,41 +621,6 @@ public List<String> getParameter(String key, List<String> defaultValue) {
return Arrays.asList(strArray);
}

/**
* Get parameter
*
* @param key the key of parameter
* @param valueType the type of parameter value
* @param <T> the type of parameter value
* @return get the parameter if present, or <code>null</code>
* @since 2.7.8
*/
public <T> T getParameter(String key, Class<T> valueType) {
return getParameter(key, valueType, null);
}

/**
* Get parameter
*
* @param key the key of parameter
* @param valueType the type of parameter value
* @param defaultValue the default value if parameter is absent
* @param <T> the type of parameter value
* @return get the parameter if present, or <code>defaultValue</code> will be used.
* @since 2.7.8
*/
public <T> T getParameter(String key, Class<T> valueType, T defaultValue) {
String value = getParameter(key);
T result = null;
if (!isBlank(value)) {
result = convertIfPossible(value, valueType);
}
if (result == null) {
result = defaultValue;
}
return result;
}

private Map<String, Number> getNumbers() {
// concurrent initialization is tolerant
if (numbers == null) {
Expand Down Expand Up @@ -1472,7 +1435,7 @@ public String getColonSeparatedKey() {

private void append(StringBuilder target, String parameterName, boolean first) {
String parameterValue = this.getParameter(parameterName);
if (!isBlank(parameterValue)) {
if (!StringUtils.isBlank(parameterValue)) {
if (!first) {
target.append(":");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,4 @@ default Class<T> getTargetType() {
.findFirst()
.orElse(null);
}

/**
* Convert the value of source to target-type value if possible
*
* @param source the value of source
* @param targetType the target type
* @param <T> the target type
* @return <code>null</code> if can't be converted
* @since 2.7.8
*/
static <T> T convertIfPossible(Object source, Class<T> targetType) {
Converter converter = getConverter(source.getClass(), targetType);
if (converter != null) {
return (T) converter.convert(source);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
*/
package org.apache.dubbo.common.convert.multiple;

import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.common.lang.Prioritized;

import java.util.Collection;

import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
import static org.apache.dubbo.common.utils.TypeUtils.findActualTypeArgument;

/**
Expand Down Expand Up @@ -63,30 +61,4 @@ default Class<S> getSourceType() {
return findActualTypeArgument(getClass(), MultiValueConverter.class, 0);
}

/**
* Find the {@link MultiValueConverter} instance from {@link ExtensionLoader} with the specified source and target type
*
* @param sourceType the source type
* @param targetType the target type
* @return <code>null</code> if not found
* @see ExtensionLoader#getSupportedExtensionInstances()
* @since 2.7.8
*/
static MultiValueConverter<?> find(Class<?> sourceType, Class<?> targetType) {
return getExtensionLoader(MultiValueConverter.class)
.getSupportedExtensionInstances()
.stream()
.filter(converter -> converter.accept(sourceType, targetType))
.findFirst()
.orElse(null);
}

static <T> T convertIfPossible(Object source, Class<?> multiValueType, Class<?> elementType) {
Class<?> sourceType = source.getClass();
MultiValueConverter converter = find(sourceType, multiValueType);
if (converter != null) {
return (T) converter.convert(source, multiValueType, elementType);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,4 @@ public void testGetParameters() {
assertEquals(1, parameters.size());
assertEquals("1.0.0", version);
}

@Test
public void testGetParameter() {
URL url = URL.valueOf("http://127.0.0.1:8080/path?i=1&b=false");
assertEquals(Integer.valueOf(1), url.getParameter("i", Integer.class));
assertEquals(Boolean.FALSE, url.getParameter("b", Boolean.class));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToBooleanConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToCharArrayConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToCharacterConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToDoubleConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToFloatConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToIntegerConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToLongConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToOptionalConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToShortConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert;
package org.apache.dubbo.convert;

import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToStringConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.convert.multiple;
package org.apache.dubbo.convert.multiple;

import org.apache.dubbo.common.convert.multiple.StringToArrayConverter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Loading

0 comments on commit 839be93

Please sign in to comment.