发表于: 2019-10-29 20:35:30

1 1091


今天完成的事情:

今天再看二大发给我的修真院真实项目代码,但是tuscany 看的有点怪怪的,想在网上找个文档之类的,发现很少系统的介绍Tuscany的,更多的资料显示是已经停止维护了,就连demo例子都比较少。头疼。

但项目结构不难,主要是俩个,分为一个server,一个web(即client),中间可能还有别的模块,例如 公共模块(包含的就是类和接口,以及一些通用jar包),还有什么定时任务的模块,前台的模块服务消费等。

里面的代码还好,只是没有dao层实现,取而代之的是dal层实现。

这个是比较奇怪的, 我在网上查资料结合我自己的理解,是dao主要作用于orm框架,例如mybatis等,是一个放orm映射的。

但是dal是对数据库的操作,二者都可以实现对数据库的操作,但是dao还必须要有一个实体类和数据库对应,做一个映射,但是dal直接操作,不需要实体类即可操作数据库,这个是我理解的二者的最大区别。

还有一个比较怪怪的是 tuscany并没有类似于dubbo的注册中心,他只有一个服务,一个消费,然后服务直接调用消费。可以分析一下启动类代码

public static void main(String[] args) throws Exception {
Server server = new Server();
   server.start();
   try {
server.run();
       
   } catch (InterruptedException e) {
log.error("keeper-admin-service server run error ", e);
   }
}

调用一下start方法,然后我们看下start方法

public void start() throws Exception {


log.info("===> keeper-admin-service Start Begin");
 

   node = SCANodeFactory.newInstance().createSCANode("META-INF/server.composite");
   node.start();

 
       log.info("===>keeper-admin-service");
 
}

上面的代码类似于加载配置文件,但是下面又调用了一个start方法,有点迷糊了,点进看看这个start方法是干啥用的,难道是多线程当中的启动吗?

package org.apache.tuscany.sca.node;

public interface SCANode {
void start();

   void stop();
}

是Tuscany 带的一个接口里的方法,晕了,啥注释都没有,完全不知道啥意思,在baidu上也没百度出来,完全找不到文档资料。

继续往下看

还有一个run方法

public void run() throws InterruptedException {
while (true) {
Thread.sleep(Long.MAX_VALUE);
   }
}

这个run方法就有点奇怪了,形成了一个死循环,然后让线程一直睡眠,这里我推断,上面的那个run一定是启动线程,然后执行run方法,但是意义在哪,执行之后一直睡眠,有点不懂。

第二个就是以前我们整合到一个xml文件中的所有操作数据库的语句,现在都被拆分为具体的某一个XML了,某一个表就有一个对应的xml

<?xml version="1.0" encoding="UTF-8"?>
<dal>
   <route>
       <object name="com.ptteng.keeper.admin.model.Article"
               listenerClass="" strategyProperty="">


           <list name="getArticleIdsByStatusAndSourceOrderByPublishat"
                 sqlitem="select id from article where status = ? and source = ? order by publish_at desc"
                 keyProperty="status,source" valueProperty="id" keyColumn="status,source"/>
           <list name="getArticleIdsBySourceOrderByPublishat"
                 sqlitem="select id from article where source=? order by publish_at desc"
                 keyProperty="source" valueProperty="id" keyColumn="source"/>
           <list name="getArticleIdsByTypeAndStatusOrderByPublishatDesc"
                 sqlitem="select id from article where type=? and status =? order by publish_at desc"
                 keyProperty="type,status" valueProperty="id" keyColumn="type,status"/>
           <list name="getArticleIdsByTypeAndStatusOrderByPublishatAscs"
                 sqlitem="select id from article where type=? and status =? order by publish_at asc "
                 keyProperty="type,status" valueProperty="id" keyColumn="type,status"/>


           <list name="getArticleIdsAll" sqlitem="select id from article where 1 = 1 order by create_at desc"
                 keyProperty="version" valueProperty="id" keyColumn="version"/>

           <dbStrategy name="mutiDS"
                       clasz="com.gemantic.dal.route.strategy.DefaultStrategy">
               <pattern value="[0-9]$" group="keeper_admin"/>
           </dbStrategy>

       </object>
   </route>
</dal>

这里面的代码就是类似于以前的 什么方法名,返回值,入参等,以及执行的sql语句。

但是搞不懂文件后面以bak结尾的有什么,代码完全一样,难道是修真院代码生成工具的结果??

这里有俩个配置文件,一个是以xml文件结尾的,看文件名就知道,一定是跟spring有关,生成bean等,另一个是以composite结尾的,这个应该就是tuscany的一部分

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:scallop="http://scallop/xmlns/sca/1.0"
targetNamespace="http://KeeperAdminComponent" xmlns:sample="http://KeeperAdminComponent" name="KeeperAdminComponent">

<component name="KeeperAdminComponent">
<implementation.spring location="META-INF/applicationContext-server.xml"/>
</component>

<service name="articleService" promote="KeeperAdminComponent/articleService">
<interface.java interface="com.ptteng.keeper.admin.service.ArticleService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="ArticleRMIService"/>
</service>


<service name="managerService" promote="KeeperAdminComponent/managerService">
<interface.java interface="com.ptteng.keeper.admin.service.ManagerService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="ManagerRMIService"/>
</service>


<service name="moduleService" promote="KeeperAdminComponent/moduleService">
<interface.java interface="com.ptteng.keeper.admin.service.ModuleService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="ModuleRMIService"/>
</service>

