- 浏览: 544958 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (251)
- UML/RUP/软件工程 (0)
- DDD:领域驱动设计 (1)
- IaaS/Paas/SaaS (1)
- Hadoop/YARN (10)
- PBDP项目 (2)
- OSGi-基础 (7)
- OSGi-Aries (2)
- OSGi-SpringDM (32)
- Oracle/MySQL/SS (8)
- Felix/Equinox/Bnd (14)
- Virgo Server/Gemini (7)
- Weblogic/JBoss/Tomcat (10)
- ActiveMQ (14)
- Camel (1)
- Spring Roo/Eclipse (7)
- Java/JSP/JSF (10)
- Maven (19)
- ESB-Mule (1)
- ESB-ServiceMix (18)
- SOA/SCA/SDO (12)
- WebService/RESTful (17)
- JS/jQuery/ExtJS (4)
- Spring/JPA/MVC (15)
- SpringSecurity (5)
- BPM/jBPM (3)
- Hudson/SVN/CI (0)
- LinuxOS/虚拟化 (25)
- Office/OpenOffice (1)
- 项目管理 (5)
- POI/jFreeChart (1)
最新评论
-
panamera:
请问JMS Transport 发布的webservice 是 ...
CXF 提供的Service Transport-JMS Transpor -
jianyi296:
where is attachment.
CXF WebService Dynamic Client -
hj01kkk:
您好,我用jdbc-user-service为什么每次验证时都 ...
SpringSecurity笔记3-Authenticating Users:Authenticaton Strategy -
wufenglin1231:
你好,我在实现Mapping exceptions to re ...
RESTful 异常处理 -
xchd:
[echo] Project: common
[echo ...
Hive安装配置学习笔记
1.Configuring collections:the list tag for lists and the set tag for sets
<beans (...)>
<osgi:list id="testServices"
interface="com.manning.sdmia.springdm.service.TestService"/>
</beans>
Attributes of the list and set tags:
(1)interface:Specifies the identifier for the service and must correspond to a class or interface
name. This is the same use as for the reference tag.
(2)filter:Can be used as an expression to select a subset of services to be matched. This is the
same use as for the reference tag.
(3)bean-name:Allows you to select the service with the bean-name property set. This is the
same use as for the reference tag.
(4)context-classloader:Can be used to automatically manage the TCCL when calling a referenced
service. This is the same use as for the reference tag.
(5)availability:Specifies whether the collection can be empty. A value of optional means that
the collection can be empty and services are optional; a value of mandatory (which is the default)
requires at least one service in the collection.
(6)comparator-ref:Specifies the comparator to be used to sort collection.
(7)greedy-proxying:
Specifies whether service proxies within the collection can be seen only as service classes (value
false) or as all classes exported by service (value true).
(8)member-type:Specifies which type of object may be added to the collection. With a value of
service-object (the default), Spring DM service proxies are present in the collection; with a value
of service-reference, the collection contains ServiceReference objects.
2. Sorting collections
Spring DM allows you to sort service collections within list and set tags by using the Comparator
interface. Comparators can be configured directly within the Spring container and referenced
when configuring service-based collections. These two ways to configure comparators are
supported by Spring DM:
■ Referencing an existing comparator bean by its identifier through the comparator-ref attribute
■ Configuring a comparator as a nested bean through the nested comparator element
示例:
public class MyCustomComparator implements Comparator<TestService>
{
public int compare
(TestService o1, TestService o2) {
//Implementing the compare processing
(...)
}
}
Configuring custom comparators for service collections:
<bean id="customComparator"
class="com.manning.sdmia.springdm.service.sorting.MyCustomComparator"/>
<osgi:set id="testServiceSet" interface="com.manning.sdmia.springdm.service.TestService"
comparator-ref="customComparator"/>
<osgi:list id="testServiceList" interface="com.manning.sdmia.springdm.service.TestService">
<osgi:comparator>
<bean class="com.manning.sdmia.springdm.service
.sorting.MyCustomComparator"/>
</osgi:comparator>
</osgi:list>
Instead of providing your own comparators, Spring DM allows you to use natural comparators,
through the natural tag of the osgi namespace. This tag has a basis attribute that accepts one
of two values, specifying which sorting strategy you want to use:
■ services —The ordering is based on the service instances, which must implement the
Comparable interface.
■ service-references
—The ordering is based on the ServiceReferences (which are automatically
Comparable)
Configuring natural comparators for service collections:
<osgi:list id="testServiceList" interface="com.manning.sdmia.springdm.service.TestService">
<osgi:comparator>
<osgi:natural basis="services"/>
</osgi:comparator>
</osgi:list>
<osgi:set id="testServiceSet" interface="com.manning.sdmia.springdm.service.TestService">
<osgi:comparator>
<osgi:natural basis="service-references"/>
</osgi:comparator>
</osgi:set>
3. Greedy proxying
The greedy proxy feature of Spring DM makes it possible to cast services in collections to all of
the exposed interfaces that a service supports. The only restriction is that the interfaces used
must be visible to the component within OSGi. Once greedy proxying is enabled, you can cast
your service reference to any of the exposed interfaces and classes visible to your component.
示例:
<osgi:list id="testServiceList" interface="com.manning.sdmia.springdm.service.TestService"
greedy-proxying="true"
/>
Using the greedy proxying feature in code:
for (Iterator iterator = testServiceList.iterator(); iterator.hasNext();) {
TestService service = (TestService) iterator.next();
(...)
if (service instanceof AnotherInterface) {
AnotherInterface anotherServiceInterface = (AnotherInterface)service;
}
}
4. Integrated support when collections are updated
Service collections managed by Spring DM follow these rules:
■ For mandatory service collections, an empty collection throws a ServiceUnavailableException
exception when trying to use an iterator.
■ For optional service collections, an empty collection throws no exception and is simply empty.
When parsing collections, the Iterator interface must be used as in standard Java applications.
Spring DM automatically updates iterators when services disappear, to avoid dealing with the
resulting stale service references. Note that this feature has no impact on unregistered service
instances that have been obtained from an iterator. Using them will result in a
ServiceUnavailableException because they no longer exist in the service registry.
5. Programmatic service support
优点:
(1) This programmatic support can be very useful when implementing test cases or building
Spring configurations.
(2)This approach is particularly suitable for bundles that can’t use the osgi XML namespace and
must work directly with the underlying Spring DM abstractions.
5.1 Registering a service programmatically.
The dedicated abstraction for registering OSGi services is the OsgiServiceFactoryBean class
located in the org.springframework.osgi.service.exporter.support package. As this class is
directly used by the osgi XML namespace , you’ll find it has the same configuration properties
as the service tag.
Programmatically service registration configuration:
TestService testServiceBean = new TestServiceImpl();
(...)
OsgiServiceFactoryBean factoryBean = new OsgiServiceFactoryBean();
factoryBean.setBundleContext(bundleContext);
factoryBean.setTarget(testServiceBean);
factoryBean.setInterfaces(new Class[] { TestService.class });
factoryBean.setContextClassLoader(ExportContextClassLoader.UNMANAGED);
factoryBean.afterPropertiesSet();
ServiceRegistration registration = (ServiceRegistration)factory.getObject();
(...)
factoryBean.destroy();
5.2 Referencing services programmatically
For referencing services, Spring DM provides two FactoryBean implementations: the
OsgiServiceProxyFactoryBean class for referencing a single service and the
OsgiServiceCollectionProxyFactoryBean
class for a collection
of services. Both classes are
located in the org.springframework.osgi.service.importer.support package.
Programmatically service referencing configuration:
OsgiServiceProxyFactoryBean factoryBean = new OsgiServiceProxyFactoryBean();
factoryBean.setBundleContext(bundleContext);
factoryBean.setInterfaces(new Class[] { TestService.class });
factoryBean.setContextClassLoader(ExportContextClassLoader.CLIENT_PROVIDER);
factoryBean.afterPropertiesSet();
TestService service = (TestService)factory.getObject();
(...)
factoryBean.destroy();
5.3 ServiceReference support
Spring DM supports injecting a service’s ServiceReference instance into a bean instead of
injecting the service instance itself. Nothing special needs to be done except for injecting the
configured reference into a property of type ServiceReference. Spring DM will automatically
inject the ServiceReference instance.
You’ll notice that the injected instance corresponds to a proxy and not the target reference of
type ServiceReference. If the underlying reference is needed, you can access it using the proxy’s
getTargetServiceReference
method, as shown in the followingt:
ServiceReference serviceReference = getServiceReference();
ServiceReference nativeReference =
((ServiceReferenceProxy)serviceReference).getTargetServiceReference();
Having injected the ServiceReference for the referenced service, the instance can be used within
the application, as in the first of the preceding code lines. Spring DM allows the native reference
given by the OSGi container to be accessed through the proxy via the getTargetServiceReference
method (as in the second of the code lines).
A typical use case for this technique is when you want to get hold of a real OSGi service because
an OSGi container implementation expects a native ServiceReference instance instead of a Spring
DM proxy.
发表评论
-
SpringDM笔记31-Testing with OSGi and SpringDM
2011-11-22 10:27 12441. 创建一个SpringDM测试类 SpringD ... -
SpringDM笔记30-OSGi中使用SSL/STL
2011-11-21 11:55 1318SSL:Secure Sockets Layer ... -
SpringDM笔记29-Require-Bundle与Import-Package的区别
2011-11-21 10:31 2238具体可参考:http://www.osgi.org/bl ... -
SpringDM笔记28-OSGi Bundle Activities with Spring-DM
2011-11-17 10:19 1158OSGi框架中也支持搞层次的模块交互:bundles.例如 ... -
SpringDM笔记28-Spring And OSGi:Layers of Integration
2011-11-15 11:00 11721. Application Design:Service和B ... -
SpringDM笔记27-Extending The Stand Extender and Configure
2011-09-02 09:38 8691. -
SpringDM笔记25-Using AJAX frameworks with Spring DM:GWT
2011-09-01 08:53 12001. Using Spring DM with AJAX fr ... -
SpringDM笔记24-Using action-based web frameworks with Spring DM:SpringMVC
2011-08-30 09:33 1478■ Action-based web frameworks ... -
SpringDM笔记23-Using the open EntityManager in view pattern实现延迟加载
2011-08-30 09:27 15661. The open EntityManager in vi ... -
SpringDM笔记22-Transactions Support With SpringDM
2011-08-29 21:24 12101. Spring’s transactional suppo ... -
SpringDM笔记21-Using ORM within OSGi with Spring DM
2011-08-25 10:31 2095Version 1.Object/relational ma ... -
SpringDM笔记20-Using JDBC within OSGi with Spring DM
2011-08-25 09:08 1776The public API for interact ... -
SpringDM笔记19-SpringDM如何处理OSGi应用的动态行为
2011-08-24 08:51 1142ServiceTracker 1. Dealing ... -
SpringDM笔记18-Designing OSGi Enterprise Applications
2011-08-22 11:08 11211. Organizing OSGi components ... -
SpringDM笔记16-处理OSGi服务的动态性:事件
2011-08-19 09:51 17791. Service registration and unr ... -
SpringDM笔记15-通过声明特定的属性注册和引用服务
2011-08-18 11:01 14071. Configuration for registerin ... -
SpringDM笔记14-The thread context classloader 及在OSGi中的运用
2011-08-18 10:40 22471. Using the thread context cla ... -
SpringDM笔记13-OSGi服务注册与引用
2011-08-18 09:28 34491. Combining OSGi services and ... -
SpringDM笔记12-Spring DM’s web Extender运行机制
2011-08-17 11:04 2087SpringDM把一个WAR作为一个Bundle, 其实 ... -
SpringDM笔记11-Hard dependencies on the OSGi environment
2011-08-17 10:50 1413Any bean in a Spring DM app ...
相关推荐
commons-collections-3.2-osgi.jar, commons-collections-3.2-sources.jar, commons-collections-3.2.1.jar, commons-collections-3.2.2-javadoc.jar, commons-collections-3.2.2-src.zip, commons-collections-...
赠送jar包:commons-collections-3.2.2.jar; 赠送原API文档:commons-collections-3.2.2-javadoc.jar; 赠送源代码:commons-collections-3.2.2-sources.jar; 赠送Maven依赖信息文件:commons-collections-3.2.2....
赠送jar包:commons-collections4-4.1.jar; 赠送原API文档:commons-collections4-4.1-javadoc.jar; 赠送源代码:commons-collections4-4.1-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.1.pom;...
赠送jar包:commons-collections-3.2.2.jar; 赠送原API文档:commons-collections-3.2.2-javadoc.jar; 赠送源代码:commons-collections-3.2.2-sources.jar; 赠送Maven依赖信息文件:commons-collections-3.2.2....
spring.jar, commons-collections.jar, commons-dbcp.jar, commons-pool.jar
常用jar包下载,包括commons-beanutils-1.9.3、commons-collections-3.2.2、commons-collections4-4.1
赠送jar包:commons-collections4-4.4.jar; 赠送原API文档:commons-collections4-4.4-javadoc.jar; 赠送源代码:commons-collections4-4.4-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.4.pom;...
赠送jar包:commons-collections4-4.4.jar; 赠送原API文档:commons-collections4-4.4-javadoc.jar; 赠送源代码:commons-collections4-4.4-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.4.pom;...
commons-collections-3.2.1-bin
标签:apache-collections-commons-collections-3.1.jar.zip,apache,collections,commons,collections,3.1,jar.zip包下载,依赖包
apache-common系列中的重要的成员:apache-common-collections。包中对Java中的集合类进行了一定的补充,定义了一些全新的集合,当然也是实现了Collection接口的,比如Bag,BidiMap。同时拥有新版本的原有集合,比如...
commons-collections4-4.1.jar
commons-collections4-4.1,用来修复java反序列漏洞,重命名后替换之前Middleware\modules下的的3.2.0版
赠送jar包:commons-collections-3.2.1.jar; 赠送原API文档:commons-collections-3.2.1-javadoc.jar; 赠送源代码:commons-collections-3.2.1-sources.jar; 包含翻译后的API文档:commons-collections-3.2.1-...
JavaEE源代码 commons-collections-2.1.1JavaEE源代码 commons-collections-2.1.1JavaEE源代码 commons-collections-2.1.1JavaEE源代码 commons-collections-2.1.1JavaEE源代码 commons-collections-2.1.1JavaEE源...
赠送jar包:eclipse-collections-forkjoin-7.1.2.jar; 赠送原API文档:eclipse-collections-forkjoin-7.1.2-javadoc.jar; 赠送源代码:eclipse-collections-forkjoin-7.1.2-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:commons-collections-3.2.1.jar 赠送原API文档:commons-collections-3.2.1-javadoc.jar 赠送源代码:commons-collections-3.2.1-sources.jar 包含翻译后的API文档:commons-collections-3.2.1-...
commons-beanutils-bean-collections-1.7.0.jar
commons-collections-3.1.jar commons-lang-2.3.jar commons-logging-1.1.3.jar ezmorph-1.0.6.jar jackson-all-1.7.4.jar ojdbc5.jar org.springframework.aop-3.0.0.RELEASE.jar org.springframework.asm-3.0.0....
postman--分享collections和environments,用于结合jenkins等CI平台做接口自动化测试