diff --git a/.classpath b/.classpath index cb33c4b7..1f1adb3c 100644 --- a/.classpath +++ b/.classpath @@ -10,7 +10,6 @@ - diff --git a/examples/Hazelcast.rar b/JdonAccessory/Hazelcast.rar similarity index 100% rename from examples/Hazelcast.rar rename to JdonAccessory/Hazelcast.rar diff --git a/JdonAccessory/JdonAccessory-Source.rar b/JdonAccessory/JdonAccessory-Source.rar new file mode 100644 index 00000000..7bc85dfe Binary files /dev/null and b/JdonAccessory/JdonAccessory-Source.rar differ diff --git a/JdonAccessory/JdonAccessorySource.zip b/JdonAccessory/JdonAccessorySource.zip deleted file mode 100644 index a0292a43..00000000 Binary files a/JdonAccessory/JdonAccessorySource.zip and /dev/null differ diff --git a/JdonAccessory/jdon-hibernate3x.jar b/JdonAccessory/jdon-hibernate3x.jar index 5d45a738..cf341e7c 100644 Binary files a/JdonAccessory/jdon-hibernate3x.jar and b/JdonAccessory/jdon-hibernate3x.jar differ diff --git a/JdonAccessory/jdon-jdbcTemp.jar b/JdonAccessory/jdon-jdbcTemp.jar new file mode 100644 index 00000000..a5c478cd Binary files /dev/null and b/JdonAccessory/jdon-jdbcTemp.jar differ diff --git a/JdonAccessory/jdon-remote-hessian.jar b/JdonAccessory/jdon-remote-hessian.jar index ff1344a8..d8fab1db 100644 Binary files a/JdonAccessory/jdon-remote-hessian.jar and b/JdonAccessory/jdon-remote-hessian.jar differ diff --git a/JdonAccessory/jdon-struts1x.jar b/JdonAccessory/jdon-struts1x.jar index e2b97444..dccd23d4 100644 Binary files a/JdonAccessory/jdon-struts1x.jar and b/JdonAccessory/jdon-struts1x.jar differ diff --git a/JdonAccessory/jdonAccessory.jar b/JdonAccessory/jdonAccessory.jar index 16bd4982..3399deae 100644 Binary files a/JdonAccessory/jdonAccessory.jar and b/JdonAccessory/jdonAccessory.jar differ diff --git a/dist/jdonFramework.jar b/dist/jdonFramework.jar index 7b718545..c2961b6d 100644 Binary files a/dist/jdonFramework.jar and b/dist/jdonFramework.jar differ diff --git a/examples/Hazelcast/HazelcastProvider.java b/examples/Hazelcast/HazelcastProvider.java deleted file mode 100644 index ec202ea9..00000000 --- a/examples/Hazelcast/HazelcastProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.jdon.components.hazelcast; - -import java.util.Collection; - -import com.hazelcast.core.Hazelcast; -import com.jdon.components.encache.EhcacheConf; -import com.jdon.components.encache.EncacheProvider; -import com.jdon.util.Debug; - -import java.util.Map; - -import net.sf.ehcache.Cache; -import net.sf.ehcache.Element; -/** - * - * @author flyzb - * - */ -public class HazelcastProvider implements com.jdon.controller.cache.Cache { - private final static String module = HazelcastProvider.class.getName(); - private String defaultMap="default"; - - public HazelcastProvider() { - Debug.logVerbose("HazelcastProvider construting", module); - } - - public Object get(Object key) { - Debug.logVerbose("hazelcast get key", module); - Map map = Hazelcast.getMap (defaultMap); - Element e = (Element) map.get(key); - if (e == null) - return null; - return e.getObjectValue(); - } - - - public void put(Object key, Object value) { - Debug.logVerbose("hazelcast put key value", module); - Element element = new Element(key, value); - Map map = Hazelcast.getMap (defaultMap); - map.put(key, element); - } - - - public void remove(Object key) { - Debug.logVerbose("hazelcast remove", module); - Map map = Hazelcast.getMap (defaultMap); - map.remove(key); - } - - - public long size() { - Map map = Hazelcast.getMap (defaultMap); - return map.size(); - } - - - public void clear() { - Map map = Hazelcast.getMap (defaultMap); - map.clear(); - } - - - public boolean contain(Object key) { - Map map = Hazelcast.getMap (defaultMap); - return map.containsKey(key); - } - - - public Collection keySet() { - Map map = Hazelcast.getMap (defaultMap); - return map.keySet(); - } - -} diff --git a/examples/Hazelcast/hazelcast.xml b/examples/Hazelcast/hazelcast.xml deleted file mode 100644 index 3b6b30f3..00000000 --- a/examples/Hazelcast/hazelcast.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - dev - dev-pass - - - 5701 - - - 224.2.2.3 - 54327 - - - 127.0.0.1 - - - - 10.10.1.* - - - - PBEWithMD5AndDES - - thesalt - - thepass - - 19 - - - - RSA/NONE/PKCS1PADDING - - thekeypass - - local - - JKS - - thestorepass - - keystore - - - - 16 - 64 - 60 - - - - 0 - - 0 - - - - 1 - - NONE - - 0 - - 25 - - - hz.ADD_NEW_ENTRY - - - - \ No newline at end of file diff --git a/examples/Hazelcast/hibernate.cfg.xml b/examples/Hazelcast/hibernate.cfg.xml deleted file mode 100644 index a354d5da..00000000 --- a/examples/Hazelcast/hibernate.cfg.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 - com.mysql.jdbc.Driver - root - 111111 - - org.hibernate.dialect.MySQLDialect - - update - true - com.hazelcast.hibernate.provider.HazelcastCacheProvider - true - true - true - - - - \ No newline at end of file diff --git "a/examples/Hazelcast/\271\330\323\332Hazelcast\265\304JF\270\374\270\304.txt" "b/examples/Hazelcast/\271\330\323\332Hazelcast\265\304JF\270\374\270\304.txt" deleted file mode 100644 index f9469703..00000000 --- "a/examples/Hazelcast/\271\330\323\332Hazelcast\265\304JF\270\374\270\304.txt" +++ /dev/null @@ -1,19 +0,0 @@ -1.下载hazelcast-1.9.2.jar和hazelcast-hibernate-1.9.2.jar。 - -2.增加新类HazelcastProvider。 - -3.更改CacheableWrapper,如下: -public class CacheableWrapper implements java.io.Serializable - -4。在container.xml中增加: - - -5.增加文件hazelcast.xml - -6.另外web工程中的hibernate.cfg.xml需要更改如下(基于hibernate3.2): -com.hazelcast.hibernate.provider.HazelcastCacheProvider -true - -更多问题讨论: -http://www.jdon.com/jivejdon/thread/39870 - diff --git a/examples/tesWeb/.classpath b/examples/tesWeb/.classpath index 3ebe119f..6f959d39 100644 --- a/examples/tesWeb/.classpath +++ b/examples/tesWeb/.classpath @@ -3,15 +3,16 @@ - - - - - - - - - - + + + + + + + + + + + diff --git a/examples/tesWeb/build.xml b/examples/tesWeb/build.xml index 3e9fd7c7..385ecdc6 100644 --- a/examples/tesWeb/build.xml +++ b/examples/tesWeb/build.xml @@ -1,9 +1,7 @@ + - @@ -28,6 +26,7 @@ + diff --git a/examples/tesWeb/myweb.war b/examples/tesWeb/myweb.war index 12d40653..04533f19 100644 Binary files a/examples/tesWeb/myweb.war and b/examples/tesWeb/myweb.war differ diff --git a/examples/tesWeb/myweb/WEB-INF/classes/sample/MyServlet.class b/examples/tesWeb/myweb/WEB-INF/classes/sample/MyServlet.class index f531aaa9..369fde84 100644 Binary files a/examples/tesWeb/myweb/WEB-INF/classes/sample/MyServlet.class and b/examples/tesWeb/myweb/WEB-INF/classes/sample/MyServlet.class differ diff --git a/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/PublisherRole.class b/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/PublisherRole.class new file mode 100644 index 00000000..3cbcdc19 Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/PublisherRole.class differ diff --git a/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/PublisherRoleImp.class b/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/PublisherRoleImp.class new file mode 100644 index 00000000..abecf9e9 Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/PublisherRoleImp.class differ diff --git a/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/UserRepositoryInMEM.class b/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/UserRepositoryInMEM.class index 693c9859..daa76431 100644 Binary files a/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/UserRepositoryInMEM.class and b/examples/tesWeb/myweb/WEB-INF/classes/sample/repository/UserRepositoryInMEM.class differ diff --git a/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloService.class b/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloService.class index a12015ce..89f3df9b 100644 Binary files a/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloService.class and b/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloService.class differ diff --git a/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloServiceImpl.class b/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloServiceImpl.class index efaaa205..86f125bd 100644 Binary files a/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloServiceImpl.class and b/examples/tesWeb/myweb/WEB-INF/classes/sample/service/HelloServiceImpl.class differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/aopalliance-1.0.jar b/examples/tesWeb/myweb/WEB-INF/lib/aopalliance-1.0.jar new file mode 100644 index 00000000..578b1a0c Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/aopalliance-1.0.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/cglib.jar b/examples/tesWeb/myweb/WEB-INF/lib/cglib.jar new file mode 100644 index 00000000..4dcf2d2d Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/cglib.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/commons-pool-1.5.1.jar b/examples/tesWeb/myweb/WEB-INF/lib/commons-pool-1.5.1.jar new file mode 100644 index 00000000..c3ff84cf Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/commons-pool-1.5.1.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/disruptor-2.0.2.jar b/examples/tesWeb/myweb/WEB-INF/lib/disruptor-2.0.2.jar new file mode 100644 index 00000000..29729ec8 Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/disruptor-2.0.2.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/ehcache-1.6.2.jar b/examples/tesWeb/myweb/WEB-INF/lib/ehcache-1.6.2.jar new file mode 100644 index 00000000..2ffdbebc Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/ehcache-1.6.2.jar differ diff --git a/dist/hessian-3.1.6.jar b/examples/tesWeb/myweb/WEB-INF/lib/hessian-3.1.6.jar similarity index 100% rename from dist/hessian-3.1.6.jar rename to examples/tesWeb/myweb/WEB-INF/lib/hessian-3.1.6.jar diff --git a/examples/tesWeb/myweb/WEB-INF/lib/jdom.jar b/examples/tesWeb/myweb/WEB-INF/lib/jdom.jar new file mode 100644 index 00000000..288e64cb Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/jdom.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/jdonFramework.jar b/examples/tesWeb/myweb/WEB-INF/lib/jdonFramework.jar new file mode 100644 index 00000000..d8059ee8 Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/jdonFramework.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/log4j.jar b/examples/tesWeb/myweb/WEB-INF/lib/log4j.jar new file mode 100644 index 00000000..c930a6ab Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/log4j.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/picocontainer-1.2.jar b/examples/tesWeb/myweb/WEB-INF/lib/picocontainer-1.2.jar new file mode 100644 index 00000000..794cde3e Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/picocontainer-1.2.jar differ diff --git a/examples/tesWeb/myweb/WEB-INF/lib/scannotation-1.0.2.jar b/examples/tesWeb/myweb/WEB-INF/lib/scannotation-1.0.2.jar new file mode 100644 index 00000000..83f52cca Binary files /dev/null and b/examples/tesWeb/myweb/WEB-INF/lib/scannotation-1.0.2.jar differ diff --git a/examples/tesWeb/myweb/index.jsp b/examples/tesWeb/myweb/index.jsp index 13d0d7b3..a6b37e5a 100644 --- a/examples/tesWeb/myweb/index.jsp +++ b/examples/tesWeb/myweb/index.jsp @@ -11,7 +11,7 @@
enter your name: - +
diff --git a/examples/tesWeb/readme.txt b/examples/tesWeb/readme.txt index 066e6491..b5e27925 100644 --- a/examples/tesWeb/readme.txt +++ b/examples/tesWeb/readme.txt @@ -2,7 +2,6 @@ this sample show how simply developing javaEE program by jdonfamework. 1. only need two annotations: -@Poolable @Service(name="helloService") public class HelloServiceImpl implements HelloService .. @@ -17,9 +16,6 @@ HelloService helloService = (HelloService) WebAppUtil.getService("helloService", String result = helloService.hello(myname); -Using ant compiling this project. - -deploy jdonremote.war to your server,such as tomcat: copy the file to tomcat/webapp http://localhost:8080/myweb/ diff --git a/examples/tesWeb/readme_cn.txt b/examples/tesWeb/readme_cn.txt deleted file mode 100644 index e9c57c1c..00000000 --- a/examples/tesWeb/readme_cn.txt +++ /dev/null @@ -1,12 +0,0 @@ -how to Debug: -使用eclipse调试jdonframework的tesweb: - -http://www.jdon.com/jivejdon/thread/38583 - -1、下载jdonframwork的源码包和jboss6的源码包 -2、配置jboss6的Jdonframework环境,参见详细文档http://www.jdon.com/jivejdon/thread/38522 -3、打开eclipse,将jdonframwork的tesweb示例导入进项目 -4、配置tesweb项目,是项目可以编译成功,编辑tesweb的引用库,确保库路径正确,打开build.xml文件,将文件中的项取消,如果不取消则每次编译之后都会将bin目录删除,从而导致源文件找不到对应的class文件而出错,使用ant编译build.xml,确定项目能够成功编译 -5、配置启用jboss6的远程调试选项,jboss6的启用远程调试设置在run.conf.bat批处理文件中,将rem set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"项的rem去掉,将suspend=n改为suspend=y,保存,启动jboss。此时jboss会在Listening for transport dt_socket at address: 8787处停止,等待eclipse调试连接 -6、设置eclipse启动调试,debug configration-》remote Java application-》双击-》设置name:webtest,connection type:standard(socket attach), host:localhost,port: 8787 -allow termination of remote vm:ture.启动调试,等待jboss启动完毕,即可在线条是jboss程序 \ No newline at end of file diff --git a/examples/tesWeb/src/sample/MyServlet.java b/examples/tesWeb/src/sample/MyServlet.java index 340c38af..c49e2f57 100644 --- a/examples/tesWeb/src/sample/MyServlet.java +++ b/examples/tesWeb/src/sample/MyServlet.java @@ -7,6 +7,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import sample.domain.User; import sample.service.HelloService; import com.jdon.controller.WebAppUtil; @@ -19,10 +20,14 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws String myname = req.getParameter("myname"); System.out.println("doGet active :" + myname); HelloService helloService = (HelloService) WebAppUtil.getService("helloService", req); - String result = helloService.hello(myname); + User user = new User(); + user.setName(myname); + user.setUserId("999"); + helloService.save(user); + + String result = helloService.hello("999"); resp.getWriter().print("server say hello to:" + result); resp.getWriter().close(); } - } diff --git a/examples/tesWeb/src/sample/repository/PublisherRole.java b/examples/tesWeb/src/sample/repository/PublisherRole.java new file mode 100644 index 00000000..1088c212 --- /dev/null +++ b/examples/tesWeb/src/sample/repository/PublisherRole.java @@ -0,0 +1,26 @@ +/* + * Copyright 2003-2009 the original author or authors. + * Licensed 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 sample.repository; + +import sample.domain.User; + +import com.jdon.domain.message.DomainMessage; + +public interface PublisherRole { + + public abstract DomainMessage remember(User user); + +} \ No newline at end of file diff --git a/examples/tesWeb/src/sample/repository/PublisherRoleImp.java b/examples/tesWeb/src/sample/repository/PublisherRoleImp.java new file mode 100644 index 00000000..faf6fc52 --- /dev/null +++ b/examples/tesWeb/src/sample/repository/PublisherRoleImp.java @@ -0,0 +1,36 @@ +package sample.repository; +import sample.domain.User; + +import com.jdon.annotation.Introduce; +import com.jdon.annotation.model.Send; +import com.jdon.domain.message.DomainMessage; + +/* + * Copyright 2003-2009 the original author or authors. + * Licensed 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. + * + */ + +@Introduce("message") +public class PublisherRoleImp implements PublisherRole { + + /* (non-Javadoc) + * @see sample.repository.RepositoryPublisherRole#remember(sample.domain.User) + */ + @Override + @Send("saveUser") + public DomainMessage remember(User user) { + return new DomainMessage(user); + } + +} diff --git a/examples/tesWeb/src/sample/repository/UserRepositoryInMEM.java b/examples/tesWeb/src/sample/repository/UserRepositoryInMEM.java index d284ee98..ab8c1050 100644 --- a/examples/tesWeb/src/sample/repository/UserRepositoryInMEM.java +++ b/examples/tesWeb/src/sample/repository/UserRepositoryInMEM.java @@ -6,6 +6,7 @@ import com.jdon.annotation.Component; import com.jdon.annotation.Introduce; +import com.jdon.annotation.model.OnEvent; import com.jdon.annotation.pointcut.Around; @Component @@ -14,18 +15,12 @@ public class UserRepositoryInMEM implements UserRepository { private final HashMap memDB = new HashMap(); - public UserRepositoryInMEM() { - User user = new User(); - user.setName("Client"); - user.setUserId("999"); - memDB.put(user.getUserId(), user); - } - @Around public User findUser(String id) { return memDB.get(id); } + @OnEvent("saveUser") public void save(User user) { memDB.put(user.getUserId(), user); diff --git a/examples/tesWeb/src/sample/service/HelloService.java b/examples/tesWeb/src/sample/service/HelloService.java index 50df0d02..211445c9 100644 --- a/examples/tesWeb/src/sample/service/HelloService.java +++ b/examples/tesWeb/src/sample/service/HelloService.java @@ -1,6 +1,10 @@ package sample.service; +import sample.domain.User; + public interface HelloService { - String hello(String name); + String hello(String name); + + void save(User user); } diff --git a/examples/tesWeb/src/sample/service/HelloServiceImpl.java b/examples/tesWeb/src/sample/service/HelloServiceImpl.java index aa51425e..187381b1 100644 --- a/examples/tesWeb/src/sample/service/HelloServiceImpl.java +++ b/examples/tesWeb/src/sample/service/HelloServiceImpl.java @@ -1,19 +1,29 @@ package sample.service; import sample.domain.User; +import sample.repository.PublisherRole; +import sample.repository.PublisherRoleImp; import sample.repository.UserRepository; import com.jdon.annotation.Service; import com.jdon.annotation.Singleton; +import com.jdon.domain.dci.RoleAssigner; @Singleton @Service("helloService") public class HelloServiceImpl implements HelloService { private UserRepository userRepository; - private User singletonuser;//test @Singleton + private RoleAssigner roleAssigner; - public HelloServiceImpl(UserRepository userRepository) { + public HelloServiceImpl(UserRepository userRepository, RoleAssigner roleAssigner) { this.userRepository = userRepository; + this.roleAssigner = roleAssigner; + } + + public void save(User user) { + PublisherRole publisher = (PublisherRole) roleAssigner.assign(user, new PublisherRoleImp()); + publisher.remember(user); + } public String hello(String name) { @@ -22,13 +32,4 @@ public String hello(String name) { return "Hello, " + user.getName(); } - public String helloSingleton(String name) { - if (singletonuser == null) { - System.out.print("only init one times"); - singletonuser = userRepository.findUser(name); - } - System.out.print("call ok"); - return "Hello, " + singletonuser.getName(); - } - } diff --git a/lib/hessian-3.1.6.jar b/lib/hessian-3.1.6.jar deleted file mode 100644 index 3e3d7fcc..00000000 Binary files a/lib/hessian-3.1.6.jar and /dev/null differ diff --git a/report/TEST-com.jdon.SampleAppTest.txt b/report/TEST-com.jdon.SampleAppTest.txt index 90de7956..4a85779f 100644 --- a/report/TEST-com.jdon.SampleAppTest.txt +++ b/report/TEST-com.jdon.SampleAppTest.txt @@ -1,5 +1,5 @@ Testsuite: com.jdon.SampleAppTest -Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 13.525 sec +Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 13.44 sec ------------- Standard Output --------------- call A.myMethod1 @@ -53,33 +53,32 @@ MyDomainEventHandler action hello MessageListener=hello Synchronous sayHelloAsynchronous eventMessage=100 Synchronous sayHello and Asynchronous eventMessage=100Asynchronous eventMessage=100 -Asynchronous eventMessage=100No.1 @OnEvent: save dbnew name -------------- ---------------- --------------- +Asynchronous eventMessage=100------------- ---------------- --------------- ------------- Standard Error ----------------- -2011-9-19 21:18:36 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict +2011-9-26 9:46:43 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict 警告: Creating a new instance of CacheManager using the diskStorePath "C:\Users\ADMINI~1\AppData\Local\Temp\" which is already used by an existing CacheManager. -The source of the configuration was InputStream java.io.BufferedInputStream@1a68ef9. -The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1316438316690. +The source of the configuration was InputStream java.io.BufferedInputStream@fefe3f. +The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1317001603765. To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance. -2011-9-19 21:18:39 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict +2011-9-26 9:46:46 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict 警告: Creating a new instance of CacheManager using the diskStorePath "C:\Users\ADMINI~1\AppData\Local\Temp\" which is already used by an existing CacheManager. -The source of the configuration was InputStream java.io.BufferedInputStream@5bb966. -The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1316438319123. +The source of the configuration was InputStream java.io.BufferedInputStream@1f2cea2. +The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1317001606204. To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance. -2011-9-19 21:18:41 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict +2011-9-26 9:46:48 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict 警告: Creating a new instance of CacheManager using the diskStorePath "C:\Users\ADMINI~1\AppData\Local\Temp\" which is already used by an existing CacheManager. -The source of the configuration was InputStream java.io.BufferedInputStream@70be88. -The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1316438321588. +The source of the configuration was InputStream java.io.BufferedInputStream@31f2a7. +The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1317001608627. To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance. -2011-9-19 21:18:43 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict +2011-9-26 9:46:51 net.sf.ehcache.CacheManager detectAndFixDiskStorePathConflict 警告: Creating a new instance of CacheManager using the diskStorePath "C:\Users\ADMINI~1\AppData\Local\Temp\" which is already used by an existing CacheManager. -The source of the configuration was InputStream java.io.BufferedInputStream@1cebc9f. -The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1316438323928. +The source of the configuration was InputStream java.io.BufferedInputStream@147358f. +The diskStore path for this CacheManager will be set to C:\Users\ADMINI~1\AppData\Local\Temp\\ehcache_auto_created_1317001611054. To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance. ------------- ---------------- --------------- -Testcase: testGetService took 3.525 sec -Testcase: testDomainEvent took 2.683 sec -Testcase: testDomainEventSimple took 2.496 sec -Testcase: testDCIDomainEvent took 2.34 sec -Testcase: testOnEvent took 2.465 sec +Testcase: testGetService took 3.578 sec +Testcase: testDomainEvent took 2.579 sec +Testcase: testDomainEventSimple took 2.436 sec +Testcase: testDCIDomainEvent took 2.325 sec +Testcase: testOnEvent took 2.511 sec diff --git a/report/TEST-com.jdon.container.ContainerDirectorTest.txt b/report/TEST-com.jdon.container.ContainerDirectorTest.txt index 6b294839..136f0790 100644 --- a/report/TEST-com.jdon.container.ContainerDirectorTest.txt +++ b/report/TEST-com.jdon.container.ContainerDirectorTest.txt @@ -1,4 +1,4 @@ Testsuite: com.jdon.container.ContainerDirectorTest -Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 2.449 sec +Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 2.457 sec -Testcase: testStartup took 2.449 sec +Testcase: testStartup took 2.453 sec diff --git a/report/TEST-com.jdon.container.config.ContainerComponentsXmlLoaderTest.txt b/report/TEST-com.jdon.container.config.ContainerComponentsXmlLoaderTest.txt index 72b1ace9..f615745c 100644 --- a/report/TEST-com.jdon.container.config.ContainerComponentsXmlLoaderTest.txt +++ b/report/TEST-com.jdon.container.config.ContainerComponentsXmlLoaderTest.txt @@ -1,4 +1,4 @@ Testsuite: com.jdon.container.config.ContainerComponentsXmlLoaderTest -Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.109 sec +Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.127 sec -Testcase: testLoad took 0.109 sec +Testcase: testLoad took 0.119 sec diff --git a/src/com/jdon/SampleAppTest.java b/src/com/jdon/SampleAppTest.java index eba8d1a0..612dffb4 100644 --- a/src/com/jdon/SampleAppTest.java +++ b/src/com/jdon/SampleAppTest.java @@ -21,7 +21,6 @@ import com.jdon.container.startup.ContainerSetupScript; import com.jdon.controller.AppUtil; import com.jdon.controller.context.application.Application; -import com.jdon.sample.test.BB; import com.jdon.sample.test.component.BInterface; import com.jdon.sample.test.domain.onecase.IServiceSample; import com.jdon.sample.test.domain.simplecase.IServiceSampleTwo; @@ -87,8 +86,10 @@ public static void main(String[] args) { css.prepare("com.jdon.jdonframework.xml", da); AppUtil appUtil = new AppUtil("com.jdon.jdonframework.xml"); - BB bb = (BB) appUtil.getComponentInstance("bb"); - bb.myDo(); + IServiceSampleTwo serviceSample = (IServiceSampleTwo) appUtil.getService("serviceSampleTwo"); + serviceSample.onEventTest(); + Assert.assertTrue(true); + } protected void tearDown() throws Exception { diff --git a/src/com/jdon/annotation/model/Send.java b/src/com/jdon/annotation/model/Send.java index ae0d2eff..63bbd249 100644 --- a/src/com/jdon/annotation/model/Send.java +++ b/src/com/jdon/annotation/model/Send.java @@ -7,9 +7,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -import com.jdon.async.disruptor.EventDisruptor; - - /** * * Domain Model should normal live in memory not in database. so cache in memory @@ -21,50 +18,52 @@ * Domain Model producer /Consumer: * * 1. annotate the producer class with @Model and @Introduce("message") - *@Model - *@Introduce("message") - *public class DomainEvent {} * - * the value "message" of @@Introduce("message") is the om.jdon.domain.message.MessageInterceptor - * configured in aspect.xml + * @Model + * @Introduce("message") public class DomainEvent {} + * + * the value "message" of @@Introduce("message") is the + * om.jdon.domain.message.MessageInterceptor configured in + * aspect.xml + * + * 2. annotate the method with @Send("mytopic") of the + * producer class; * @Send("mytopic") public DomainMessage + * myMethod() { DomainMessage em = new + * DomainMessage(this.name); return em; } + * + * 3. the "mytopic" value in @Send("mytopic") is equals to + * the "mytopic" value in @Consumer("mytopic"); + * + * 4. annotate the consumer class with + * @Consumer("mytopic"); * - * 2. annotate the method with @Send("mytopic") of the producer class; - * * @Send("mytopic") - * public DomainMessage myMethod() { - * DomainMessage em = new DomainMessage(this.name); - * return em; - * } + * 5.there are two kind of consumer * - * 3. the "mytopic" value in @Send("mytopic") is equals to the "mytopic" value - * in @Consumer("mytopic"); + * (1)the consumer class must implements + * com.jdon.domain.message.DomainEventHandler * - * 4. annotate the consumer class with @Consumer("mytopic"); + * @Consumer("mytopic") public class MyDomainEventHandler implements + * DomainEventHandler { * - * 5.there are two kind of consumer + * public void onEvent(EventDisruptor event, boolean + * endOfBatch) throws Exception{..} * - * (1)the consumer class must implements - * com.jdon.domain.message.DomainEventHandler + * } * - * @Consumer("mytopic") - *public class MyDomainEventHandler implements DomainEventHandler { - * - * public void onEvent(EventDisruptor event, boolean endOfBatch) throws Exception{..} - * - *} * + * (2)or the consumer class's method annotated with + * @onEvent("mytopic") * - * (2)or the consumer class's method annotated with @onEvent("mytopic") - * * * - * Topic/queue(1:N or 1:1): + * Topic/queue(1:N or 1:1): * * @Send(topicName) ==> @Consumer(topicName); * * * - * under version 6.3 there is a Older queue(1:1): + * under version 6.3 there is a Older queue(1:1): * * @Send(topicName) ==> @Component(topicName); * diff --git a/src/com/jdon/aop/AopClient.java b/src/com/jdon/aop/AopClient.java index 61dfb2d9..45380bfa 100644 --- a/src/com/jdon/aop/AopClient.java +++ b/src/com/jdon/aop/AopClient.java @@ -83,6 +83,8 @@ public Object invoke() throws Throwable { throw new Exception(ex); } catch (Throwable ex) { throw new Throwable(ex); + } finally { + targetMetaRequestsHolder.clear(); } return result; } @@ -98,8 +100,9 @@ public Object invoke() throws Throwable { */ public Object invoke(TargetMetaRequest targetMetaRequest, Method method, Object[] args) throws Throwable { targetMetaRequestsHolder.setTargetMetaRequest(targetMetaRequest); - Debug.logVerbose("[JdonFramework] enter AOP invoker2 for:" + targetMetaRequest.getTargetMetaDef().getClassName() + " method:" - + method.getName(), module); + Debug.logVerbose( + "[JdonFramework] enter AOP invoker2 for:" + targetMetaRequest.getTargetMetaDef().getClassName() + " method:" + method.getName(), + module); Object result = null; MethodInvocation methodInvocation = null; @@ -113,6 +116,8 @@ public Object invoke(TargetMetaRequest targetMetaRequest, Method method, Object[ throw new Exception(ex); } catch (Throwable ex) { throw new Throwable(ex); + } finally { + targetMetaRequestsHolder.clear(); } return result; diff --git a/src/com/jdon/async/disruptor/DisruptorFactory.java b/src/com/jdon/async/disruptor/DisruptorFactory.java index f7d75e70..ca995375 100644 --- a/src/com/jdon/async/disruptor/DisruptorFactory.java +++ b/src/com/jdon/async/disruptor/DisruptorFactory.java @@ -58,12 +58,8 @@ private DisruptorWizard createDw(int size) { } public DisruptorWizard addEventMessageHandler(String topic, TreeSet handlers) { - - if (handlers.size() == 0) { - Debug.logError("[Jdonframework]no found the class annotated with @Consumer(" + topic + ") ", module); + if (handlers.size() == 0) return null; - } - DisruptorWizard dw = createDw(handlers.size()); EventHandlerGroup eh = null; for (DomainEventHandler handler : handlers) { @@ -83,7 +79,11 @@ public EventDisruptor getEventDisruptor(String topic) { handlers = loadEvenHandler(topic); handlers = loadOnEventConsumers(topic, handlers); if (handlers.size() == 0) { - Debug.logError("[Jdonframework]no found the class annotated with @Consumer(" + topic + ") ", module); + // maybe in @Component(topicName) + Object o = containerWrapper.lookup(topic); + if (o == null) { + Debug.logError("[Jdonframework]no found the class annotated with @Consumer(" + topic + ") ", module); + } return null; } handlesMap.put(topic, handlers); diff --git a/src/com/jdon/container/ContainerWrapper.java b/src/com/jdon/container/ContainerWrapper.java index af6c3e84..06d339d8 100644 --- a/src/com/jdon/container/ContainerWrapper.java +++ b/src/com/jdon/container/ContainerWrapper.java @@ -135,19 +135,4 @@ public interface ContainerWrapper { */ public List getComponentInstancesOfType(Class componentType); - /** - * register a child container - * - * @param name - */ - public void registerChild(String name); - - /** - * get the child container - * - * @param name - * @return container - */ - public ContainerWrapper getChild(String name); - } diff --git a/src/com/jdon/container/access/TargetMetaRequestsHolder.java b/src/com/jdon/container/access/TargetMetaRequestsHolder.java index cd3ff12e..05e90e57 100644 --- a/src/com/jdon/container/access/TargetMetaRequestsHolder.java +++ b/src/com/jdon/container/access/TargetMetaRequestsHolder.java @@ -2,7 +2,7 @@ public class TargetMetaRequestsHolder { - private final static ThreadLocal targetMetaRequests = new ThreadLocal(); + private static ThreadLocal targetMetaRequests = new ThreadLocal(); public TargetMetaRequest getTargetMetaRequest() { return (TargetMetaRequest) targetMetaRequests.get(); @@ -12,4 +12,8 @@ public void setTargetMetaRequest(TargetMetaRequest targetMetaRequest) { targetMetaRequests.set(targetMetaRequest); } + public void clear() { + targetMetaRequests.remove(); + } + } diff --git a/src/com/jdon/container/annotation/type/ConsumerLoader.java b/src/com/jdon/container/annotation/type/ConsumerLoader.java index 16e3c3f6..ac5793a8 100644 --- a/src/com/jdon/container/annotation/type/ConsumerLoader.java +++ b/src/com/jdon/container/annotation/type/ConsumerLoader.java @@ -31,6 +31,7 @@ import com.jdon.controller.context.AppContextWrapper; import com.jdon.domain.message.DomainEventHandler; import com.jdon.domain.message.consumer.ConsumerMethodHolder; +import com.jdon.util.ClassUtil; import com.jdon.util.Debug; import com.jdon.util.UtilValidate; @@ -88,18 +89,31 @@ public void createAnnotationConsumerClass(String className, AnnotationHolder ann */ public void loadMehtodAnnotations(Class cclass, ContainerWrapper containerWrapper) { - for (Method method : cclass.getDeclaredMethods()) { - if (method.isAnnotationPresent(OnEvent.class)) { - OnEvent onEvent = method.getAnnotation(OnEvent.class); - String consumerKey = ConsumerLoader.TOPICNAME2 + onEvent.value(); - Collection consumerMethods = getContainerConsumers(consumerKey, containerWrapper); - String componentname = getConsumerName(cclass); - consumerMethods.add(new ConsumerMethodHolder(componentname, method)); + try { + for (Method method : ClassUtil.getAllDecaredMethods(cclass)) { + if (method.isAnnotationPresent(OnEvent.class)) { + addConsumerMethod(method, cclass, containerWrapper); + } else { + Method mm = ClassUtil.finddAnnotationForMethod(method, OnEvent.class); + if (mm != null) { + addConsumerMethod(mm, cclass, containerWrapper); + } + } } + } catch (Exception e) { + e.printStackTrace(); } } + private void addConsumerMethod(Method method, Class cclass, ContainerWrapper containerWrapper) { + OnEvent onEvent = method.getAnnotation(OnEvent.class); + String consumerKey = ConsumerLoader.TOPICNAME2 + onEvent.value(); + Collection consumerMethods = getContainerConsumers(consumerKey, containerWrapper); + String componentname = getConsumerName(cclass); + consumerMethods.add(new ConsumerMethodHolder(componentname, method)); + } + public Collection getContainerConsumers(String topicKey, ContainerWrapper containerWrapper) { Collection consumers = (Collection) containerWrapper.lookup(topicKey); diff --git a/src/com/jdon/container/builder/DefaultContainerBuilder.java b/src/com/jdon/container/builder/DefaultContainerBuilder.java index 3adf7fcf..487f2f6d 100644 --- a/src/com/jdon/container/builder/DefaultContainerBuilder.java +++ b/src/com/jdon/container/builder/DefaultContainerBuilder.java @@ -137,7 +137,11 @@ public void registerAspectComponents() throws Exception { } /** - * register user services in jdonframework.xml + * register user services/components in jdonframework.xml + * + * AnnotationContainerBuilder will override this method, and register + * annotation services or components. + * */ public void registerUserService() throws Exception { Debug.logVerbose("[JdonFramework] note: registe user pojoservice ", module); diff --git a/src/com/jdon/container/pico/JdonConstructorInjectionComponentAdapter.java b/src/com/jdon/container/pico/JdonConstructorInjectionComponentAdapter.java index f78f30c5..e9499778 100644 --- a/src/com/jdon/container/pico/JdonConstructorInjectionComponentAdapter.java +++ b/src/com/jdon/container/pico/JdonConstructorInjectionComponentAdapter.java @@ -61,12 +61,6 @@ private void setArguments(PicoContainer container) { this.guardedContainer = container; } - public void clearGuardedContainer() { - if (guardedContainer != null) - guardedContainer.stop(); - guardedContainer = null; - - } } private ConfigInfo configInfo; @@ -133,7 +127,10 @@ public Object run() { }; } instantiationGuard.setArguments(container); - return instantiationGuard.observe(getComponentImplementation()); + Object result = instantiationGuard.observe(getComponentImplementation()); + instantiationGuard.clear(); + return result; + } // overide InstantiatingComponentAdapter 's newInstance @@ -170,12 +167,7 @@ public void clear() { super.clear(); if (instantiationGuard != null) { instantiationGuard.clear(); - instantiationGuard.clearGuardedContainer(); } - instantiationGuard = null; - - if (sortedMatchingConstructors != null) - sortedMatchingConstructors.clear(); } diff --git a/src/com/jdon/container/pico/JdonInstantiatingComponentAdapter.java b/src/com/jdon/container/pico/JdonInstantiatingComponentAdapter.java index 0887d084..567d5747 100644 --- a/src/com/jdon/container/pico/JdonInstantiatingComponentAdapter.java +++ b/src/com/jdon/container/pico/JdonInstantiatingComponentAdapter.java @@ -241,9 +241,7 @@ protected JdonInstantiatingComponentAdapter(Object componentKey, Class component public void clear() { if (verifyingGuard != null) { verifyingGuard.clear(); - verifyingGuard.clearGuardedContainer(); } - verifyingGuard = null; } } diff --git a/src/com/jdon/container/pico/JdonPicoContainer.java b/src/com/jdon/container/pico/JdonPicoContainer.java index 53a087e7..85b02b69 100644 --- a/src/com/jdon/container/pico/JdonPicoContainer.java +++ b/src/com/jdon/container/pico/JdonPicoContainer.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; import org.picocontainer.ComponentAdapter; import org.picocontainer.ComponentMonitor; @@ -65,27 +67,27 @@ public class JdonPicoContainer implements MutablePicoContainer, ComponentMonitor public final static String module = JdonPicoContainer.class.getName(); - private final Map componentKeyToAdapterCache = new HashMap(); + private final Map componentKeyToAdapterCache = new ConcurrentHashMap(); - private final Map componentKeyToInstanceCache = new HashMap(); + private final Map componentKeyToInstanceCache = new ConcurrentHashMap(); - private ComponentAdapterFactory componentAdapterFactory; - private PicoContainer parent; - private final List componentAdapters = new ArrayList(); + private final List componentAdapters = new CopyOnWriteArrayList(); // Keeps track of instantiation order. - private final List orderedComponentAdapters = new ArrayList(); + private final List orderedComponentAdapters = new CopyOnWriteArrayList(); private LifecycleManager lifecycleManager = new OrderedComponentAdapterLifecycleManager(); - private boolean started = false; - private boolean disposed = false; - private final HashSet children = new HashSet(); // Keeps track of child containers started status private Set childrenStarted = new HashSet(); + private ComponentAdapterFactory componentAdapterFactory; + private PicoContainer parent; + private boolean started = false; + private boolean disposed = false; + /** * Creates a new container with a custom ComponentAdapterFactory and a * parent container. @@ -448,15 +450,6 @@ public void stop() { } this.lifecycleManager.stop(this); started = false; - for (Object p : componentAdapters) { - if (p instanceof JdonConstructorInjectionComponentAdapter) { - JdonConstructorInjectionComponentAdapter c = (JdonConstructorInjectionComponentAdapter) p; - c.clear(); - } else if (p instanceof InstanceComponentAdapter) { - InstanceComponentAdapter c = (InstanceComponentAdapter) p; - c.stop(this); - } - } componentKeyToAdapterCache.clear(); componentKeyToInstanceCache.clear(); componentAdapters.clear(); @@ -466,6 +459,15 @@ public void stop() { parent = null; } + public void clearGurad() { + for (Object p : this.orderedComponentAdapters) { + if (p instanceof JdonConstructorInjectionComponentAdapter) { + JdonConstructorInjectionComponentAdapter c = (JdonConstructorInjectionComponentAdapter) p; + c.clear(); + } + } + } + private boolean childStarted(PicoContainer child) { return childrenStarted.contains(new Integer(child.hashCode())); } diff --git a/src/com/jdon/container/pico/PicoContainerWrapper.java b/src/com/jdon/container/pico/PicoContainerWrapper.java index d348bb7d..93150d5a 100644 --- a/src/com/jdon/container/pico/PicoContainerWrapper.java +++ b/src/com/jdon/container/pico/PicoContainerWrapper.java @@ -16,14 +16,13 @@ package com.jdon.container.pico; import java.lang.reflect.Constructor; +import java.util.ArrayList; import java.util.List; import java.util.Map; import org.picocontainer.ComponentAdapter; -import org.picocontainer.MutablePicoContainer; import org.picocontainer.Parameter; import org.picocontainer.defaults.ConstantParameter; -import org.picocontainer.defaults.DefaultPicoContainer; import com.jdon.container.ContainerWrapper; import com.jdon.container.finder.ContainerCallback; @@ -39,7 +38,7 @@ public class PicoContainerWrapper implements ContainerWrapper { public final static String module = PicoContainerWrapper.class.getName(); - private MutablePicoContainer container; + private JdonPicoContainer container; private volatile boolean start; @@ -53,39 +52,12 @@ public PicoContainerWrapper(ConfigInfo configInfo) { registerContainerCallback(); } - public PicoContainerWrapper(MutablePicoContainer container) { - this.container = container; - registerContainerCallback(); - } - public synchronized void registerContainerCallback() { ContainerCallback containerCallback = new ContainerCallback(this); register(ContainerCallback.NAME, containerCallback); register(ComponentAdvsior.NAME, new ComponentAdvsior(containerCallback)); } - /** - * registe a child container in parent container - */ - public synchronized void registerChild(String name) { - try { - MutablePicoContainer child = new DefaultPicoContainer(container); - register(name, child); - // todo: bidirector register, so components can find each other - // child.registerComponentInstance(name, container); - } catch (Exception ex) { - Debug.logWarning(" registe error: " + name, module); - } - } - - /** - * get the child container from the parent container - */ - public ContainerWrapper getChild(String name) { - MutablePicoContainer child = (MutablePicoContainer) lookup(name); - return new PicoContainerWrapper(child); - } - public synchronized void register(String name, Class className) { try { Debug.logVerbose("[JdonFramework]register: name=" + name + " class=" + className.getName(), module); @@ -184,8 +156,10 @@ public boolean isStart() { } public synchronized void setStart(boolean start) { - if (start) + if (start) { + this.container.clearGurad(); this.notifyAll(); + } this.start = start; } @@ -254,7 +228,17 @@ public List getComponentInstancesOfType(Class componentType) { Debug.logError("container not start", module); return null; } - return container.getComponentInstancesOfType(componentType); + List result = new ArrayList(); + // not use orignal + // Map orignals = (Map) lookup(ContainerWrapper.OrignalKey); + // if (orignals != null) + // for (Object o : orignals.values()) { + // if (componentType.isAssignableFrom(o.getClass())) { + // result.add(o); + // } + // } + result.addAll(container.getComponentInstancesOfType(componentType)); + return result; } } diff --git a/src/com/jdon/domain/advsior/ComponentAdvsior.java b/src/com/jdon/domain/advsior/ComponentAdvsior.java index b7acd3b5..8db95a7f 100644 --- a/src/com/jdon/domain/advsior/ComponentAdvsior.java +++ b/src/com/jdon/domain/advsior/ComponentAdvsior.java @@ -70,7 +70,8 @@ public Object createProxy(Object o) { try { Class[] interfaces = getInterfaces(o.getClass()); if (interfaces == null) { - Debug.logError(" Your injected class:" + o.getClass() + " is a @Component/@Service, so the class must has a interface", module); + Debug.logError(" Your class:" + o.getClass() + + " has a annotation @Introduce, the class need implement a interface when it be register in container", module); return o; } diff --git a/src/com/jdon/domain/message/DomainEventDispatchHandler.java b/src/com/jdon/domain/message/DomainEventDispatchHandler.java index 233d511b..6687ba0a 100644 --- a/src/com/jdon/domain/message/DomainEventDispatchHandler.java +++ b/src/com/jdon/domain/message/DomainEventDispatchHandler.java @@ -73,7 +73,8 @@ public void onEvent(EventDisruptor event, boolean endOfBatch) throws Exception { i++; } Object o = containerWrapper.lookupOriginal(consumerMethodHolder.getClassName()); - method.invoke(o, parameters); + Object eventResult = method.invoke(o, parameters); + event.getDomainMessage().setEventResult(eventResult); } catch (Exception e) { Debug.logError("[Jdonframework]" + consumerMethodHolder.getClassName() + " method with @onEvent error: " + e, module); } diff --git a/src/com/jdon/domain/model/injection/ModelProxyInjection.java b/src/com/jdon/domain/model/injection/ModelProxyInjection.java index 6d892129..bad4f127 100644 --- a/src/com/jdon/domain/model/injection/ModelProxyInjection.java +++ b/src/com/jdon/domain/model/injection/ModelProxyInjection.java @@ -22,8 +22,8 @@ import com.jdon.annotation.Service; import com.jdon.annotation.model.Inject; import com.jdon.container.finder.ContainerCallback; -import com.jdon.domain.advsior.ComponentAdvsior; import com.jdon.domain.advsior.ModelAdvisor; +import com.jdon.util.ClassUtil; import com.jdon.util.Debug; import com.jdon.util.ObjectCreator; @@ -51,21 +51,23 @@ public class ModelProxyInjection { private final static String module = ModelProxyInjection.class.getName(); private final ModelAdvisor modelAdvisor; - private final ComponentAdvsior componentAdvsior; private final ContainerCallback containerCallback; - public ModelProxyInjection(ModelAdvisor modelAdvisor, ComponentAdvsior componentAdvsior, ContainerCallback containerCallback) { + public ModelProxyInjection(ModelAdvisor modelAdvisor, ContainerCallback containerCallback) { super(); this.modelAdvisor = modelAdvisor; - this.componentAdvsior = componentAdvsior; this.containerCallback = containerCallback; } public void injectProperties(Object targetModel) { + Class fClass = null; try { - for (Field field : targetModel.getClass().getDeclaredFields()) { + Field[] fields = ClassUtil.getAllDecaredFields(targetModel.getClass()); + if (fields == null) + return; + for (Field field : fields) { if (field.isAnnotationPresent(Inject.class)) { - Class fClass = field.getType(); + fClass = field.getType(); Object fieldObject = getInjectObject(targetModel, fClass); if (field.getType().isAssignableFrom(fieldObject.getClass())) { try { @@ -83,7 +85,7 @@ public void injectProperties(Object targetModel) { } } catch (Exception e) { - Debug.logError("inject Properties error:" + e + " in" + targetModel.getClass(), module); + Debug.logError("inject Properties error:" + e + " in " + targetModel.getClass() + "'s field: " + fClass, module); } } @@ -111,15 +113,19 @@ protected Object createTargetComponent(Object targetModel, Class fClass) { Object o = null; try { List objects = containerCallback.getContainerWrapper().getComponentInstancesOfType(fClass); + // List should be have only one. for (Object instance : objects) { - if (isComponent(instance)) { - o = instance; - break; - } + // there are two posiible: a component or a proxy, + return instance; + // if (isComponent(instance)) { + // o = instance; + // break; + // } } - if (o != null) - o = componentAdvsior.createProxy(o); + // if (o != null && componentAdvsior.getInterfaces(o.getClass()) != + // null) + // o = componentAdvsior.createProxy(o); } catch (Exception e) { Debug.logError("createTargetComponent error:" + e + " in" + targetModel.getClass(), module); } diff --git a/src/com/jdon/sample/test/dci/RepositoryListener.java b/src/com/jdon/sample/test/dci/RepositoryListener.java index 27244c62..c0f850f9 100644 --- a/src/com/jdon/sample/test/dci/RepositoryListener.java +++ b/src/com/jdon/sample/test/dci/RepositoryListener.java @@ -22,6 +22,6 @@ @Consumer("save") public class RepositoryListener implements DomainEventHandler { public void onEvent(EventDisruptor event, boolean endOfBatch) throws Exception { - System.out.println("No.3 @Consumer:DCI RepositoryListener Action \n"); + System.out.println("\n No.3 @OnEvent:" + this.getClass().getName()); } } diff --git a/src/com/jdon/sample/test/domain/simplecase/repository/MyModelRepository.java b/src/com/jdon/sample/test/domain/simplecase/repository/MyModelRepository.java index 7a43f969..eaf8c791 100644 --- a/src/com/jdon/sample/test/domain/simplecase/repository/MyModelRepository.java +++ b/src/com/jdon/sample/test/domain/simplecase/repository/MyModelRepository.java @@ -15,11 +15,13 @@ */ package com.jdon.sample.test.domain.simplecase.repository; +import com.jdon.annotation.model.OnEvent; import com.jdon.sample.test.domain.simplecase.MyModel; public interface MyModelRepository { public MyModel getModel(Long key); + @OnEvent("save") public void save(MyModel myModel); } diff --git a/src/com/jdon/sample/test/domain/simplecase/repository/TestA.java b/src/com/jdon/sample/test/domain/simplecase/repository/RepositoryA.java similarity index 87% rename from src/com/jdon/sample/test/domain/simplecase/repository/TestA.java rename to src/com/jdon/sample/test/domain/simplecase/repository/RepositoryA.java index e7882860..76acef34 100644 --- a/src/com/jdon/sample/test/domain/simplecase/repository/TestA.java +++ b/src/com/jdon/sample/test/domain/simplecase/repository/RepositoryA.java @@ -20,11 +20,11 @@ import com.jdon.sample.test.domain.simplecase.MyModel; @Component -public class TestA { +public class RepositoryA { @OnEvent("save") public void todo(MyModel myModel) { - System.out.print("No.2 @OnEvent:TestA ." + myModel.getName() + "\n"); + System.out.print("\n No.2 @OnEvent:" + this.getClass().getName()); } } diff --git a/src/com/jdon/sample/test/domain/simplecase/repository/RepositoryImp.java b/src/com/jdon/sample/test/domain/simplecase/repository/RepositoryImp.java index 688aa811..3c865232 100644 --- a/src/com/jdon/sample/test/domain/simplecase/repository/RepositoryImp.java +++ b/src/com/jdon/sample/test/domain/simplecase/repository/RepositoryImp.java @@ -17,7 +17,6 @@ import com.jdon.annotation.Component; import com.jdon.annotation.Introduce; -import com.jdon.annotation.model.OnEvent; import com.jdon.annotation.pointcut.Around; import com.jdon.sample.test.domain.simplecase.MyModel; @@ -32,9 +31,8 @@ public MyModel getModel(Long key) { return mym; } - @OnEvent("save") public void save(MyModel myModel) { - System.out.print("No.1 @OnEvent: save db" + myModel.getName() + "\n"); + System.out.print("\n No.1 @OnEvent:" + this.getClass().getName()); } diff --git a/src/com/jdon/util/ClassUtil.java b/src/com/jdon/util/ClassUtil.java index bea3bed1..b949ad0e 100644 --- a/src/com/jdon/util/ClassUtil.java +++ b/src/com/jdon/util/ClassUtil.java @@ -16,6 +16,7 @@ package com.jdon.util; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -78,6 +79,76 @@ public static Field[] getAllDecaredFields(Class clazz) { return fields.toArray(new Field[fields.size()]); } + public static Class finddAnnotationForMethod(Class clazz, Class annotationClass) { + Class[] superClasses = getAllSuperclasses(clazz); + if (superClasses != null) + for (Class superClass : superClasses) { + if (superClass.isAnnotationPresent(annotationClass)) { + return superClass; + } + } + + superClasses = getParentAllInterfaces(clazz); + if (superClasses != null) + for (Class superClass : superClasses) { + if (superClass.isAnnotationPresent(annotationClass)) { + return superClass; + } + } + return null; + + } + + public static Method finddAnnotationForMethod(Method m, Class annotationClass) { + try { + Class[] superClasses = getAllSuperclasses(m.getDeclaringClass()); + if (superClasses != null) + for (Class superClass : superClasses) { + for (Method ms : superClass.getDeclaredMethods()) { + if (ms.isAnnotationPresent(annotationClass)) { + if (ms.getName() == m.getName()) { + return ms; + } + } + } + } + + superClasses = getParentAllInterfaces(m.getDeclaringClass()); + if (superClasses != null) + for (Class superClass : superClasses) { + for (Method ms : superClass.getDeclaredMethods()) { + if (ms.isAnnotationPresent(annotationClass)) { + if (ms.getName() == m.getName()) { + return ms; + } + + } + } + } + + } catch (SecurityException e) { + e.printStackTrace(); + } + return null; + + } + + public static Method[] getAllDecaredMethods(Class clazz) { + List methods = new ArrayList(); + // fields.addAll(Arrays.asList(clazz.getDeclaredFields())); + + Class[] superClasses = getAllSuperclasses(clazz); + for (Class superClass : superClasses) { + methods.addAll(Arrays.asList(superClass.getDeclaredMethods())); + } + + // superClasses = getParentAllInterfaces(clazz); + // for (Class superClass : superClasses) { + // methods.addAll(Arrays.asList(superClass.getDeclaredMethods())); + // } + return methods.toArray(new Method[methods.size()]); + } + public static Class[] getAllSuperclasses(Class cls) { if (cls == null) { return new Class[0];