mirror of https://github.com/longtai-cn/hippo4j
# Conflicts: # hippo4j-config/src/main/java/cn/hippo4j/config/controller/ConfigController.java # hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java # hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java # hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.javapull/776/head
commit
eb0ad2bc6f
@ -0,0 +1,130 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE module PUBLIC
|
||||||
|
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||||
|
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||||
|
<module name="Checker">
|
||||||
|
<module name="NewlineAtEndOfFile"/>
|
||||||
|
<module name="RegexpSingleline">
|
||||||
|
<property name="format" value="printStackTrace"/>
|
||||||
|
<property name="message" value="Prohibit invoking printStackTrace in source code !"/>
|
||||||
|
</module>
|
||||||
|
<module name="TreeWalker">
|
||||||
|
<module name="AvoidStarImport">
|
||||||
|
<property name="excludes" value="java.io,java.net,java.lang.Math"/>
|
||||||
|
<property name="allowClassImports" value="false"/>
|
||||||
|
<property name="allowStaticMemberImports" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="IllegalImport"/>
|
||||||
|
<module name="RedundantImport"/>
|
||||||
|
<module name="UnusedImports"/>
|
||||||
|
<module name="JavadocType">
|
||||||
|
<property name="allowUnknownTags" value="true"/>
|
||||||
|
<property name="allowMissingParamTags" value="true"/>
|
||||||
|
<message key="javadoc.missing" value="Class Comments: Missing Javadoc Comments"/>
|
||||||
|
</module>
|
||||||
|
<!-- Do not scan method annotations for now -->
|
||||||
|
<!--<module name="JavadocMethod">
|
||||||
|
<property name="tokens" value="METHOD_DEF"/>
|
||||||
|
<property name="allowMissingPropertyJavadoc" value="true"/>
|
||||||
|
<message key="javadoc.missing" value="Method Comments: Missing Javadoc Comments"/>
|
||||||
|
</module>-->
|
||||||
|
<module name="LocalFinalVariableName"/>
|
||||||
|
<module name="LocalVariableName"/>
|
||||||
|
<module name="PackageName">
|
||||||
|
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$" />
|
||||||
|
</module>
|
||||||
|
<module name="StaticVariableName"/>
|
||||||
|
<module name="TypeName"/>
|
||||||
|
<module name="MemberName"/>
|
||||||
|
<module name="MethodName"/>
|
||||||
|
<module name="ParameterName "/>
|
||||||
|
<module name="ConstantName"/>
|
||||||
|
<module name="ArrayTypeStyle"/>
|
||||||
|
<module name="UpperEll"/>
|
||||||
|
<module name="LineLength">
|
||||||
|
<property name="max" value="200"/>
|
||||||
|
</module>
|
||||||
|
<module name="MethodLength">
|
||||||
|
<property name="tokens" value="METHOD_DEF"/>
|
||||||
|
<property name="max" value="150"/>
|
||||||
|
</module>
|
||||||
|
<module name="ParameterNumber">
|
||||||
|
<property name="max" value="5"/>
|
||||||
|
<property name="ignoreOverriddenMethods" value="true"/>
|
||||||
|
<property name="tokens" value="METHOD_DEF"/>
|
||||||
|
</module>
|
||||||
|
<module name="MethodParamPad"/>
|
||||||
|
<module name="TypecastParenPad"/>
|
||||||
|
<module name="NoWhitespaceAfter"/>
|
||||||
|
<module name="NoWhitespaceBefore"/>
|
||||||
|
<module name="OperatorWrap"/>
|
||||||
|
<module name="ParenPad"/>
|
||||||
|
<module name="WhitespaceAfter"/>
|
||||||
|
<module name="WhitespaceAround"/>
|
||||||
|
<module name="ModifierOrder"/>
|
||||||
|
<module name="RedundantModifier"/>
|
||||||
|
<module name="AvoidNestedBlocks"/>
|
||||||
|
<module name="EmptyBlock"/>
|
||||||
|
<module name="LeftCurly"/>
|
||||||
|
<module name="NeedBraces"/>
|
||||||
|
<module name="RightCurly"/>
|
||||||
|
<module name="EmptyStatement"/>
|
||||||
|
<module name="EqualsHashCode"/>
|
||||||
|
<module name="IllegalInstantiation"/>
|
||||||
|
<module name="InnerAssignment"/>
|
||||||
|
<module name="MagicNumber">
|
||||||
|
<property name="ignoreNumbers" value="0, 1, 2"/>
|
||||||
|
<property name="ignoreAnnotation" value="true"/>
|
||||||
|
<property name="ignoreHashCodeMethod" value="true"/>
|
||||||
|
<property name="ignoreFieldDeclaration" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="MissingSwitchDefault"/>
|
||||||
|
<module name="SimplifyBooleanExpression"/>
|
||||||
|
<module name="SimplifyBooleanReturn"/>
|
||||||
|
<module name="FinalClass"/>
|
||||||
|
<module name="InterfaceIsType"/>
|
||||||
|
<module name="VisibilityModifier">
|
||||||
|
<property name="packageAllowed" value="true"/>
|
||||||
|
<property name="protectedAllowed" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="StringLiteralEquality"/>
|
||||||
|
<module name="NestedForDepth">
|
||||||
|
<property name="max" value="3"/>
|
||||||
|
</module>
|
||||||
|
<module name="NestedIfDepth">
|
||||||
|
<property name="max" value="4"/>
|
||||||
|
</module>
|
||||||
|
<module name="UncommentedMain">
|
||||||
|
<property name="excludedClasses" value=".*Application$"/>
|
||||||
|
</module>
|
||||||
|
<module name="Regexp">
|
||||||
|
<property name="format" value="System\.out\.println"/>
|
||||||
|
<property name="illegalPattern" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="ReturnCount">
|
||||||
|
<property name="max" value="4"/>
|
||||||
|
</module>
|
||||||
|
<module name="NestedTryDepth ">
|
||||||
|
<property name="max" value="4"/>
|
||||||
|
</module>
|
||||||
|
<module name="SuperFinalize"/>
|
||||||
|
<module name="SuperClone"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE suppressions PUBLIC
|
||||||
|
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||||
|
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||||
|
<suppressions>
|
||||||
|
<suppress checks="MagicNumber" files="ResizableCapacityLinkedBlockingQueue.java"/>
|
||||||
|
<suppress checks="InnerAssignment" files="ResizableCapacityLinkedBlockingQueue.java"/>
|
||||||
|
<suppress checks="StaticVariableName" files="ApplicationContextHolder.java"/>
|
||||||
|
<suppress checks="StaticVariableName" files="JacksonHandler.java"/>
|
||||||
|
<suppress checks="MagicNumber" files="ByteConvertUtil.java"/>
|
||||||
|
</suppressions>
|
@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_position: 2
|
|
||||||
---
|
|
||||||
|
|
||||||
# 阻塞队列自定义
|
|
||||||
|
|
||||||
同拒绝策略自定义。
|
|
@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 4
|
||||||
|
---
|
||||||
|
|
||||||
|
# 参数默认配置
|
||||||
|
|
||||||
|
曾有多名小伙伴反馈说,项目中线程池一多,配置文件中配置就显得很臃肿。为此 hippo4j-config 开发出了动态线程池默认配置。
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
default-executor:
|
||||||
|
core-pool-size: 4
|
||||||
|
maximum-pool-size: 6
|
||||||
|
blocking-queue: ResizableCapacityLinkedBlockingQueue
|
||||||
|
queue-capacity: 1024
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 9999
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
active-alarm: 90
|
||||||
|
capacity-alarm: 85
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
notify:
|
||||||
|
interval: 5
|
||||||
|
receives: chen.ma
|
||||||
|
executors:
|
||||||
|
- thread-pool-id: message-produce
|
||||||
|
- thread-pool-id: message-consume
|
||||||
|
core-pool-size: 80
|
||||||
|
maximum-pool-size: 100
|
||||||
|
execute-time-out: 1000
|
||||||
|
notify:
|
||||||
|
interval: 6
|
||||||
|
receives: chen.ma
|
||||||
|
```
|
||||||
|
|
||||||
|
`spring.dynamic.thread-pool.executors` 层级下,仅需要配置 `thread-pool-id`,其余配置从 `spring.dynamic.thread-pool.default-executor` 读取。
|
||||||
|
|
||||||
|
如果 `spring.dynamic.thread-pool.executors` 下配置和 `spring.dynamic.thread-pool.default-executor` 冲突,以前者为主。
|
||||||
|
|
||||||
|
通过该自定义配置方式,可减少大量重复线程池参数配置项,提高核心配置简洁度。
|
||||||
|
|
||||||
|
提示:`spring.dynamic.thread-pool.default-executor` 层级下参数,不提供动态刷新功能。
|
@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.web.exception.IllegalException;
|
||||||
|
import com.github.dozermapper.core.DozerBeanMapperBuilder;
|
||||||
|
import com.github.dozermapper.core.Mapper;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean util.
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class BeanUtil {
|
||||||
|
|
||||||
|
protected static Mapper BEAN_MAPPER_BUILDER;
|
||||||
|
|
||||||
|
static {
|
||||||
|
BEAN_MAPPER_BUILDER = DozerBeanMapperBuilder.buildDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, S> T convert(S source, Class<T> clazz) {
|
||||||
|
return Optional.ofNullable(source)
|
||||||
|
.map(each -> BEAN_MAPPER_BUILDER.map(each, clazz))
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, S> T convert(S source, T target) {
|
||||||
|
Optional.ofNullable(source)
|
||||||
|
.ifPresent(each -> BEAN_MAPPER_BUILDER.map(each, target));
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, S> List<T> convert(List<S> sources, Class<T> clazz) {
|
||||||
|
return Optional.ofNullable(sources)
|
||||||
|
.map(each -> {
|
||||||
|
List<T> targetList = new ArrayList<T>(each.size());
|
||||||
|
each.forEach(item -> targetList.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
|
||||||
|
return targetList;
|
||||||
|
})
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, S> Set<T> convert(Set<S> sources, Class<T> clazz) {
|
||||||
|
return Optional.ofNullable(sources)
|
||||||
|
.map(each -> {
|
||||||
|
Set<T> targetSize = new HashSet<T>(each.size());
|
||||||
|
each.forEach(item -> targetSize.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
|
||||||
|
return targetSize;
|
||||||
|
})
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T mapToBean(Map<String, Object> map, Class<T> clazz, boolean toCamelCase) {
|
||||||
|
if (clazz == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
T newInstance = clazz.newInstance();
|
||||||
|
return mapToBean(map, newInstance, toCamelCase);
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
throw new IllegalException("do not create instance for " + clazz.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* map to bean
|
||||||
|
*
|
||||||
|
* @param map map
|
||||||
|
* @param bean obj bean
|
||||||
|
* @param toCamelCase format to camel case
|
||||||
|
* @param <T> bean type
|
||||||
|
* @return T
|
||||||
|
*/
|
||||||
|
public static <T> T mapToBean(Map<String, Object> map, T bean, boolean toCamelCase) {
|
||||||
|
if (bean == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
Class<?> clazz = bean.getClass();
|
||||||
|
map.forEach((s, o) -> {
|
||||||
|
String name = toCamelCase ? StringUtil.toCamelCase(s, StringUtil.UNDERLINE) : s;
|
||||||
|
Method method = setter(clazz, name);
|
||||||
|
if (method != null) {
|
||||||
|
ReflectUtil.invoke(bean, method, o);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for properties
|
||||||
|
*
|
||||||
|
* @param o obj
|
||||||
|
* @param propertiesName name
|
||||||
|
* @return Method for get
|
||||||
|
*/
|
||||||
|
public static Method getter(Class<?> o, String propertiesName) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PropertyDescriptor descriptor = new PropertyDescriptor(propertiesName, o);
|
||||||
|
return descriptor.getReadMethod();
|
||||||
|
} catch (IntrospectionException e) {
|
||||||
|
throw new IllegalException("not find getter for" + propertiesName + "in" + o.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for properties
|
||||||
|
*
|
||||||
|
* @param o obj
|
||||||
|
* @param propertiesName name
|
||||||
|
* @return Method for set
|
||||||
|
*/
|
||||||
|
public static Method setter(Class<?> o, String propertiesName) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PropertyDescriptor descriptor = new PropertyDescriptor(propertiesName, o);
|
||||||
|
return descriptor.getWriteMethod();
|
||||||
|
} catch (IntrospectionException e) {
|
||||||
|
throw new IllegalException("not find setter for" + propertiesName + "in" + o.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.SimpleTimeZone;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date and time util
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class DateUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get time zone for this JVM
|
||||||
|
*/
|
||||||
|
private static final TimeZone TIME_ZONE = TimeZone.getDefault();
|
||||||
|
|
||||||
|
public static final String NORM_DATE_PATTERN = "yyyy-MM-dd";
|
||||||
|
|
||||||
|
public static final String NORM_TIME_PATTERN = "HH:mm:ss";
|
||||||
|
|
||||||
|
public static final String NORM_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
|
||||||
|
* represented by this <tt>Date</tt> object.
|
||||||
|
*
|
||||||
|
* @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
|
||||||
|
* represented by this date.
|
||||||
|
*/
|
||||||
|
public static long getTime(LocalDateTime date) {
|
||||||
|
return getTime(date, TIME_ZONE.toZoneId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getTime(LocalDateTime date, ZoneId zoneId) {
|
||||||
|
return date.atZone(zoneId).toInstant().toEpochMilli();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* modify format to date
|
||||||
|
*
|
||||||
|
* @param date date
|
||||||
|
* @param normTimePattern PATTERN
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String format(Date date, String normTimePattern) {
|
||||||
|
SimpleDateFormat zoneFormat = new SimpleDateFormat(normTimePattern);
|
||||||
|
return zoneFormat.format(date);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reference google guava
|
||||||
|
*/
|
||||||
|
public class Joiner {
|
||||||
|
|
||||||
|
private final String separator;
|
||||||
|
|
||||||
|
private Joiner(String separator) {
|
||||||
|
this.separator = Objects.requireNonNull(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a joiner which automatically places {@code separator} between consecutive elements.
|
||||||
|
*/
|
||||||
|
public static Joiner on(String separator) {
|
||||||
|
return new Joiner(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string containing the string representation of each of {@code parts}, using the
|
||||||
|
* previously configured separator between each.
|
||||||
|
*/
|
||||||
|
public final String join(Object[] parts) {
|
||||||
|
return join(Arrays.asList(parts));
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String join(Iterable<?> parts) {
|
||||||
|
return join(parts.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string containing the string representation of each of {@code parts}, using the
|
||||||
|
* previously configured separator between each.
|
||||||
|
*/
|
||||||
|
public final String join(Iterator<?> parts) {
|
||||||
|
return appendTo(new StringBuilder(), parts).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final StringBuilder appendTo(StringBuilder builder, Iterator<?> parts) {
|
||||||
|
try {
|
||||||
|
appendTo((Appendable) builder, parts);
|
||||||
|
} catch (IOException impossible) {
|
||||||
|
throw new AssertionError(impossible);
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException {
|
||||||
|
Objects.requireNonNull(appendable);
|
||||||
|
if (parts.hasNext()) {
|
||||||
|
appendable.append(toString(parts.next()));
|
||||||
|
while (parts.hasNext()) {
|
||||||
|
appendable.append(separator);
|
||||||
|
appendable.append(toString(parts.next()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return appendable;
|
||||||
|
}
|
||||||
|
|
||||||
|
CharSequence toString(Object part) {
|
||||||
|
Objects.requireNonNull(part);
|
||||||
|
return (part instanceof CharSequence) ? (CharSequence) part : part.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.hippo4j.common.web.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic exception to handle illegal operations
|
||||||
|
*/
|
||||||
|
public class IllegalException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 8247610319171014183L;
|
||||||
|
|
||||||
|
public IllegalException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IllegalException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IllegalException(Throwable e) {
|
||||||
|
super(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IllegalException(String message, Throwable throwable) {
|
||||||
|
super(message, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IllegalException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, throwable, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class IdUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void randomUUIDTest() {
|
||||||
|
String randomUUID = IdUtil.randomUUID();
|
||||||
|
Assert.assertNotNull(randomUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleUUIDTest() {
|
||||||
|
String simpleUUID = IdUtil.simpleUUID();
|
||||||
|
Assert.assertNotNull(simpleUUID);
|
||||||
|
Assert.assertFalse(simpleUUID.contains("-"));
|
||||||
|
}
|
||||||
|
}
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 cn.hippo4j.config.toolkit;
|
|
||||||
|
|
||||||
import com.github.dozermapper.core.DozerBeanMapperBuilder;
|
|
||||||
import com.github.dozermapper.core.Mapper;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bean util.
|
|
||||||
*/
|
|
||||||
public class BeanUtil {
|
|
||||||
|
|
||||||
private BeanUtil() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Mapper BEAN_MAPPER_BUILDER;
|
|
||||||
|
|
||||||
static {
|
|
||||||
BEAN_MAPPER_BUILDER = DozerBeanMapperBuilder.buildDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, S> T convert(S source, Class<T> clazz) {
|
|
||||||
return Optional.ofNullable(source)
|
|
||||||
.map(each -> BEAN_MAPPER_BUILDER.map(each, clazz))
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, S> List<T> convert(List<S> sources, Class<T> clazz) {
|
|
||||||
return Optional.ofNullable(sources)
|
|
||||||
.map(each -> {
|
|
||||||
List<T> targetList = new ArrayList<T>(each.size());
|
|
||||||
each.stream()
|
|
||||||
.forEach(item -> targetList.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
|
|
||||||
return targetList;
|
|
||||||
})
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, S> Set<T> convert(Set<S> sources, Class<T> clazz) {
|
|
||||||
return Optional.ofNullable(sources)
|
|
||||||
.map(each -> {
|
|
||||||
Set<T> targetSize = new HashSet<T>(each.size());
|
|
||||||
each.stream()
|
|
||||||
.forEach(item -> targetSize.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
|
|
||||||
return targetSize;
|
|
||||||
})
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue