Loong声明式服务使用方法

  使用loong的webconsolebundle-plugin打包项目中的资源文件

<plugin>
		<groupId>org.trustie.loong.modules.loong-webconsole</groupId>
		<artifactId>loong-webconsolebundle-plugin</artifactId>
		<version>1.0.0</version>
		<extensions>true</extensions>
		<configuration>
			<attchFiles>
				plugin.xml,
				resources
			</attchFiles>
		</configuration>
</plugin>
 

 

Loong声明式服务使用

 

先定义一个metadata.xml文件

 

<?xml version="1.0" encoding="utf-8"?>
<DService>
	<!-- tree -->
	<component name="TreeNodeProvider" structure="true" immediate="false"
		classname="com.cvicse.inforguard.utmp.analysis.storage.business.impl.TreeNodeImpl">
		<service />
		<lifecycle valid="starting" invalid="stopping" />
		<reference field="m_baseDao" />
		<reference field="m_machineRoomDao" />
		<reference field="m_mibSrv" />
	</component>

	<!-- create instance -->
	<instance component="TreeNodeProvider" name="TreeNodeProviderInstance" />
</DService>

 这样声明了一个叫TreeNodeProvider的服务。服务要有一个接口。服务中引用的其他服务使用reference来表示 field后面直接家类属性。其中该属性定义的是接口类型。例如referenc 中m_baseDao。其类型为IBaseDao

 

其中lifecycle 中starting 和invalid 定义的是该服务被初始化后执行valid 后面定义的starting()方法。服务被停止执行invalid后面定义的stopping()方法

 

public class TreeNodeImpl implements ITreeNode {
	/**
	 * Dao对象
	 */
	private IBaseDao m_baseDao;

	/**
	 * 机房Dao
	 */
	private IMachineRoomDao m_machineRoomDao;

	/**
	 * 资产定位信息模板
	 */
	private IMib m_mibSrv;
 
    ......
}

 使用Maven打包,其代码为:

 

......
<plugin>
	<groupId>org.apache.felix</groupId>
	<artifactId>maven-bundle-plugin</artifactId>
	<version>2.0.0</version>
	<extensions>true</extensions>
	<configuration>
		<instructions>
			<Bundle-SymbolicName>
				${pom.artifactId};singleton:=true
			</Bundle-SymbolicName>
			<Bundle-Version>
				${project.version}
			</Bundle-Version>
			<Private-Package>
				com.cvicse.inforguard.utmp.analysis.storage,
				com.cvicse.inforguard.utmp.analysis.storage.business,
				com.cvicse.inforguard.utmp.analysis.storage.business.impl,
				com.cvicse.inforguard.utmp.analysis.storage.asset.service.impl
			</Private-Package>
			<Include-Resource>
				metadata.xml
			</Include-Resource>
		</instructions>
	</configuration>
</plugin>
<!-- loong的声明式服务打包插件 -->
<plugin>
	<groupId>org.trustie.loong.modules.loong-dservice</groupId>
	<artifactId>loong-dservice-plugin</artifactId>
	<version>1.2.1</version>
	<executions>
		<execution>
			<goals>
				<goal>dservice-bundle</goal>
			</goals>
		</execution>
	</executions>
</plugin>
......

你可能感兴趣的:(企业应用,osgi,微内核,loong,龙)