Spring和mima结合配置IoAccept中的sessionConfig中的属性

2 篇文章 0 订阅
是不是想在使用spring配置mina的时候,配置IoAccept中的sessionConfig中的属性?比如readBufferSize和 IdleTime
如果你用java代码你会这样写:
IoAcceptor acceptor=new NioSocketAcceptor();
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig.setIdleTime(IdleStatus.BOTH_IDLE,10);

那么用spring配置的时候怎么写呢?
先看下NioSocketAccept的构造方法:
public NioSocketAcceptor() {
super(new DefaultSocketSessionConfig(), NioProcessor.class);
((DefaultSocketSessionConfig) getSessionConfig()).init(this);
}
得知 DefaultSocketSessionConfig 被实例化。

看到方法:
public SocketSessionConfig getSessionConfig() {
return (SocketSessionConfig) super.getSessionConfig();
}
得知获取方法为getSessionConfig。

我们看到 DefaultSocketSessionConfig 以及其 继承的类中 有一些 set*方法。setReceiveBufferSize
setBothIdleTime
setReaderIdleTime等
我们可以通过spring来注入这些参数的值。
代码如下:
<!-- session config -->
<bean id="sessionConfig" factory-bean="serverAcceptor"
factory-method="getSessionConfig" >

<property name="bothIdleTime" value="10"/>
<property name="receiveBufferSize" value="1024"/>
</bean>


<!-- server -->

<bean id="serverAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
init-method="bind" destroy-method="unbind">
<property name="defaultLocalAddress">
<bean class="java.net.InetSocketAddress">
<constructor-arg>
<value>9123</value>
</constructor-arg>
</bean>
</property>
<property name="handler" ref="tspChainedIoHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>

至此便可完成在spring中配置IoAccept中的sessionConfig中的属性。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值