You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Michael Bauroth <Mi...@falcom.de> on 2006/08/02 00:47:28 UTC

Once more Mina and Spring

Hi,

I've found in one of the last examples the following config snippet:

<bean id="filterChainBuilder" 
class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
   <property name="filters">
     <list>
       <bean class="org.apache.mina.filter.thread.ThreadPoolFilter">
       <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
         <constructor-arg value="IoWorker"/>
         <property name="maximumPoolSize" value="16"/>
         <property name="keepAliveTime" value="60000"/>
       </bean>
      ...

Unfortunately this code doesn't work anymore because of changes of the 
underlying class I think. What can I do?

Any help would be appreciated.

Regards
Michael

Re: Once more Mina and Spring

Posted by Niklas Therning <ni...@trillian.se>.
Michael Bauroth wrote:
> Thank you for your answer. Just one last question about the topic of
> threadpools in this context.
>
> Can I add the snippet:
>
> <bean class="org.apache.mina.filter.thread.ThreadPoolFilter">
>   <constructor-arg>
>     <bean
> class="org.apache.mina.filter.thread.LeaderFollowersThreadPool">
>       <property name="threadNamePrefix" value="IoWorker"/>
>       <property name="maximumPoolSize" value="16"/>
>       <property name="keepAliveTime" value="60000"/>
>     </bean>
>   </constructor-arg>
> </bean>
>
> once at the beginning of the filterchain filters list and once more at
> the end to encapsulate more timeconsuming tasks in some of the codecs
> between them?
>
> And last but not least: I didn't understand fully the extended
> threadmodel. What happens, when I use your second approach?
>
>> An alternative to the changes above would be to configure your own
>> PooledThreadModel and remove the ThreadPoolFilter configuration:
>>
>> <bean class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
>>   <property name="reuseAddress" value="true"/>
>>   <property name="threadModel">
>>     <bean class="org.apache.mina.common.PooledThreadModel">
>>       <property name="threadNamePrefix" value="IoWorker"/>
>>       <property name="maximumPoolSize" value="16"/>
>>       <property name="keepAliveTime" value="60000"/>
>>     </bean>
>>   </property>
>> </bean>
>
> Is the result already a full functionally threadpool (and if, of what
> kind it is) or must I add some additional code here (e.g. when I want
> to use another threadmodel instead)?
> I hope you know what I mean :)
>

The default ThreadModel is a PooledThreadModel which will create a
ThreadPoolFilter (TPF) (maximumPoolSize=16, keepAlive=60 sec) and add
that to the beginning of your filter chain. My second approach simply
overrides this default with a new PooledThreadModel with some non
default property values.

If you want to configure thread pools yourself you will have to
configure a ThreadModel yourself and set that in the
SocketAcceptorConfig you configure using Spring. The ThreadModel.MANUAL
ThreadModel I used in my first approach is a ThreadModel which doesn't
create any TPF at all. So when using this you will be in full control
over the configuration of the TPF(s).

To have two TPFs as you describe you will have to configure the second
one yourself. You could let MINA configure the first one from the
defaults, you could create a PooledThreadModel in Spring and change
maximumPoolSize and keepAlive to your likings (my second approach in my
previous mail) or you could set the MANUAL ThreadModel and create a TPF
from within Spring (the first approach).

HTH

-- 
Niklas Therning
Software Architect
www.spamdrain.net


Re: Once more Mina and Spring

Posted by Michael Bauroth <Mi...@falcom.de>.
Thank you for your answer. Just one last question about the topic of 
threadpools in this context.

Can I add the snippet:

<bean class="org.apache.mina.filter.thread.ThreadPoolFilter">
   <constructor-arg>
     <bean class="org.apache.mina.filter.thread.LeaderFollowersThreadPool">
       <property name="threadNamePrefix" value="IoWorker"/>
       <property name="maximumPoolSize" value="16"/>
       <property name="keepAliveTime" value="60000"/>
     </bean>
   </constructor-arg>
</bean>

once at the beginning of the filterchain filters list and once more at 
the end to encapsulate more timeconsuming tasks in some of the codecs 
between them?

And last but not least: I didn't understand fully the extended 
threadmodel. What happens, when I use your second approach?

> An alternative to the changes above would be to configure your own
> PooledThreadModel and remove the ThreadPoolFilter configuration:
> 
> <bean class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
>   <property name="reuseAddress" value="true"/>
>   <property name="threadModel">
>     <bean class="org.apache.mina.common.PooledThreadModel">
>       <property name="threadNamePrefix" value="IoWorker"/>
>       <property name="maximumPoolSize" value="16"/>
>       <property name="keepAliveTime" value="60000"/>
>     </bean>
>   </property>
> </bean>

Is the result already a full functionally threadpool (and if, of what 
kind it is) or must I add some additional code here (e.g. when I want to 
use another threadmodel instead)?
I hope you know what I mean :)

Best Regards
Michael

Re: Once more Mina and Spring

Posted by Niklas Therning <ni...@trillian.se>.
Michael Bauroth wrote:
> Hi,
>
> I've found in one of the last examples the following config snippet:
>
> <bean id="filterChainBuilder"
> class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
>
>   <property name="filters">
>     <list>
>       <bean class="org.apache.mina.filter.thread.ThreadPoolFilter">
>       <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
>         <constructor-arg value="IoWorker"/>
>         <property name="maximumPoolSize" value="16"/>
>         <property name="keepAliveTime" value="60000"/>
>       </bean>
>      ...
>
> Unfortunately this code doesn't work anymore because of changes of the
> underlying class I think. What can I do?
>
Here's what you need to do:

Put this anywhere in your Spring config

<bean id="org.apache.mina.common.ThreadModel.MANUAL"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>


When you configure your SocketAcceptorConfig be sure to set the
threadModel to MANUAL otherwise MINA will create a ThreadPoolFilter for you

<bean class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
  <property name="reuseAddress" value="true"/>
  <property name="threadModel"
ref="org.apache.mina.common.ThreadModel.MANUAL"/>
</bean>

Then you need to change your XML above into

<bean class="org.apache.mina.filter.thread.ThreadPoolFilter">
  <constructor-arg>
    <bean class="org.apache.mina.filter.thread.LeaderFollowersThreadPool">
      <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
      <constructor-arg value="IoWorker"/>
      <property name="maximumPoolSize" value="16"/>
      <property name="keepAliveTime" value="60000"/>
    </bean>
  </constructor-arg>

An alternative to the changes above would be to configure your own
PooledThreadModel and remove the ThreadPoolFilter configuration:

<bean class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
  <property name="reuseAddress" value="true"/>
  <property name="threadModel">
    <bean class="org.apache.mina.common.PooledThreadModel">
      <property name="threadNamePrefix" value="IoWorker"/>
      <property name="maximumPoolSize" value="16"/>
      <property name="keepAliveTime" value="60000"/>
    </bean>
  </property>
</bean>

Thanks for bringing this to my attention. I have updated the Javadoc for
IoAcceptorFactoryBean.

I think I will have to look into how we can simplify the Spring
integration further. With the introduction of ThreadModel and the
generalization of ThreadPoolFilter the Spring integration has been a lot
more complicated.

-- 
Niklas Therning
Software Architect
www.spamdrain.net