发表于: 2017-11-20 19:00:36
1 627
今日完成:
对于昨天关于rmi的猜想和计划进行了实施,但是不能实现,原因是rmi的bean在项目构建的时候就已经生成,且不可改变,而我是想通过它里面的set方法对url进行设置,而在生成这个bean时url和interface两个属性都要有才能构建rmi,而构建后就已经无法更改url了,然后就屈服了写两个设定的rmi来随机调用,而不是先根据所有ip和port先通过ping来生成可通行路径再生成rmi,目前这种方法只能通过不和spring集成的情况下能生成。
明日计划:
看看任务九,看看任务通不通过。
代码展示:
server,另一个就是registrPorty改一下。
<bean id="RMIServer" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="helloRMI"/>
<property name="service" ref="helloRMIServiceImpl"/>
<property name="serviceInterface" value="com.jnshu.rmi.ServicesDao"/>
<property name="registryPort" value="4568"/>
</bean>
client中rmi的配置
<bean id="myRMIClient1" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" lazy-init="true">
<property name="serviceInterface" value="com.jnshu.rmi.ServicesDao"/>
<property name="serviceUrl" value="rmi://localhost:4567/helloRMI"/>
</bean>
<bean id="myRMIClient2" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" lazy-init="true">
<property name="serviceInterface" value="com.jnshu.rmi.ServicesDao"/>
<property name="serviceUrl" value="rmi://localhost:4568/helloRMI"/>
</bean>
client中端口选择类,先随机选择一个server,然后看是否能通,如果不能通,是无法getbean的。
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
int random=0;
int rmista=0;
while (rmista==0) {
try {
random = new Random().nextInt(2) + 1;
ServicesDao servicesDao=applicationContext.getBean("myRMIClient" + random, ServicesDao.class);
System.out.println("使用"+random+"号server");
rmista=1;
return servicesDao;
}catch (Exception e){System.out.println(random+"号服务类坏了。");}
}
在控制器中这样就能调用了。查看人时直接实例化一个model,不然下次调用又要连接一次就会十分耗时
Person per=PortSelectionRandom.servicesRandom().takeById(searchid)
进度:
任务八提交
任务开始时间:2017.11.16
预计demo时间:2017.11.20
禅道:http://task.ptteng.com/zentao/my-task.htm
demo也许会迟到,但绝不会缺席。
评论