<service name="roleModuleService" promote="KeeperAdminComponent/roleModuleService">
<interface.java interface="com.ptteng.keeper.admin.service.RoleModuleService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="RoleModuleRMIService"/>
</service>


<service name="roleService" promote="KeeperAdminComponent/roleService">
<interface.java interface="com.ptteng.keeper.admin.service.RoleService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="RoleRMIService"/>
</service>

<service name="constantService" promote="KeeperAdminComponent/constantService">
<interface.java interface="com.ptteng.keeper.admin.service.ConstantService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="ConstantRMIService"/>
</service>

<service name="contentsService" promote="KeeperAdminComponent/contentsService">
<interface.java interface="com.ptteng.keeper.admin.service.ContentsService"/>
<scallop:binding.rmi host="localhost" port="11181" serviceName="ContentsRMIService"/>
</service>

</composite>

这个文件的刚开始就是加载我们的 spring xml配置文件,然后我们在main方法里面再加载这个composite文件。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:sca="http://www.springframework.org/schema/sca"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

           http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">

   <context:component-scan base-package="com.ptteng.keeper.admin.service"/>


   <!--<service name="versionService" promote="autoAdminComponent/versionService">-->
   <!--<interface.java interface="com.ptteng.keeper.admin.service.VersionService"/>-->
   <!--<scallop:binding.rmi host="localhost" port="11042" serviceName="VersionRMIService"/>-->
   <!--</service>-->


   <sca:service name="articleService"
                type="com.ptteng.keeper.admin.service.ArticleService" target="articleService"/>

   <bean id="articleService"
         class="com.ptteng.keeper.admin.service.impl.ArticleServiceImpl" parent="baseDaoService">
   </bean>

   <sca:service name="managerService"
                type="com.ptteng.keeper.admin.service.ManagerService" target="managerService"/>
   <bean id="managerService"
         class="com.ptteng.keeper.admin.service.impl.ManagerServiceImpl" parent="baseDaoService">
   </bean>


   <sca:service name="moduleService"
                type="com.ptteng.keeper.admin.service.ModuleService" target="moduleService"/>
   <bean id="moduleService"
         class="com.ptteng.keeper.admin.service.impl.ModuleServiceImpl" parent="baseDaoService">
   </bean>


   <sca:service name="roleModuleService"
                type="com.ptteng.keeper.admin.service.RoleModuleService" target="roleModuleService"/>
   <bean id="roleModuleService"
         class="com.ptteng.keeper.admin.service.impl.RoleModuleServiceImpl" parent="baseDaoService">
   </bean>

   <sca:service name="roleService"
                type="com.ptteng.keeper.admin.service.RoleService" target="roleService"/>
   <bean id="roleService"
         class="com.ptteng.keeper.admin.service.impl.RoleServiceImpl" parent="baseDaoService">
   </bean>


   <sca:service name="constantService"
                type="com.ptteng.keeper.admin.service.ConstantService" target="constantService"/>
   <bean id="constantService"
         class="com.ptteng.keeper.admin.service.impl.ConstantServiceImpl" parent="baseDaoService">
   </bean>

   <sca:service name="contentsService"
                type="com.ptteng.keeper.admin.service.ContentsService" target="contentsService"/>

   <bean id="contentsService"
         class="com.ptteng.keeper.admin.service.impl.ContentsServiceImpl" parent="baseDaoService">

   </bean>

   <!--<sca:service name="versionService"-->
   <!--type="com.ptteng.keeper.admin.service.VersionService" target="versionService"/>-->
   <!--<bean id="versionService"-->
   <!--class="com.ptteng.keeper.admin.service.impl.VersionServiceImpl" parent="baseDaoService">-->
   <!--</bean>-->


   <!--<sca:service name="opinionService"-->
   <!--type="com.ptteng.keeper.admin.service.OpinionService" target="opinionService"/>-->


   <!--<bean id="opinionService"-->
   <!--class="com.ptteng.keeper.admin.service.impl.OpinionServiceImpl" parent="baseDaoService">-->

   <!--</bean>-->


   <bean id="dao" class="com.gemantic.dal.dao.impl.CompositeDaoImpl"/>
   <bean id="baseDaoService"
         class="com.ptteng.common.dao.BaseDaoServiceImpl">
       <property name="dao" ref="dao"/>
   </bean>


   <!-- performance -->
   <aop:aspectj-autoproxy/>
   <bean id="aroundLoggingTime" class="com.gemantic.common.stat.aop.time.AroundTimeConsume"/>
   <aop:config>
       <aop:aspect ref="aroundLoggingTime">
           <aop:pointcut id="publicServiceMethod"
                         expression="execution(* com.ptteng..service.*.*(..)) "/>
           <aop:around method="around" pointcut-ref="publicServiceMethod"/>
       </aop:aspect>
   </aop:config>
</beans>

把bean注入到 sca里面,然后再composite文件中 远程调用

这里应该就是大概思路了。大概看了一下,没有文档,也不知道理解的对不对。



明天计划的事情:

调整心态,继续学习准备。



遇到的问题:

主要是没有文档,直接边看项目边猜,第二个就是代码生成,是通过excel,这个不会用,不知道咋用excel代码生成。


收获:了解了 Tuscany等,但是感觉自己也不了解,文档较少。


返回列表 返回列表
评论

    分享到