Hi all,

I've been playing around with Service Binder
(http://gravity.sourceforge.net/servicebinder/) for the past week or
so (thanks Richard and Humberto!).  My team is strongly considering
OSGi as the base of a re-implementation of one of our enterprise
systems here, currently based on Spring
(http://www.springframework.org).  Since we all know and love Spring,
I wanted to see if I could work it into OSGi somehow.

I've modified the latest ServiceBinder implementation to load its
service instances from a Spring BeanFactory, instead of trying to
dynamically instantiate the classes itself.  I also got rid of the
standalone ServiceBinder XML file and integrated ServiceBinder
definitions directly into the Spring XML files.  Now services might be
defined like this:

==========================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "binder-beans.dtd">

<beans>
    <bean id="hibernateServiceImpl" singleton="false"
        class="test.orm.hibernate.impl.HibernateServiceImpl">

        <instance>
            <provides interface="test.orm.hibernate.HibernateService"/>
            <osgiproperty name="version" value="1" type="string"/>
            <desires
                service="test.service.ServiceProvider"
                filter="(version=*)"
                cardinality="0..1"
                policy="dynamic"
                bind-method="setService"
                unbind-method="unsetService"
            />
        </instance>
                
        <property name="dataSource"><ref bean="hibernateDataSource"/></property>
        <property name="properties">
            <props>
                <prop
key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.jdbc.batch_size">0</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>

    </bean>

    <bean id="hibernateDataSource"
class="org.apache.commons.dbcp.BasicDataSource">
        ...
    </bean>
</beans>

==========================================================

Bean XML definitions are specified with the "Bean-Definitions"
manifest entry; e.g.,
    Bean-Definitions: beans/hibernate.xml, beans/someservice.xml


The old ServiceBinder XML file has been replaced with the <instance/>
element in the new <bean/> definition (some element names have been
changed).  Any bean that contains an <instance/> element will be
handed to ServiceBinder.

Some issues currently:
* I would like to support wildcard lookup of bean files, but there
doesn't appear to be any way to get a list of resources from a bundle.
 As of now, each xml file has to be explicitly specified.
* Each service bundle requires its own BeanFactory instance (not sure
about the overhead with this).
* Logging all goes to stdout.

I've made it available for download at:
http://www.rit.edu/~jrv4595/springservicebinder.zip
Since the Spring jar is included (twice- once in the source tree and
once in the compiled bundle), the archive is about 5mb.

Any questions/comments/suggestions are greatly appreciated. :)

-Jeremy

Reply via email to