I just added a zip file to JIRA which contains some Spring FactoryBeans
making it quite simple to configure Mina Acceptors and Connectors using
Spring. Please have a look at it and let me know what you think. To
build it you will have to add some dependencies to project.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl104-over-slf4j</artifactId>
<version>1.0-beta9</version>
<url>http://www.slf4j.org/</url>
</dependency>
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-core</artifactId>
<version>1.2.5</version>
<url>http://www.springframework.org/</url>
</dependency>
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>1.2.5</version>
<url>http://www.springframework.org/</url>
</dependency>
To run the tests Easymock is required:
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<version>1.2_Java1.3</version>
<url>http://www.easymock.org/</url>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<version>1.2</version>
<url>http://www.easymock.org/</url>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1</version>
<url>http://cglib.sourceforge.net/</url>
</dependency>
Unfortunately version 1.2 of easymockclassextension doesn't appear to be
in the maven repository. I had to download it from
http://www.easymock.org and install it into my local repository. I hope
that's ok.
I was thinking about writing something on how to build, test and use
these FactoryBeans on the WIKI. Would MinaSpringIntegration be a good
name for such a WIKI page?
/Niklas
Trustin Lee wrote:
> Hi Niklas,
>
> 2005/11/2, Niklas Therning <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>>:
>
> Hi,
>
> I've played around a bit with getting Mina to work nicely with Spring.
> Right now the Mina classes are quite Dependency Injection unfriendly.
> But by implementing a few Spring FactoryBeans it is possible to make
> Mina easily configurable using Spring, at least for my needs.
>
> Basically what I want is to be able to define the filters used by my
> SocketConnector and SocketAcceptor and, for the SocketAcceptor,
> also the
> bindings. This is what it looks like in Spring XML:
>
> <bean id="threadPoolFilter"
> class="org.apache.mina.filter.ThreadPoolFilter">
> <constructor-arg value="WorkerThread"/><!-- This is the prefix
> used by
> threads in the pool -->
> <property name="maximumPoolSize" value="10"/>
> </bean>
>
> <!-- My SocketAcceptor -->
> <bean id="socketAcceptor"
> class=" org.apache.mina.spring.SocketAcceptorFactoryBean">
> <property name="filters">
> <map>
> <entry key="blacklist">
> <bean class="org.apache.mina.filter.BlacklistFilter ">
> <property name="blacklist">
> <list>
> <!-- Put all hosts to be blacklisted here. -->
> <value> 192.168.0.1 <http://192.168.0.1></value>
> <value>127.0.0.1 <http://127.0.0.1></value>
> </list>
> </property>
> </bean>
> </entry>
> <entry key="threadPool" value-ref="threadPoolFilter"/>
> </map>
> </property>
> <property name="bindings">
> <map>
> <!-- Bind to port 1234 on 127.0.0.1 <http://127.0.0.1> and
> use myHandler as the
> handler-->
> <entry key="127.0.0.1:1234 <http://127.0.0.1:1234>"
> value-ref="myHandler"/>
> </map>
> </property>
> </bean>
>
> <!-- My SocketConnector -->
> <bean id="socketConnector"
> class="org.apache.mina.spring.SocketConnectorFactoryBean">
> <property name="filters">
> <map>
> <entry key="threadPool" value-ref="threadPoolFilter"/>
> </map>
> </property>
> <property name="connectTimeout" value="30"/>
> </bean>
>
> <bean id="myHandler" class="MyHandler"/>
>
>
> The only thing I've had to change in the original Mina code to
> make this
> work is the "blacklist" property which have been added to the
> BlackListFilter class.
>
> SocketAcceptorFactoryBean will take care of binding and unbinding
> as the
> Spring context is created and destroyed. No need for a ServiceRegistry
> as I see it. Both SocketAcceptorFactoryBean and
> SocketConnectorFactoryBean will add all configured filters to the
> end of
> the filter chain.
>
> WDYT? I will happily contribute this code back to the project if you
> think it could be useful. The same could also be done for
> VmPipe/Datagram/Acceptor/Connector.
>
> /Niklas
>
>
> Thank you so much for your continuous contribution! :D
>
> We appreciate it, of course! Please submit your patch to JIRA and
> I'll merge it as soon as I make MINA Maven multiproject.
>
> Thanks again,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/