Skip to content

Commit

Permalink
优化代码完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfuhai committed Oct 20, 2017
1 parent cc10670 commit d0bcf4e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 21 deletions.
100 changes: 79 additions & 21 deletions src/main/java/io/jboot/Jboot.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ public void start() {

JbootAppListenerManager.me().onJbootStarted();

tryToHoldApplication();
// tryToHoldApplication();
}

private void tryToHoldApplication() {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// private void tryToHoldApplication() {
// try {
// Thread.sleep(Long.MAX_VALUE);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }


private boolean startServer() {
Expand Down Expand Up @@ -235,6 +235,17 @@ private void printServerUrl() {
System.out.println("\nserver started success , url : " + url);
}

private static String getRootClassPath() {
String path = null;
try {
path = Jboot.class.getClassLoader().getResource("").toURI().getPath();
return new File(path).getAbsolutePath();
} catch (URISyntaxException e) {
e.printStackTrace();
}
return path;
}


///////////get component methods///////////

Expand Down Expand Up @@ -325,6 +336,11 @@ public JbootRedis getRedis() {
}


/**
* 获取本地server 例如,undertow
*
* @return
*/
public JbootServer getServer() {
return jbootServer;
}
Expand Down Expand Up @@ -366,40 +382,93 @@ public static <T> T config(Class<T> clazz) {

private JbootrpcConfig rpcConfig;

/**
* 获取 RPC服务
*
* @param clazz
* @param <T>
* @return
*/
public static <T> T service(Class<T> clazz) {
if (jboot.rpcConfig == null) {
jboot.rpcConfig = config(JbootrpcConfig.class);
}
return service(clazz, jboot.rpcConfig.getDefaultGroup(), jboot.rpcConfig.getDefaultVersion());
}

/**
* 获取 RPC 服务
*
* @param clazz
* @param group
* @param version
* @param <T>
* @return
*/
public static <T> T service(Class<T> clazz, String group, String version) {
return me().getRpc().serviceObtain(clazz, group, version);
return jboot.getRpc().serviceObtain(clazz, group, version);
}

/**
* 想本地系统发送一个事件
*
* @param event
*/
public static void sendEvent(JbootEvent event) {
JbootEventManager.me().pulish(event);
}

/**
* 向本地系统发送一个事件
*
* @param action
* @param data
*/
public static void sendEvent(String action, Object data) {
sendEvent(new JbootEvent(action, data));
}


/**
* http get操作
*
* @param url
* @return
*/
public static String httpGet(String url) {
return httpGet(url, null);
}

/**
* http get操作
*
* @param url
* @param params
* @return
*/
public static String httpGet(String url, Map<String, Object> params) {
JbootHttpRequest request = JbootHttpRequest.create(url, params, JbootHttpRequest.METHOD_GET);
JbootHttpResponse response = jboot.getHttp().handle(request);
return response.isError() ? null : response.getContent();
}

/**
* http post 操作
*
* @param url
* @return
*/
public static String httpPost(String url) {
return httpPost(url, null);
}

/**
* Http post 操作
*
* @param url
* @param params post的参数,可以是文件
* @return
*/
public static String httpPost(String url, Map<String, Object> params) {
JbootHttpRequest request = JbootHttpRequest.create(url, params, JbootHttpRequest.METHOD_POST);
JbootHttpResponse response = jboot.getHttp().handle(request);
Expand All @@ -408,7 +477,7 @@ public static String httpPost(String url, Map<String, Object> params) {


/**
* 获取被增强的,可以使用AOP注入的
* 获取被增强的,可以使用AOP注入的实体类
*
* @param clazz
* @param <T>
Expand Down Expand Up @@ -440,17 +509,6 @@ public static <T> T hystrix(String key, HystrixRunnable hystrixRunnable) {
return (T) new JbootHystrixCommand(key, hystrixRunnable).execute();
}

private static String getRootClassPath() {
String path = null;
try {
path = Jboot.class.getClassLoader().getResource("").toURI().getPath();
return new File(path).getAbsolutePath();
} catch (URISyntaxException e) {
e.printStackTrace();
}
return path;
}


/**
* 产品模式:开发、测试、产品
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ private void injectInterceptors(String target) {
return;
}

//获取这个拦截器下的所有拦截器
//如果没有拦截器,直接返回
Interceptor[] interceptors = action.getInterceptors();
if (interceptors == null || interceptors.length == 0) {
return;
}

//如果注入过了,就没必要再次注入
//因为拦截器是在整个系统中是单例的
if (injectFlags.contains(target)) {
return;
}

//对所有拦截器进行注入
for (Interceptor interceptor : interceptors) {
Jboot.injectMembers(interceptor);
}
Expand Down

0 comments on commit d0bcf4e

Please sign in to comment.