Just wondering,

 

Here the filters are stored in a Spring Map. But isn’t the order of the filters meaningful? Shouldn’t we have to specify the order somewhere?

 

Jose Alberto

 

 


From: Trustin Lee [mailto:trustin@gmail.com]
Sent: 02 November 2005 01:22
To: Apache Directory Developers List
Subject: Re: [mina] Spring integration

 

Hi Niklas,

2005/11/2, Niklas Therning <niklas@trillian.se>:

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</value>
                <value>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 and use myHandler as the
handler-->
        <entry key="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/