现在的位置: 首页 > 综合 > 正文

Virgo整合ECF

2012年11月14日 ⁄ 综合 ⁄ 共 7099字 ⁄ 字号 评论关闭

ECF框架是OSGI-RemoteService的声明实现,其依赖Bundle包括:
org.eclipse.ecf
org.eclipse.ecf.osgi.services.distribution
org.eclipse.ecf.osgi.services.remoteserviceadmin
org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy
org.eclipse.core.runtime
org.eclipse.equinox.app
org.eclipse.ecf.identity
org.eclipse.ecf.discovery
org.eclipse.equinox.concurrent
org.eclipse.equinox.preferences
org.eclipse.core.jobs
org.eclipse.equinox.registry
org.eclipse.osgi.services.remoteserviceadmin
org.eclipse.core.contenttype
org.eclipse.ecf.provider.jmdns
org.eclipse.ecf.sharedobject
org.eclipse.ecf.provider
org.eclipse.ecf.remoteservice
org.eclipse.ecf.provider.remoteservice
ECF框架的很多plugin都设计成了延迟加载模式(Bundle-ActivationPolicy: lazy),因此需要首先修改virgo的配置文件($VTS-HOME/lib/org.eclipse.virgo.kernel.launch.properties).将osgi.compatibility.eagerStart.LazyActivation属性设置成true,来确保virgo支持延迟加载机制。

另外所声明服务的bundle(这里为org.chen.test.service)和发布服务的bundle(这里为org.chen.test)也需要声明成延迟加载模式(Bundle-ActivationPolicy: lazy)
一、通过DS方式发布RemoteService
Plan信息如下:

<?xml version="1.0" encoding="UTF-8"?>
<plan name="ecf.plan" version="1.0.0" scoped="false" atomic="true"
        xmlns="http://www.eclipse.org/virgo/schema/plan"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.eclipse.org/virgo/schema/plan
	http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">
	<artifact name="org.eclipse.ecf" type="bundle"/>
	<artifact name="org.eclipse.ecf.osgi.services.distribution" type="bundle"/>
	<artifact name="org.eclipse.ecf.osgi.services.remoteserviceadmin" type="bundle"/>
	<artifact name="org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy" type="bundle"/>
	<artifact name="org.eclipse.core.runtime" type="bundle"/>
	<artifact name="org.eclipse.equinox.app" type="bundle"/>
	<artifact name="org.eclipse.ecf.identity" type="bundle"/>
	<artifact name="org.eclipse.ecf.discovery" type="bundle"/>	
	<artifact name="org.eclipse.equinox.concurrent" type="bundle"/>
	<artifact name="org.eclipse.equinox.preferences" type="bundle"/>
	<artifact name="org.eclipse.core.jobs" type="bundle"/>
	<artifact name="org.eclipse.equinox.registry" type="bundle"/>
	<artifact name="org.eclipse.osgi.services.remoteserviceadmin" type="bundle"/>
	<artifact name="org.eclipse.core.contenttype" type="bundle"/>
	<artifact name="org.eclipse.ecf.provider.jmdns" type="bundle"/>
	<artifact name="org.eclipse.ecf.sharedobject" type="bundle"/>
	<artifact name="org.eclipse.ecf.provider" type="bundle"/>
	<artifact name="org.eclipse.ecf.remoteservice" type="bundle"/>
	<artifact name="org.eclipse.ecf.provider.remoteservice" type="bundle"/>
	<artifact name="org.chen.test.service" type="bundle"/>
	<artifact name="org.chen.test" type="bundle"/>
</plan>

服务发布如下:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" 
	enabled="true" immediate="true" name="hello.ds.host">
   <implementation class="org.chen.test.HelloComponent"/>
   <property name="service.exported.interfaces" type="String" value="*"/>
   <property name="service.exported.configs" type="String" value="ecf.generic.server"/>
   <property name="ecf.exported.containerfactoryargs" type="String" value="ecftcp://localhost:3787/server"/>
   <service>
      <provide interface="org.chen.test.service.IHelloService"/>
   </service>
</scr:component>

