Michael Bauroth wrote:
> Hi,
>
> I'm doing currently my first steps with the Springbased approach in
> Mina. Now I have a few questions how to convert my old code to the new
> style:
>
> 1. I'm configuring an alternate SocketAcceptor over the config file,
> which will be used for the later binding.
>
> <property name="serviceConfig">
> <bean class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
> <property name="filterChainBuilder" ref="filterChainBuilder"/>
> <property name="reuseAddress" value="false"/>
> <property name="disconnectOnUnbind" value="false"/>
> </bean>
> </property>
Hmmm, what serviceConfig property? Are you using the
IoAcceptorFactoryBean? If you are using the IoAcceptorFactoryBean as per
the example in the Javadoc for that class the service config you create
won't become the default config for the acceptor but it will rather be
used only for a particular port you specify in the binding.
Using IoAcceptorFactoryBean the serviceConfig you specify will be used
in a call to acceptor.bind().
>
> When I check the settings after server start, I get other values than
> specified. Here is the related code:
>
> System.out.println("Starting server ...");
> System.out.println("UseDirectBuffers " +
> ByteBuffer.isUseDirectBuffers());
> System.out.println("DisconnectOnUnbind " +
> ((SocketAcceptorConfig)mAcceptor.getDefaultConfig()).isDisconnectOnUnbind());
>
> System.out.println("ReuseAddress " +
> ((SocketAcceptorConfig)mAcceptor.getDefaultConfig()).isReuseAddress());
>
> What I'm doing wrong?
As I described above the default config won't be modified when you use
IoAcceptorFactoryBean as per the example in the Javadoc. You can
configure the default config using Spring but unfortunately there is no
setDefaultConfig() in SocketAcceptor at this moment so to do this can be
rather messy:
<bean id="acceptor"
class="org.apache.mina.transport.socket.nio.SocketAcceptor"/>
<bean id="defaultAcceptorConfig" factory-bean="acceptor"
factory-method="getDefaultConfig">
<property name="filterChainBuilder" ref="filterChainBuilder"/>
<property name="reuseAddress" value="false"/>
<property name="disconnectOnUnbind" value="false"/>
</bean>
>
>
> 2. In the original code I have specified some extra settings:
>
> SocketSessionConfig tSessionConfig =
> (SocketSessionConfig)mAcceptorConfig.getSessionConfig();
>
> tSessionConfig.setReuseAddress( REUSE_ADDRESS );
> tSessionConfig.setTcpNoDelay( TCP_NO_DELAY );
> tSessionConfig.setSendBufferSize( TCP_SND_BUFFER_SIZE );
> tSessionConfig.setReceiveBufferSize( TCP_RCV_BUFFER_SIZE );
> tSessionConfig.setSoLinger( SO_LINGER );
> tSessionConfig.setOobInline( OOB_INLINE );
> tSessionConfig.setKeepAlive( KEEP_ALIVE );
>
> How can I specify these settings over the configuration xml file?
Again, at the moment there is no setSessionConfig() in
SocketSessionConfig. To do this in Spring you will again have to use a
rather messy config like the one above:
<bean id="sessionConfig" factory-bean="defaultAcceptorConfig"
factory-method="getSessionConfig">
<property name="reuseAddress" value="false"/>
<property name="tcpNoDelay" value="false"/>
...
</bean>
This example configures the session config for the defaultAcceptorConfig
bean created previously.
>
>
> 3. How can I request the SocketAddress from an acceptor after binding?
> I can't find a related method?
AFAIK you can't. There is an isBound() method but you probably want
something like getBoundAdresses(), right? That should be easy enough to
add, at least to SocketAcceptor. I'll have a look at it.
BTW, what do you and others think about adding a setDefaultConfig() to
the various acceptors and connectors (adding it to the IoService
interface will loose type safety so I don't think that's a good idea)
and setSessionConfig() to the various acceptor config and connector
config classes (like SocketAcceptorConfig)? I realize that this will
probably only be useful for users using Spring and other DI containers
but for those users it will simplify things a lot. WDYT?
--
Niklas Therning
Software Architect
www.spamdrain.net