清理代码
This commit is contained in:
-10
@@ -1,10 +0,0 @@
|
||||
language: java
|
||||
script:
|
||||
- mvn test
|
||||
- mvn test -Pfunctional-test -Dselenium.driver=firefox
|
||||
env: MAVEN_OPTS="-XX:MaxPermSize=128m"
|
||||
addons:
|
||||
firefox: "26.0"
|
||||
before_install:
|
||||
- "export DISPLAY=:99.0"
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
@@ -1,3 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "init db for production mode"
|
||||
|
||||
mvn antrun:run -Prefresh-db
|
||||
+2
-2
@@ -17,7 +17,7 @@ import org.springside.examples.bootapi.domain.Account;
|
||||
import org.springside.examples.bootapi.repository.AccountDao;
|
||||
import org.springside.modules.utils.Digests;
|
||||
import org.springside.modules.utils.Encodes;
|
||||
import org.springside.modules.utils.Identities;
|
||||
import org.springside.modules.utils.Ids;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
@@ -60,7 +60,7 @@ public class AccountService {
|
||||
throw new RestException("Password wrong", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
String token = Identities.uuid2();
|
||||
String token = Ids.uuid2();
|
||||
loginUsers.put(token, account);
|
||||
counterService.increment("loginUser");
|
||||
return token;
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
#Sat Nov 07 10:12:13 CST 2015
|
||||
0=TestDB(Embedded)|org.h2.Driver|jdbc\:h2\:mem\:testdb|sa
|
||||
webAllowOthers=false
|
||||
webPort=8082
|
||||
webPort=8090
|
||||
webSSL=false
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "start applicaiton in production mode"
|
||||
|
||||
java -Xmx1024m -XX:MaxPermSize=128M -Djava.security.egd=file:/dev/./urandom -jar target/boot-api-5.0.0-SNAPSHOT.war --spring.profiles.active=prod
|
||||
|
||||
#set the server port
|
||||
|
||||
+1
-1
@@ -15,6 +15,6 @@
|
||||
|
||||
<modules>
|
||||
<module>boot-api</module>
|
||||
<module>boot-advanced-api</module>
|
||||
<module>boot-showcase</module>
|
||||
</modules>
|
||||
</project>
|
||||
+1
-1
@@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
public class Identities {
|
||||
public class Ids {
|
||||
|
||||
private static SecureRandom random = new SecureRandom();
|
||||
|
||||
@@ -86,9 +86,7 @@ public class Reflections {
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接调用对象方法, 无视private/protected修饰符.
|
||||
* 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用.
|
||||
* 同时匹配方法名+参数类型,
|
||||
* 直接调用对象方法, 无视private/protected修饰符. 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用. 同时匹配方法名+参数类型,
|
||||
*/
|
||||
public static Object invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes,
|
||||
final Object[] args) {
|
||||
@@ -105,8 +103,7 @@ public class Reflections {
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接调用对象方法, 无视private/protected修饰符,
|
||||
* 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
|
||||
* 直接调用对象方法, 无视private/protected修饰符, 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
|
||||
* 只匹配函数名,如果有多个同名函数调用第一个。
|
||||
*/
|
||||
public static Object invokeMethodByName(final Object obj, final String methodName, final Object[] args) {
|
||||
@@ -130,7 +127,8 @@ public class Reflections {
|
||||
public static Field getAccessibleField(final Object obj, final String fieldName) {
|
||||
Validate.notNull(obj, "object can't be null");
|
||||
Validate.notBlank(fieldName, "fieldName can't be blank");
|
||||
for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {
|
||||
for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass
|
||||
.getSuperclass()) {
|
||||
try {
|
||||
Field field = superClass.getDeclaredField(fieldName);
|
||||
makeAccessible(field);
|
||||
@@ -143,9 +141,7 @@ public class Reflections {
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
||||
* 如向上转型到Object仍无法找到, 返回null.
|
||||
* 匹配函数名+参数类型。
|
||||
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. 如向上转型到Object仍无法找到, 返回null. 匹配函数名+参数类型。
|
||||
*
|
||||
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
|
||||
*/
|
||||
@@ -154,7 +150,8 @@ public class Reflections {
|
||||
Validate.notNull(obj, "object can't be null");
|
||||
Validate.notBlank(methodName, "methodName can't be blank");
|
||||
|
||||
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
|
||||
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType
|
||||
.getSuperclass()) {
|
||||
try {
|
||||
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
|
||||
makeAccessible(method);
|
||||
@@ -167,9 +164,7 @@ public class Reflections {
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
||||
* 如向上转型到Object仍无法找到, 返回null.
|
||||
* 只匹配函数名。
|
||||
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. 如向上转型到Object仍无法找到, 返回null. 只匹配函数名。
|
||||
*
|
||||
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
|
||||
*/
|
||||
@@ -177,7 +172,8 @@ public class Reflections {
|
||||
Validate.notNull(obj, "object can't be null");
|
||||
Validate.notBlank(methodName, "methodName can't be blank");
|
||||
|
||||
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
|
||||
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType
|
||||
.getSuperclass()) {
|
||||
Method[] methods = searchType.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(methodName)) {
|
||||
@@ -203,17 +199,14 @@ public class Reflections {
|
||||
* 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
||||
*/
|
||||
public static void makeAccessible(Field field) {
|
||||
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier
|
||||
.isFinal(field.getModifiers())) && !field.isAccessible()) {
|
||||
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
|
||||
|| Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处
|
||||
* 如无法找到, 返回Object.class.
|
||||
* eg.
|
||||
* public UserDao extends HibernateDao<User>
|
||||
* 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处 如无法找到, 返回Object.class. eg. public UserDao extends HibernateDao<User>
|
||||
*
|
||||
* @param clazz The class to introspect
|
||||
* @return the first generic declaration, or Object.class if cannot be determined
|
||||
@@ -223,8 +216,7 @@ public class Reflections {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过反射, 获得Class定义中声明的父类的泛型参数的类型.
|
||||
* 如无法找到, 返回Object.class.
|
||||
* 通过反射, 获得Class定义中声明的父类的泛型参数的类型. 如无法找到, 返回Object.class.
|
||||
*
|
||||
* 如public UserDao extends HibernateDao<User,Long>
|
||||
*
|
||||
@@ -256,6 +248,9 @@ public class Reflections {
|
||||
return (Class) params[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CGLib处理过后的实体的原类.
|
||||
*/
|
||||
public static Class<?> getUserClass(Object instance) {
|
||||
Validate.notNull(instance, "Instance must not be null");
|
||||
Class clazz = instance.getClass();
|
||||
|
||||
@@ -44,19 +44,31 @@ public class Threads {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y",
|
||||
* 创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y"
|
||||
*
|
||||
* 在用threaddump查看线程时特别有用。 格式如"mythread-%d",使用了Guava的工具类
|
||||
*/
|
||||
public static ThreadFactory buildJobFactory(String nameFormat) {
|
||||
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y"
|
||||
*
|
||||
* 在用threaddump查看线程时特别有用。 格式如"mythread-%d",使用了Guava的工具类
|
||||
*/
|
||||
public static ThreadFactory buildJobFactory(String nameFormat, boolean daemon) {
|
||||
return new ThreadFactoryBuilder().setNameFormat(nameFormat).setDaemon(daemon).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法.
|
||||
*
|
||||
* 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
|
||||
* 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
||||
* 如果仍然超時,則強制退出.
|
||||
* 另对在shutdown时线程本身被调用中断做了处理.
|
||||
*
|
||||
* 如果超时, 则调用shutdownNow,取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
||||
*
|
||||
* 如果仍然超時,則強制退出. 另对在shutdown时线程本身被调用中断做了处理.
|
||||
*/
|
||||
public static void gracefulShutdown(ExecutorService pool, int shutdownTimeout, int shutdownNowTimeout,
|
||||
TimeUnit timeUnit) {
|
||||
@@ -79,7 +91,9 @@ public class Threads {
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接调用shutdownNow的方法, 有timeout控制.取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
||||
* 直接调用shutdownNow的方法, 有timeout控制.
|
||||
*
|
||||
* 取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
||||
*/
|
||||
public static void normalShutdown(ExecutorService pool, int timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
|
||||
@@ -11,9 +11,9 @@ public class IdentitiesTest {
|
||||
|
||||
@Test
|
||||
public void demo() {
|
||||
System.out.println("uuid: " + Identities.uuid());
|
||||
System.out.println("uuid2:" + Identities.uuid2());
|
||||
System.out.println("randomLong: " + Identities.randomLong());
|
||||
System.out.println("randomBase62:" + Identities.randomBase62(7));
|
||||
System.out.println("uuid: " + Ids.uuid());
|
||||
System.out.println("uuid2:" + Ids.uuid2());
|
||||
System.out.println("randomLong: " + Ids.randomLong());
|
||||
System.out.println("randomBase62:" + Ids.randomBase62(7));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user