二、通过gemini发布、获取服务
在DS发布环境的基础上新增cn.com.gei.krp.remoteservice,该bundle用于发布和获取远程服务。
1.RemoteServiceExporter用于发布远程服务,发布配置如下:

<?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:osgi="http://www.springframework.org/schema/osgi"
   xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd


http://www.springframework.org/schema/osgi

       http://www.springframework.org/schema/osgi/spring-osgi.xsd">
	
	<bean id="helloService" class="org.chen.test.HelloComponent" />
	<osgi:reference id="containerManager" interface="org.eclipse.ecf.core.IContainerManager"/>
	<bean id="helloServiceExporter" class="cn.com.gei.krp.remoteservice.RemoteServiceExporter" init-method="start">
		<property name="containerManager" ref="containerManager"/>
		<!-- 服务接口 -->
		<property name="serviceInterface" value="org.chen.test.service.IHelloService"/>
		<!-- 服务实例 -->
		<property name="serviceImplementation" ref="helloService"/>
		<!-- 服务URL -->
		<property name="serviceHostAddress" value="ecftcp://localhost:3788/server" />
	</bean>
</beans>

2.RemoteServiceImporter用于获取远程服务,配置如下:

<?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:osgi="http://www.springframework.org/schema/osgi"
	xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd


http://www.springframework.org/schema/osgi

       http://www.springframework.org/schema/osgi/spring-osgi.xsd">
	<osgi:reference id="containerManager" interface="org.eclipse.ecf.core.IContainerManager" />
	<bean id="helloServiceImporter"
		class="cn.com.gei.krp.remoteservice.RemoteServiceImporter" init-method="start">
		<property name="containerManager" ref="containerManager" />
		<property name="serviceInterface"
			value="org.chen.test.service.IHelloService" />
		<property name="remoteServiceHostAddress" value="ecftcp://localhost:3788/server" />
	</bean>
	<bean id="helloService" factory-bean="helloServiceImporter" factory-method="getRemoteService" />
	<bean id="consumer" class="proxy.remote.Consumer">
		<property name="service" ref="helloService"></property>
	</bean>
</beans>

Plan信息如下:

<?xml version="1.0" encoding="UTF-8"?>
<plan name="ecf.plan" version="1.0.0" scoped="false" atomic="true"
        xmlns="http://www.eclipse.org/virgo/schema/plan"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.eclipse.org/virgo/schema/plan
		        http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">
	<artifact name="org.eclipse.ecf" type="bundle"></artifact>
	<artifact name="org.eclipse.ecf.osgi.services.distribution" type="bundle"></artifact>
	<artifact name="org.eclipse.ecf.osgi.services.remoteserviceadmin" type="bundle"></artifact>
	<artifact name="org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy" type="bundle"></artifact>
	<artifact name="org.eclipse.core.runtime" type="bundle"/>
	<artifact name="org.eclipse.equinox.app" type="bundle"></artifact>
	<artifact name="org.eclipse.ecf.identity" type="bundle"/>
	<artifact name="org.eclipse.ecf.discovery" type="bundle"/>
	<artifact name="org.eclipse.equinox.concurrent" type="bundle"/>
	<artifact name="org.eclipse.equinox.preferences" type="bundle"/>
	<artifact name="org.eclipse.core.jobs" type="bundle"></artifact>
	<artifact name="org.eclipse.equinox.registry" type="bundle"/>
	<artifact name="org.eclipse.osgi.services.remoteserviceadmin" type="bundle"></artifact>
	<artifact name="org.eclipse.core.contenttype" type="bundle"/>
	<artifact name="org.eclipse.ecf.provider.jmdns" type="bundle"/>
	<artifact name="org.eclipse.ecf.sharedobject" type="bundle"/>
	<artifact name="org.eclipse.ecf.provider" type="bundle"/>
	<artifact name="org.eclipse.ecf.remoteservice" type="bundle"/>
	<artifact name="org.eclipse.ecf.provider.remoteservice" type="bundle"></artifact>
	<artifact name="cn.com.gei.krp.remoteservice" type="bundle"/>
	<artifact name="org.chen.test.service" type="bundle"></artifact>
	<artifact name="org.chen.test" type="bundle"></artifact>
</plan>

抱歉!评论已关闭.