Skip to content

Commit

Permalink
optimize ...
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfuhai committed May 22, 2018
1 parent c02e01c commit 0374371
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-client</artifactId>
<version>6.3.0</version>
<version>6.3.1</version>
<scope>provided</scope>
</dependency>

Expand Down
20 changes: 11 additions & 9 deletions src/main/java/io/jboot/aop/injector/JbootrpcMembersInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,37 @@
public class JbootrpcMembersInjector implements MembersInjector {

private static Log log = Log.getLog(JbootrpcMembersInjector.class);
private static JbootrpcConfig config = Jboot.config(JbootrpcConfig.class);


private Field field;
private static JbootrpcConfig config = Jboot.config(JbootrpcConfig.class);

public JbootrpcMembersInjector(Field field) {
this.field = field;
}

@Override
public void injectMembers(Object instance) {
Object impl = null;
JbootrpcService jbootrpcService = field.getAnnotation(JbootrpcService.class);

String group = StringUtils.isBlank(jbootrpcService.group()) ? config.getDefaultGroup() : jbootrpcService.group();
String version = StringUtils.isBlank(jbootrpcService.version()) ? config.getDefaultVersion() : jbootrpcService.version();

JbootrpcService annotation = field.getAnnotation(JbootrpcService.class);

String group = StringUtils.isBlank(annotation.group()) ? config.getDefaultGroup() : annotation.group();
String version = StringUtils.isBlank(annotation.version()) ? config.getDefaultVersion() : annotation.version();

Object implObject = null;
try {
impl = Jboot.service(field.getType(), group, version);
implObject = Jboot.service(field.getType(), group, version);
} catch (Throwable e) {
log.error(e.toString(), e);
}

if (impl == null) {
if (implObject == null) {
return;
}

try {
field.setAccessible(true);
field.set(instance, impl);
field.set(instance, implObject);
} catch (Throwable e) {
log.error(e.toString(), e);
}
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/io/jboot/web/JbootControllerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -21,9 +21,6 @@
import com.jfinal.core.ControllerFactory;
import io.jboot.Jboot;

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

/**
* @author Michael Yang 杨福海 ([email protected]
* @version V1.0
Expand All @@ -40,20 +37,24 @@ public static JbootControllerManager me() {
private JbootControllerManager() {
}

private ThreadLocal<Map<Class<? extends Controller>, Controller>> buffers = new ThreadLocal<Map<Class<? extends Controller>, Controller>>() {
protected Map<Class<? extends Controller>, Controller> initialValue() {
return new HashMap<Class<? extends Controller>, Controller>();
}
};
// private ThreadLocal<Map<Class<? extends Controller>, Controller>> buffers = new ThreadLocal<Map<Class<? extends Controller>, Controller>>() {
// protected Map<Class<? extends Controller>, Controller> initialValue() {
// return new HashMap<Class<? extends Controller>, Controller>();
// }
// };
//
// public Controller getController(Class<? extends Controller> controllerClass) throws InstantiationException, IllegalAccessException {
// Controller ret = buffers.get().get(controllerClass);
// if (ret == null) {
// ret = controllerClass.newInstance();
// Jboot.injectMembers(ret);
// buffers.get().put(controllerClass, ret);
// }
// return ret;
// }

public Controller getController(Class<? extends Controller> controllerClass) throws InstantiationException, IllegalAccessException {
Controller ret = buffers.get().get(controllerClass);
if (ret == null) {
ret = controllerClass.newInstance();
Jboot.injectMembers(ret);
buffers.get().put(controllerClass, ret);
}
return ret;
return Jboot.bean(controllerClass);
}


Expand Down

0 comments on commit 0374371

Please sign in to comment.