spring Mina 整合,多埠繫結spring.xml配置
阿新 • • 發佈:2019-02-18
<!-- Mina 整合 -->
<!-- slf4j-api-1.7.7.jar -->
<!-- slf4j-log4j12-1.7.7.jar -->
<!-- 配置 textCodecFilter <bean id="textCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg> <bean class="com.founder.bank.util.TextLineChineseCodecFactory"></bean>
</constructor-arg> </bean> -->
<!-- 字元編 碼過濾器,改為判斷報文頭固定長度 -->
<bean id="codecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="com.founder.bank.util.PrefixedStringCodecFactory"></bean>
</constructor-arg>
</bean>
<!-- 多執行緒處理過濾器,的操作開啟多執行緒,一般放在編解碼過濾器之後, IO 執行緒與業務處理執行緒分開 -->
<bean id="executors" class="org.apache.mina.filter.executor.ExecutorFilter">
<constructor-arg index="0">
<value>1000</value>
</constructor-arg>
<constructor-arg index="1">
<value>1800</value>
</constructor-arg>
</bean>
<!-- 將IoSession的主鍵屬性注入執行緒對映表MDC中 -->
<bean id="mdcInjectionFilter" class="org.apache.mina.filter.logging.MdcInjectionFilter">
<!-- <constructor-arg value="remoteAddress" /> -->
</bean>
<!-- 日誌過濾器 -->
<bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter">
<!-- <property name="messageReceivedLogLevel" ref="info"></property> <property
name="exceptionCaughtLogLevel" ref="info"></property> -->
</bean>
<!-- <bean id="info" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField" value="org.apache.mina.filter.logging.LogLevel.INFO"
/> </bean> -->
<!-- 過濾器鏈 -->
<bean id="filterChainBuilder"
class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
<property name="filters">
<map>
<entry key="loggingFilter" value-ref="loggingFilter" />
<entry key="codecFilter" value-ref="codecFilter" />
<entry key="executors" value-ref="executors" />
</map>
</property>
</bean>
<!-- 過濾器鏈2 <bean id="filterChainBuilderText" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
<property name="filters"> <map> <entry key="loggingFilter" value-ref="loggingFilter"
/> <entry key="codecFilter" value-ref="textCodecFilter" /> <entry key="mdcInjectionFilter"
value-ref="mdcInjectionFilter" /> <entry key="executors" value-ref="executors"
/> </map> </property> </bean> -->
<!-- 設定 I/O 接受器,並指定接收到請求後交給 serverHandler 進行處理 -->
<bean id="customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.net.SocketAddress"
value="org.apache.mina.integration.beans.InetSocketAddressEditor" />
</map>
</property>
</bean>
<!-- session config 通過工廠方法注入 -->
<bean id="sessionConfig" factory-bean="ioAcceptor" factory-method="getSessionConfig">
<property name="writeTimeout" value="30" />
<property name="bothIdleTime" value="30" />
<property name="minReadBufferSize" value="512" />
<property name="maxReadBufferSize" value="10240" />
</bean>
<!-- 定義資料處理Bean,接收到請求後交給 serverHandle -->
<bean id="serverHandler" class="com.founder.bank.filter.ServerHandler" />
<!-- IoAccepter,繫結到8888埠 -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
init-method="bind" destroy-method="unbind">
<!-- 預設啟用的執行緒個數是CPU 的核數+1, -->
<!--<constructor-arg index="0" value="10"></constructor-arg> -->
<property name="defaultLocalAddress" value=":8888" />
<property name="handler" ref="serverHandler" />
<property name="reuseAddress" value="true" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>
<!-- IoAccepter,繫結到8889埠 <bean id="ioAcceptorText" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
init-method="bind" destroy-method="unbind"> <property name="defaultLocalAddress"
value=":8889" /> <property name="handler" ref="serverHandler" /> <property
name="reuseAddress" value="true" /> <property name="filterChainBuilder" ref="filterChainBuilderText"
/> </bean> -->
<!-- slf4j-api-1.7.7.jar -->
<!-- slf4j-log4j12-1.7.7.jar -->
<!-- 配置 textCodecFilter <bean id="textCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg> <bean class="com.founder.bank.util.TextLineChineseCodecFactory"></bean>
</constructor-arg> </bean> -->
<!-- 字元編 碼過濾器,改為判斷報文頭固定長度 -->
<bean id="codecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="com.founder.bank.util.PrefixedStringCodecFactory"></bean>
</constructor-arg>
</bean>
<!-- 多執行緒處理過濾器,的操作開啟多執行緒,一般放在編解碼過濾器之後, IO 執行緒與業務處理執行緒分開 -->
<bean id="executors" class="org.apache.mina.filter.executor.ExecutorFilter">
<constructor-arg index="0">
<value>1000</value>
</constructor-arg>
<constructor-arg index="1">
<value>1800</value>
</constructor-arg>
</bean>
<!-- 將IoSession的主鍵屬性注入執行緒對映表MDC中 -->
<bean id="mdcInjectionFilter" class="org.apache.mina.filter.logging.MdcInjectionFilter">
<!-- <constructor-arg value="remoteAddress" /> -->
</bean>
<!-- 日誌過濾器 -->
<bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter">
<!-- <property name="messageReceivedLogLevel" ref="info"></property> <property
name="exceptionCaughtLogLevel" ref="info"></property> -->
</bean>
<!-- <bean id="info" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField" value="org.apache.mina.filter.logging.LogLevel.INFO"
/> </bean> -->
<!-- 過濾器鏈 -->
<bean id="filterChainBuilder"
class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
<property name="filters">
<map>
<entry key="loggingFilter" value-ref="loggingFilter" />
<entry key="codecFilter" value-ref="codecFilter" />
<entry key="executors" value-ref="executors" />
</map>
</property>
</bean>
<!-- 過濾器鏈2 <bean id="filterChainBuilderText" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
<property name="filters"> <map> <entry key="loggingFilter" value-ref="loggingFilter"
/> <entry key="codecFilter" value-ref="textCodecFilter" /> <entry key="mdcInjectionFilter"
value-ref="mdcInjectionFilter" /> <entry key="executors" value-ref="executors"
/> </map> </property> </bean> -->
<!-- 設定 I/O 接受器,並指定接收到請求後交給 serverHandler 進行處理 -->
<bean id="customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.net.SocketAddress"
value="org.apache.mina.integration.beans.InetSocketAddressEditor" />
</map>
</property>
</bean>
<!-- session config 通過工廠方法注入 -->
<bean id="sessionConfig" factory-bean="ioAcceptor" factory-method="getSessionConfig">
<property name="writeTimeout" value="30" />
<property name="bothIdleTime" value="30" />
<property name="minReadBufferSize" value="512" />
<property name="maxReadBufferSize" value="10240" />
</bean>
<!-- 定義資料處理Bean,接收到請求後交給 serverHandle -->
<bean id="serverHandler" class="com.founder.bank.filter.ServerHandler" />
<!-- IoAccepter,繫結到8888埠 -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
init-method="bind" destroy-method="unbind">
<!-- 預設啟用的執行緒個數是CPU 的核數+1, -->
<!--<constructor-arg index="0" value="10"></constructor-arg> -->
<property name="defaultLocalAddress" value=":8888" />
<property name="handler" ref="serverHandler" />
<property name="reuseAddress" value="true" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>
<!-- IoAccepter,繫結到8889埠 <bean id="ioAcceptorText" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
init-method="bind" destroy-method="unbind"> <property name="defaultLocalAddress"
value=":8889" /> <property name="handler" ref="serverHandler" /> <property
name="reuseAddress" value="true" /> <property name="filterChainBuilder" ref="filterChainBuilderText"
/> </bean> -->