/*
* @(#) $Id: VmPipeAcceptorFactoryBean.java 355016 2005-12-08 07:00:30Z trustin $
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.mina.integration.spring;
import java.net.SocketAddress;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.integration.spring.support.AbstractIoAcceptorFactoryBean;
import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
import org.apache.mina.transport.vmpipe.VmPipeAddress;
import org.springframework.util.Assert;
/**
* {@link AbstractIoAcceptorFactoryBean} implementation which allows for easy
* configuration of {@link VmPipeAcceptor} instances using Spring. Example of
* usage:
* <p>
*
* <pre>
* <!-- My IoHandler implementation-->
* <bean id="myHandler" class="com.foo.bar.MyHandler">
* ...
*
* <!-- Create a thread pool filter -->
* <bean id="threadPoolFilter"
* class="org.apache.mina.filter.ThreadPoolFilter">
* <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
* <constructor-arg value="IoWorker"/>
* <property name="maximumPoolSize" value="10"/>
* </bean>
*
* <!-- Create the DatagramAcceptor -->
* <bean id="vmPipeAcceptor"
* class="org.apache.mina.integration.spring.VmPipeAcceptorFactoryBean">
* <property name="filters">
* <list>
* <ref local="threadPoolFilter"/>
* </list>
* </property>
* <property name="bindings">
* <list>
* <bean class="org.apache.mina.integration.spring.Binding">
* <property name="address" value=":9287"/>
* <property name="handler" ref="myHandler"/>
* </bean>
* <bean class="org.apache.mina.integration.spring.Binding">
* <property name="address" value=":6273"/>
* <property name="handler" ref="myHandler"/>
* </bean>
* </list>
* </property>
* </bean>
* </pre>
*
* </p>
*
* @author The Apache Directory Project (dev@directory.apache.org)
* @version $Rev: 355016 $, $Date: 2005-12-08 16:00:30 +0900 (Thu, 08 Dec 2005) $
*/
public class VmPipeAcceptorFactoryBean extends AbstractIoAcceptorFactoryBean
{
protected IoAcceptor createIoAcceptor() throws Exception
{
return new VmPipeAcceptor();
}
protected SocketAddress parseSocketAddress( String s )
{
Assert.notNull( s, "null SocketAddress string" );
s = s.trim();
if( s.startsWith( ":" ) )
{
s = s.substring( 1 );
}
try
{
return new VmPipeAddress( Integer.parseInt( s.trim() ) );
}
catch( NumberFormatException nfe )
{
throw new IllegalArgumentException( "Illegal vm pipe address: " + s );
}
}
}